summaryrefslogtreecommitdiff
path: root/lib/Kolab/FreeBusy/Logger.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Kolab/FreeBusy/Logger.php')
-rw-r--r--lib/Kolab/FreeBusy/Logger.php27
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/Kolab/FreeBusy/Logger.php b/lib/Kolab/FreeBusy/Logger.php
index 552c7e0..8af607c 100644
--- a/lib/Kolab/FreeBusy/Logger.php
+++ b/lib/Kolab/FreeBusy/Logger.php
@@ -4,6 +4,7 @@ namespace Kolab\FreeBusy;
use Monolog\Logger as Monologger;
use Monolog\Handler\StreamHandler;
+use Monolog\Handler\SyslogHandler;
use Monolog\Handler\NullHandler;
/**
@@ -18,16 +19,22 @@ class Logger
*/
public static function get($name, $level = 0)
{
- if (!isset(self::$instances[$name])) {
+ if (!isset(self::$instances[$name]) || ($level && !self::$instances[$name]->isHandling($level))) {
$logger = new Monologger($name);
- // TODO: support more log drivers
+ // read log config
$config = Config::getInstance();
+ $identity = $config->get('log.name', 'freebusy');
+ $loglevel = $level ?: $config->get('log.level', Monologger::INFO);
+
switch ($config->get('log.driver')) {
case 'file':
- $logdir = self::realpath($config->get('log.path'));
- $loglevel = $level ?: $config->get("log.level", Monologger::INFO);
- $logger->pushHandler(new StreamHandler($logdir . $name. '.log', $loglevel));
+ $logdir = Utils::abspath($config->get('log.path'), '/');
+ $logger->pushHandler(new StreamHandler($logdir . $identity . '.log', $loglevel));
+ break;
+
+ case 'syslog':
+ $logger->pushHahdler(new SyslogHandler($identity, $config->get('log.facility', 'user'), $loglevel));
break;
default:
@@ -41,15 +48,5 @@ class Logger
return self::$instances[$name];
}
- /**
- * Resolve the given directory to a real path ending with a /
- */
- private static function realpath($dirname)
- {
- if ($dirname[0] != '/')
- $dirname = realpath(KOLAB_FREEBUSY_ROOT . '/' . $dirname);
-
- return rtrim($dirname, '/') . '/';
- }
}