Skip to content

Commit

Permalink
logging: Allow logging to web server error_log
Browse files Browse the repository at this point in the history
This commit adds a new configuration option `logger_destination`
allowing to choose between Monolog’s ErrorLogHandler and StreamHandler.
  • Loading branch information
jtojnar committed Jan 8, 2018
1 parent 398b1af commit b1f2263
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- It is possible to set tag or source to be opened after user logs in ([#927](https://github.com/SSilence/selfoss/pull/927))
- Displaying multiple images from tweets with galleries is supported ([#934](https://github.com/SSilence/selfoss/pull/934))
- Quoted tweets are supported ([#934](https://github.com/SSilence/selfoss/pull/934))
- Logging destination can be changed ([#1004](https://github.com/SSilence/selfoss/pull/1004))

### Bug fixes
- Fixed Full-text RSS spout ([#897](https://github.com/SSilence/selfoss/pull/897))
Expand Down
6 changes: 5 additions & 1 deletion _docs/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ <h2 id="configuration_params">Configuration</h2>
<td class="documentation-first-column">db_port</td>
<td>port for database connections (3306 for mysql, 5432 for PostgreSQL</td>
</tr>
<tr>
<td class="documentation-first-column">logger_destination</td>
<td>By default, the logs are saved to <code>data/logs/default.log</code> but you can choose a different file by specifying a file path prefixed by <code>file:</code>. Setting <code>file:php://stderr</code> is especially useful when running selfoss on a PaaS or inside Docker. Alternately, you can set the option to <code>error_log</code> to redirect the messages to <a href="https://secure.php.net/manual/en/function.error-log.php">SAPI error log</a> – handy for PHP-FPM, which <a href="https://secure.php.net/manual/en/install.fpm.configuration.php#catch-workers-output">discards stderr</a> by default.</td>
</tr>
<tr>
<td class="documentation-first-column">logger_level</td>
<td>set logging level – following logging levels are available: <code>EMERGENCY</code>, <code>ALERT</code>, <code>CRITICAL</code>, <code>ERROR</code>, <code>WARNING</code>, <code>NOTICE</code>, <code>INFO</code>, <code>DEBUG</code>. Additionally, you can use <code>NONE</code> pseudo-level to turn the logging off completely.<br>Use this for troubleshooting on updating feeds (but be aware that the log file can become very large.) The logged messages will be saved to <code>/data/logs/default.log</code>.</td>
<td>set logging level – following logging levels are available: <code>EMERGENCY</code>, <code>ALERT</code>, <code>CRITICAL</code>, <code>ERROR</code>, <code>WARNING</code>, <code>NOTICE</code>, <code>INFO</code>, <code>DEBUG</code>. Additionally, you can use <code>NONE</code> pseudo-level to turn the logging off completely.<br>Use this for troubleshooting on updating feeds (but be aware that the log file can become very large.)</td>
</tr>
<tr>
<td class="documentation-first-column">items_perpage</td>
Expand Down
13 changes: 12 additions & 1 deletion common.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Monolog\Formatter\LineFormatter;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

Expand Down Expand Up @@ -39,7 +40,17 @@
// init logger
$log = new Logger('selfoss');
if ($f3->get('logger_level') !== 'NONE') {
$handler = new StreamHandler(__DIR__ . '/data/logs/default.log', $f3->get('logger_level'));
$logger_destination = $f3->get('logger_destination');

if (strpos($logger_destination, 'file:') === 0) {
$handler = new StreamHandler(substr($logger_destination, 5), $f3->get('logger_level'));
} elseif ($logger_destination === 'error_log') {
$handler = new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, $f3->get('logger_level'));
} else {
echo 'The `logger_destination` option needs to be either `error_log` or a file path prefixed by `file:`.';
exit;
}

$formatter = new LineFormatter(null, null, true, true);
$formatter->includeStacktraces(true);
$handler->setFormatter($formatter);
Expand Down
1 change: 1 addition & 0 deletions defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ db_username=root
db_password=
db_port=
db_prefix=
logger_destination=file:data/logs/default.log
logger_level=ERROR
items_perpage=50
items_lifetime=30
Expand Down

0 comments on commit b1f2263

Please sign in to comment.