diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-05-07 14:40:49 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-05-07 14:40:49 -0400 |
commit | 6361131d3f03bdc6f5642bfda8e1f165239d593a (patch) | |
tree | 1bcd0e73715502d516f08494fd71270c072492a7 /app | |
parent | 300dabe6b4e9e648c1111363fad8154def7cfb5f (diff) |
Improve logging
Diffstat (limited to 'app')
-rw-r--r-- | app/ServiceProvider/LoggingProvider.php | 29 | ||||
-rw-r--r-- | app/constants.php | 12 |
2 files changed, 29 insertions, 12 deletions
diff --git a/app/ServiceProvider/LoggingProvider.php b/app/ServiceProvider/LoggingProvider.php index 68c074f0..4d6adbe4 100644 --- a/app/ServiceProvider/LoggingProvider.php +++ b/app/ServiceProvider/LoggingProvider.php @@ -6,6 +6,8 @@ use Psr\Log\LogLevel; use Pimple\Container; use Pimple\ServiceProviderInterface; use SimpleLogger\Logger; +use SimpleLogger\Stderr; +use SimpleLogger\Stdout; use SimpleLogger\Syslog; use SimpleLogger\File; @@ -14,19 +16,32 @@ class LoggingProvider implements ServiceProviderInterface public function register(Container $container) { $logger = new Logger; + $driver = null; - if (ENABLE_SYSLOG) { - $syslog = new Syslog('kanboard'); - $syslog->setLevel(LogLevel::ERROR); - $logger->setLogger($syslog); + switch (LOG_DRIVER) { + case 'syslog': + $driver = new Syslog('kanboard'); + break; + case 'stdout': + $driver = new Stdout(); + break; + case 'stderr': + $driver = new Stderr(); + break; + case 'file': + $driver = new File(LOG_FILE); + break; } - if (DEBUG) { - $logger->setLogger(new File(DEBUG_FILE)); + if ($driver !== null) { + if (! DEBUG) { + $driver->setLevel(LogLevel::INFO); + } + + $logger->setLogger($driver); } $container['logger'] = $logger; - return $container; } } diff --git a/app/constants.php b/app/constants.php index b5b01960..6f30af7f 100644 --- a/app/constants.php +++ b/app/constants.php @@ -16,8 +16,13 @@ defined('FILES_DIR') or define('FILES_DIR', DATA_DIR.DIRECTORY_SEPARATOR.'files' defined('PLUGINS_DIR') or define('PLUGINS_DIR', ROOT_DIR.DIRECTORY_SEPARATOR.'plugins'); // Enable/disable debug -defined('DEBUG') or define('DEBUG', getenv('DEBUG')); -defined('DEBUG_FILE') or define('DEBUG_FILE', getenv('DEBUG_FILE') ?: DATA_DIR.DIRECTORY_SEPARATOR.'debug.log'); +defined('DEBUG') or define('DEBUG', strtolower(getenv('DEBUG')) === 'true'); + +// Logging drivers: syslog, stdout, stderr or file +defined('LOG_DRIVER') or define('LOG_DRIVER', getenv('LOG_DRIVER')); + +// Logging file +defined('LOG_FILE') or define('LOG_FILE', DATA_DIR.DIRECTORY_SEPARATOR.'debug.log'); // Application version defined('APP_VERSION') or define('APP_VERSION', build_app_version('$Format:%d$', '$Format:%H$')); @@ -96,9 +101,6 @@ defined('ENABLE_HSTS') or define('ENABLE_HSTS', true); // Enable or disable "X-Frame-Options: DENY" HTTP header defined('ENABLE_XFRAME') or define('ENABLE_XFRAME', true); -// Syslog -defined('ENABLE_SYSLOG') or define('ENABLE_SYSLOG', getenv('ENABLE_SYSLOG')); - // Escape html inside markdown text defined('MARKDOWN_ESCAPE_HTML') or define('MARKDOWN_ESCAPE_HTML', true); |