Skip to content

Commit

Permalink
Add system log driver and use it by default
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Mar 5, 2018
1 parent 299198f commit 95ac11a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
25 changes: 25 additions & 0 deletions app/Core/Log/System.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Kanboard\Core\Log;

/**
* Built-in PHP Logger
*
* @package Kanboard\Core\Log
* @author Frédéric Guillot
*/
class System extends Base
{
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log($level, $message, array $context = [])
{
error_log('['.$level.'] '.$this->interpolate($message, $context));
}
}
4 changes: 4 additions & 0 deletions app/ServiceProvider/LoggingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Kanboard\Core\Log\Stdout;
use Kanboard\Core\Log\Syslog;
use Kanboard\Core\Log\File;
use Kanboard\Core\Log\System;

/**
* Class LoggingProvider
Expand Down Expand Up @@ -37,6 +38,9 @@ public function register(Container $container)
case 'file':
$driver = new File(LOG_FILE);
break;
case 'system':
$driver = new System();
break;
}

if ($driver !== null) {
Expand Down
4 changes: 2 additions & 2 deletions app/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
// Enable/disable debug
defined('DEBUG') or define('DEBUG', strtolower(getenv('DEBUG')) === 'true');

// Logging drivers: syslog, stdout, stderr or file
defined('LOG_DRIVER') or define('LOG_DRIVER', '');
// Logging drivers: syslog, stdout, stderr, system or file
defined('LOG_DRIVER') or define('LOG_DRIVER', 'system');

// Logging file
defined('LOG_FILE') or define('LOG_FILE', DATA_DIR.DIRECTORY_SEPARATOR.'debug.log');
Expand Down
4 changes: 2 additions & 2 deletions config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
// Enable/Disable debug
define('DEBUG', false);

// Available log drivers: syslog, stderr, stdout or file
define('LOG_DRIVER', '');
// Available log drivers: syslog, stderr, stdout, system or file
define('LOG_DRIVER', 'system');

// Log filename if the log driver is "file"
define('LOG_FILE', DATA_DIR.DIRECTORY_SEPARATOR.'debug.log');
Expand Down
7 changes: 4 additions & 3 deletions doc/en_US/config.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ Enable/Disable debug mode

```php
define('DEBUG', true);
define('LOG_DRIVER', 'file'); // Other drivers are: syslog, stdout, stderr or file
define('LOG_DRIVER', 'file'); // Other drivers are: syslog, stdout, stderr, system or file

// By default, the log file is in data/debug.log but you can change the path:
define('LOG_FILE', '/path/to/debug.log');
```

The log driver must be defined if you enable the debug mode.
The debug mode logs all SQL queries and the time taken to generate pages.
- The log driver must be defined if you enable the debug mode.
- The debug mode logs all SQL queries and the time taken to generate pages.
- The `system` driver use the built-in PHP logger which could be configured in the [php.ini](http://php.net/manual/en/errorfunc.configuration.php#ini.error-log). By default, log messages are sent to the web server logs.

Plugins
-------
Expand Down
2 changes: 1 addition & 1 deletion doc/en_US/installation.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ From the archive (stable version)
The `data` folder is used to store:

- Sqlite database: `db.sqlite`
- Debug file: `debug.log` (if debug mode is enabled)
- Debug file: `debug.log` (if debug mode is enabled with the `file` driver)
- Uploaded files: `files/*`
- Image thumbnails: `files/thumbnails/*`

Expand Down
2 changes: 1 addition & 1 deletion docker/var/www/app/config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

define('ENABLE_URL_REWRITE', true);
define('LOG_DRIVER', 'stderr');
define('LOG_DRIVER', 'system');

0 comments on commit 95ac11a

Please sign in to comment.