1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 02:04:35 +02:00

Add WireLog::disable() and WireLog::enable() functions to temporary disable (and later enable) a log during runtime

This commit is contained in:
Ryan Cramer
2019-12-27 15:55:08 -05:00
parent deb2065465
commit 7d4ef4b786

View File

@@ -29,6 +29,14 @@ class WireLog extends Wire {
*/
protected $fileLogs = array();
/**
* Names of logs that have been temporary silenced for this request
*
* @var array Keys are log names, values are irrelevant
*
*/
protected $disabled = array();
/**
* Record an informational or 'success' message in the message log (messages.txt)
*
@@ -111,13 +119,15 @@ class WireLog extends Wire {
*/
public function ___save($name, $text, $options = array()) {
if(isset($this->disabled[$name]) || isset($this->disabled['*'])) return false;
$defaults = array(
'showUser' => true,
'showURL' => true,
'user' => null,
'url' => '', // URL to show (default=blank, auto-detect)
'delimiter' => "\t",
);
);
$options = array_merge($defaults, $options);
// showURL option was previously named showPage
@@ -479,4 +489,32 @@ class WireLog extends Wire {
return $log;
}
/**
* Disable the given log name temporarily so that save() calls do not record entries during this request
*
* @param string $name Log name or specify '*' to disable all
* @return self
* @since 3.0.148
* @see WireLog::enable()
*
*/
public function disable($name) {
if(!empty($name)) $this->disabled[$name] = true;
return $this;
}
/**
* Enable a previously disabled log
*
* @param string $name Log name or specify '*' to reverse a previous disable('*') call.
* @return self
* @since 3.0.148
* @see WireLog::disable()
*
*/
public function enable($name) {
unset($this->disabled[$name]);
return $this;
}
}