LSlog handlers: fix log TRACE enabled error (even if disabled)

This commit is contained in:
Benjamin Renard 2020-09-10 10:17:19 +02:00
parent 1e6fa6fe8e
commit 988054bfc5
6 changed files with 48 additions and 12 deletions

View file

@ -42,6 +42,8 @@ class LSlog_console extends LSlog_handler {
parent :: __construct($config);
$this -> stdout = fopen('php://stdout', 'w');
$this -> stderr = fopen('php://stderr', 'w');
if ($this -> enabled)
LSlog :: log_trace("$this Enabled", get_class($this));
}
/**

View file

@ -43,7 +43,8 @@ class LSlog_email extends LSlog_handler {
public function __construct($config) {
parent :: __construct($config);
$this -> recipient = self :: getConfig('recipient');
$this -> logging('TRACE', "$this Enabled", get_class($this));
if ($this -> enabled)
LSlog :: log_trace("$this Enabled", get_class($this));
}
/**

View file

@ -43,7 +43,8 @@ class LSlog_file extends LSlog_handler {
$this -> path = self :: getConfig('path', LSlog :: getConfig('filename', 'tmp/LS.log'));
if (substr($this -> path, 0, 1) != '/')
$this -> path = LS_ROOT_DIR."/".$this -> path;
$this -> logging('TRACE', "$this Enabled", get_class($this));
if ($this -> enabled)
LSlog :: log_trace("$this Enabled", get_class($this));
}
/**

View file

@ -87,6 +87,32 @@ class LSlog_handler {
);
}
/**
* Get handler info
*
* @param[in] $key string The info name
*
* @retval mixed The info value
**/
public function __get($key) {
switch ($key) {
case 'enabled':
return $this -> getConfig('enabled', true, 'bool');
case 'format':
if (php_sapi_name() == "cli")
$format = $this -> getConfig('cli_format', $this -> default_cli_format, 'string');
else
$format = $this -> getConfig('format', $this -> default_format, 'string');
// Add datetime prefix (if enabled)
if ($this -> getConfig('datetime_prefix', $this -> default_datetime_prefix, 'boolean')) {
$format = date($this -> getConfig('datetime_format', $this -> default_datetime_format, 'string'))." - $format";
}
return $format;
}
// Unknown key, log warning
LSlog :: log_warning("$this -> __get($key): invalid property requested\n".LSlog :: get_debug_backtrace_context());
}
/**
* Check system compatibility with this handler
*
@ -184,16 +210,8 @@ class LSlog_handler {
**/
protected function format($level, $message, $logger=null) {
global $argv;
if (php_sapi_name() == "cli")
$format = $this -> getConfig('cli_format', $this -> default_cli_format, 'string');
else
$format = $this -> getConfig('format', $this -> default_format, 'string');
// Add datetime prefix (if enabled)
if ($this -> getConfig('datetime_prefix', $this -> default_datetime_prefix, 'boolean')) {
$format = date($this -> getConfig('datetime_format', $this -> default_datetime_format, 'string'))." - $format";
}
return getFData(
$format,
$this -> format,
array(
'level' => $level,
'message' => $message,

View file

@ -59,7 +59,8 @@ class LSlog_syslog extends LSlog_handler {
public function __construct($config) {
parent :: __construct($config);
$this -> priority = static :: getConfig('priority');
$this -> logging('TRACE', "$this Enabled", get_class($this));
if ($this -> enabled)
LSlog :: log_trace("$this Enabled", get_class($this));
}
/**

View file

@ -30,6 +30,19 @@ class LSlog_system extends LSlog_handler {
// Default datetime prefix (enabled/disabled)
protected $default_datetime_prefix = false;
/**
* Constructor
*
* @param[in] $config array The handler configuration
*
* @retval void
**/
public function __construct($config) {
parent :: __construct($config);
if ($this -> enabled)
LSlog :: log_trace("$this Enabled", get_class($this));
}
/**
* Log a message
*