logger : allow the facility and loglevel to be string. They are converted into integer before use
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2147 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
52
logger.php
52
logger.php
@@ -61,6 +61,34 @@ class logger
|
||||
@param mixed ...$message Message to log */
|
||||
public function log ($priority=LOG_NOTICE, $message)
|
||||
{
|
||||
if (! is_int ($priority))
|
||||
{
|
||||
switch ($priority)
|
||||
{
|
||||
case "LOG_EMERG": $priority = LOG_EMERG; break;
|
||||
case "LOG_ALERT": $priority = LOG_ALERT; break;
|
||||
case "LOG_CRIT": $priority = LOG_CRIT; break;
|
||||
case "LOG_ERR": $priority = LOG_ERR; break;
|
||||
case "LOG_WARNING": $priority = LOG_WARNING; break;
|
||||
case "LOG_NOTICE": $priority = LOG_NOTICE; break;
|
||||
case "LOG_INFO": $priority = LOG_INFO; break;
|
||||
case "LOG_DEBUG": $priority = LOG_DEBUG; break;
|
||||
}
|
||||
}
|
||||
if (! is_int ($this->loglevelmin))
|
||||
{
|
||||
switch ($this->loglevelmin)
|
||||
{
|
||||
case "LOG_EMERG": $this->loglevelmin = LOG_EMERG; break;
|
||||
case "LOG_ALERT": $this->loglevelmin = LOG_ALERT; break;
|
||||
case "LOG_CRIT": $this->loglevelmin = LOG_CRIT; break;
|
||||
case "LOG_ERR": $this->loglevelmin = LOG_ERR; break;
|
||||
case "LOG_WARNING": $this->loglevelmin = LOG_WARNING; break;
|
||||
case "LOG_NOTICE": $this->loglevelmin = LOG_NOTICE; break;
|
||||
case "LOG_INFO": $this->loglevelmin = LOG_INFO; break;
|
||||
case "LOG_DEBUG": $this->loglevelmin = LOG_DEBUG; break;
|
||||
}
|
||||
}
|
||||
if ($this->loglevelmin < $priority)
|
||||
return;
|
||||
$backtrace = debug_backtrace();
|
||||
@@ -171,6 +199,30 @@ class logger
|
||||
@param integer|null $priority Priority to use */
|
||||
private function logsyslog ($message, $priority)
|
||||
{
|
||||
if (is_string ($this->syslogFacility))
|
||||
{
|
||||
switch ($this->syslogFacility)
|
||||
{
|
||||
case "LOG_AUTH": $this->syslogFacility=LOG_AUTH; break;
|
||||
case "LOG_AUTHPRIV": $this->syslogFacility=LOG_AUTHPRIV; break;
|
||||
case "LOG_DAEMON": $this->syslogFacility=LOG_DAEMON; break;
|
||||
case "LOG_KERN": $this->syslogFacility=LOG_KERN; break;
|
||||
case "LOG_LOCAL0": $this->syslogFacility=LOG_LOCAL0; break;
|
||||
case "LOG_LOCAL1": $this->syslogFacility=LOG_LOCAL1; break;
|
||||
case "LOG_LOCAL2": $this->syslogFacility=LOG_LOCAL2; break;
|
||||
case "LOG_LOCAL3": $this->syslogFacility=LOG_LOCAL3; break;
|
||||
case "LOG_LOCAL4": $this->syslogFacility=LOG_LOCAL4; break;
|
||||
case "LOG_LOCAL5": $this->syslogFacility=LOG_LOCAL5; break;
|
||||
case "LOG_LOCAL6": $this->syslogFacility=LOG_LOCAL6; break;
|
||||
case "LOG_LOCAL7": $this->syslogFacility=LOG_LOCAL7; break;
|
||||
case "LOG_LPR": $this->syslogFacility=LOG_LPR; break;
|
||||
case "LOG_MAIL": $this->syslogFacility=LOG_MAIL; break;
|
||||
case "LOG_NEWS": $this->syslogFacility=LOG_NEWS; break;
|
||||
case "LOG_SYSLOG": $this->syslogFacility=LOG_SYSLOG; break;
|
||||
case "LOG_USER": $this->syslogFacility=LOG_USER; break;
|
||||
case "LOG_UUCP": $this->syslogFacility=LOG_UUCP; break;
|
||||
}
|
||||
}
|
||||
openlog ($this->syslogPrefix, NULL, $this->syslogFacility);
|
||||
syslog ($priority, $message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user