Adopted composer autoload way
Split up classes into separate way, to allow autoloader to do it's work Signed-off-by: Diederik de Groot <ddegroot@talon.nl>
This commit is contained in:
54
lib/Logger/Filehandle.php
Normal file
54
lib/Logger/Filehandle.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace PROVISION\Logger;
|
||||
|
||||
class Filehandle extends Logger
|
||||
{
|
||||
private $priority_map = array(
|
||||
LOG_DEBUG => "D",
|
||||
LOG_INFO => "I",
|
||||
LOG_NOTICE => "N",
|
||||
LOG_WARNING => "W",
|
||||
LOG_ERR => "E",
|
||||
LOG_CRIT => "C",
|
||||
LOG_ALERT => "A",
|
||||
LOG_EMERG => "!"
|
||||
);
|
||||
function __construct($minimum, $filehandle, $dateformat = "r")
|
||||
{
|
||||
$this->filehandle = $filehandle;
|
||||
$this->dateformat = $dateformat;
|
||||
return parent::__construct($minimum);
|
||||
}
|
||||
|
||||
function log($priority, $message)
|
||||
{
|
||||
if($this->shouldlog($priority))
|
||||
fwrite($this->filehandle, date($this->dateformat) . ": " . $this->priority_map[$priority] . " $message\n");
|
||||
}
|
||||
}
|
||||
|
||||
class Filename extends Filehandle
|
||||
{
|
||||
function __construct($minimum, $filename, $dateformat = "r")
|
||||
{
|
||||
return parent::__construct($minimum, fopen($filename, "a"), $dateformat);
|
||||
}
|
||||
}
|
||||
|
||||
class Stderr extends Filehandle
|
||||
{
|
||||
function __construct($minimum, $dateformat = "r")
|
||||
{
|
||||
return parent::__construct($minimum, STDERR, $dateformat);
|
||||
}
|
||||
}
|
||||
class Stdout extends Filehandle
|
||||
{
|
||||
function __construct($minimum, $dateformat = "r")
|
||||
{
|
||||
return parent::__construct($minimum, STDOUT, $dateformat);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
12
lib/Logger/Filename.php
Normal file
12
lib/Logger/Filename.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace PROVISION\Logger;
|
||||
|
||||
class Filename extends Filehandle
|
||||
{
|
||||
function __construct($minimum, $filename, $dateformat = "r")
|
||||
{
|
||||
return parent::__construct($minimum, fopen($filename, "a"), $dateformat);
|
||||
}
|
||||
}
|
||||
?>
|
32
lib/Logger/Logger.php
Normal file
32
lib/Logger/Logger.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace PROVISION\Logger;
|
||||
|
||||
/* Note about the Logger class:
|
||||
* The "priority" and "minimum should be one of the constants used for syslog.
|
||||
* See: http://php.net/manual/en/function.syslog.php
|
||||
* They are: LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE,
|
||||
* LOG_INFO, LOG_DEBUG
|
||||
* Note that LOG_EMERG, LOG_ALERT, and LOG_CRIT are not really relevant to a
|
||||
* tftp server - these represent instability in the entire operating system.
|
||||
* Note that the number they are represented by are in reverse order -
|
||||
* LOG_EMERG is the lowest, LOG_DEBUG the highest.
|
||||
*/
|
||||
abstract class Logger
|
||||
{
|
||||
function __construct($minimum)
|
||||
{
|
||||
$this->minimum = $minimum;
|
||||
}
|
||||
|
||||
function shouldlog($priority)
|
||||
{
|
||||
// Note: this looks reversed, but is correct
|
||||
// the priority must be AT LEAST the minimum,
|
||||
// because higher priorities represent lower numbers.
|
||||
return $priority <= $this->minimum;
|
||||
}
|
||||
|
||||
abstract function log($priority, $message);
|
||||
}
|
||||
?>
|
11
lib/Logger/Null.php
Normal file
11
lib/Logger/Null.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace PROVISION\Logger;
|
||||
|
||||
class Null extends Logger
|
||||
{
|
||||
function log($priority, $message)
|
||||
{
|
||||
}
|
||||
}
|
||||
?>
|
12
lib/Logger/Stderr.php
Normal file
12
lib/Logger/Stderr.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace PROVISION\Logger;
|
||||
|
||||
class Stderr extends Filehandle
|
||||
{
|
||||
function __construct($minimum, $dateformat = "r")
|
||||
{
|
||||
return parent::__construct($minimum, STDERR, $dateformat);
|
||||
}
|
||||
}
|
||||
?>
|
12
lib/Logger/Stdout.php
Normal file
12
lib/Logger/Stdout.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace PROVISION\Logger;
|
||||
|
||||
class Stdout extends Filehandle
|
||||
{
|
||||
function __construct($minimum, $dateformat = "r")
|
||||
{
|
||||
return parent::__construct($minimum, STDOUT, $dateformat);
|
||||
}
|
||||
}
|
||||
?>
|
13
lib/Logger/Syslog.php
Normal file
13
lib/Logger/Syslog.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace PROVISION\Logger;
|
||||
|
||||
class Syslog extends Logger
|
||||
{
|
||||
function log($priority, $message)
|
||||
{
|
||||
if($this->shouldlog($priority))
|
||||
syslog($priority,$message);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user