added logging configuration

Log facitlities can now be disabled. By default only debug is disabled.
It might make sense to by default disable deprecated as well?

Debug logging is now independend of the allowdebug method. allowdebug
was often used in two ways: for displaying errors directly to the user
and for logging to the debug log. Now it only controls the former.
This commit is contained in:
Andreas Gohr 2020-08-13 20:28:52 +02:00
parent 31667ec678
commit cad4fbf6e2
6 changed files with 28 additions and 16 deletions

View File

@ -111,6 +111,7 @@ $conf['mailfrom'] = ''; //use this email when sending mails
$conf['mailreturnpath'] = ''; //use this email as returnpath for bounce mails
$conf['mailprefix'] = ''; //use this as prefix of outgoing mails
$conf['htmlmail'] = 1; //send HTML multipart mails
$conf['dontlog'] = 'debug'; //logging facilites that should be disabled
/* Syndication Settings */
$conf['sitemap'] = 0; //Create a google sitemap? How often? In days.

View File

@ -14,6 +14,8 @@ class Logger
/** @var string what kind of log is this */
protected $facility;
protected $isLogging = true;
/**
* Logger constructor.
*
@ -21,7 +23,13 @@ class Logger
*/
protected function __construct($facility)
{
global $conf;
$this->facility = $facility;
// Should logging be disabled for this facility?
$dontlog = explode(',', $conf['dontlog']);
$dontlog = array_map('trim', $dontlog);
if (in_array($facility, $dontlog)) $this->isLogging = false;
}
/**
@ -45,7 +53,7 @@ class Logger
* @param mixed $details Any details that should be added to the log entry
* @param string $file A source filename if this is related to a source position
* @param int $line A line number for the above file
* @return bool
* @return bool has a log been written?
*/
static public function error($message, $details = null, $file = '', $line = 0)
{
@ -61,7 +69,7 @@ class Logger
* @param mixed $details Any details that should be added to the log entry
* @param string $file A source filename if this is related to a source position
* @param int $line A line number for the above file
* @return bool
* @return bool has a log been written?
*/
static public function debug($message, $details = null, $file = '', $line = 0)
{
@ -77,7 +85,7 @@ class Logger
* @param mixed $details Any details that should be added to the log entry
* @param string $file A source filename if this is related to a source position
* @param int $line A line number for the above file
* @return bool
* @return bool has a log been written?
*/
static public function deprecated($message, $details = null, $file = '', $line = 0)
{
@ -93,10 +101,12 @@ class Logger
* @param mixed $details Any details that should be added to the log entry
* @param string $file A source filename if this is related to a source position
* @param int $line A line number for the above file
* @return bool
* @return bool has a log been written?
*/
public function log($message, $details = null, $file = '', $line = 0)
{
if(!$this->isLogging) return false;
// details are logged indented
if ($details) {
if (!is_string($details)) {

View File

@ -422,7 +422,7 @@ function dbg($msg,$hidden=false){
}
/**
* Print info to a log file
* Print info to debug log file
*
* @author Andreas Gohr <andi@splitbrain.org>
* @deprecated 2020-08-13
@ -430,18 +430,10 @@ function dbg($msg,$hidden=false){
* @param string $header
*/
function dbglog($msg,$header=''){
global $conf;
dbg_deprecated('\\dokuwiki\\Logger');
// The debug log isn't automatically cleaned thus only write it when
// debugging has been enabled by the user.
if($conf['allowdebug'] !== 1) return;
if(is_object($msg) || is_array($msg)){
$msg = print_r($msg,true);
}
// was the msg as single line string? use it as header
if($header === '' && strpos($msg, "\n") === false) {
if($header === '' && is_string($msg) && strpos($msg, "\n") === false) {
$header = $msg;
$msg = '';
}

View File

@ -147,6 +147,7 @@ $lang['mailfrom'] = 'Sender email address to use for automatic mails';
$lang['mailreturnpath'] = 'Recipient email address for non delivery notifications';
$lang['mailprefix'] = 'Email subject prefix to use for automatic mails. Leave blank to use the wiki title';
$lang['htmlmail'] = 'Send better looking, but larger in size HTML multipart emails. Disable for plain text only mails.';
$lang['dontlog'] = 'Disable logging for these types of logs.';
/* Syndication Settings */
$lang['sitemap'] = 'Generate Google sitemap this often (in days). 0 to disable';

View File

@ -199,6 +199,14 @@ $meta['mailfrom'] = array('email', '_placeholders' => true);
$meta['mailreturnpath'] = array('email', '_placeholders' => true);
$meta['mailprefix'] = array('string');
$meta['htmlmail'] = array('onoff');
$meta['dontlog'] = array(
'disableactions',
'_choices' => array(
'error',
'debug',
'deprecated',
),
);
$meta['_syndication'] = array('fieldset');
$meta['sitemap'] = array('numeric');

View File

@ -1,8 +1,8 @@
====== View Logs ======
This interface allows you to view the various logs that are written by DokuWiki. By default, there shouldn't be logged
much here (it depends on your log settings). However if something goes wrong, chances are high, you'll find useful info
here. All times are UTC!
much here (it depends on your [[doku>config:dontlog|log settings]]). However if something goes wrong, chances are high,
you'll find useful info here. All times are UTC!
Please be aware **log files can contain sensitive information** like passwords, paths or other secrets.
Be sure to redact the logs appropriately when posting them on the forum or in bug reports!