diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-10-25 16:22:10 -0700 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-10-25 16:22:10 -0700 |
commit | 9e2b2a32fd0e967ad3184e9a5d091a29953acb91 (patch) | |
tree | 00822e24aa1110c73ca455a8d096ef296c008cbc /vendor/fguillot/simpleLogger/src/SimpleLogger/Syslog.php | |
parent | c507c5416251c505cb3e088a03c6664bed73c812 (diff) |
Include composer dependencies in repo
Diffstat (limited to 'vendor/fguillot/simpleLogger/src/SimpleLogger/Syslog.php')
-rw-r--r-- | vendor/fguillot/simpleLogger/src/SimpleLogger/Syslog.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/vendor/fguillot/simpleLogger/src/SimpleLogger/Syslog.php b/vendor/fguillot/simpleLogger/src/SimpleLogger/Syslog.php new file mode 100644 index 00000000..c4e26a7a --- /dev/null +++ b/vendor/fguillot/simpleLogger/src/SimpleLogger/Syslog.php @@ -0,0 +1,72 @@ +<?php + +namespace SimpleLogger; + +use RuntimeException; +use Psr\Log\LogLevel; + +/** + * Syslog Logger + * + * @package SimpleLogger + * @author Frédéric Guillot + */ +class Syslog extends Base +{ + /** + * Setup Syslog configuration + * + * @param string $ident Application name + * @param int $facility See http://php.net/manual/en/function.openlog.php + */ + public function __construct($ident = 'PHP', $facility = LOG_USER) + { + if (! openlog($ident, LOG_ODELAY | LOG_PID, $facility)) { + throw new RuntimeException('Unable to connect to syslog.'); + } + } + + /** + * Get syslog priority according to Psr\LogLevel + * + * @param mixed $level + * @return integer + */ + public function getSyslogPriority($level) + { + switch ($level) { + case LogLevel::EMERGENCY: + return LOG_EMERG; + case LogLevel::ALERT: + return LOG_ALERT; + case LogLevel::CRITICAL: + return LOG_CRIT; + case LogLevel::ERROR: + return LOG_ERR; + case LogLevel::WARNING: + return LOG_WARNING; + case LogLevel::NOTICE: + return LOG_NOTICE; + case LogLevel::INFO: + return LOG_INFO; + } + + return LOG_DEBUG; + } + + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string $message + * @param array $context + * @return null + */ + public function log($level, $message, array $context = array()) + { + $syslogPriority = $this->getSyslogPriority($level); + $syslogMessage = $this->interpolate($message, $context); + + syslog($syslogPriority, $syslogMessage); + } +} |