mirror of
https://github.com/processwire/processwire.git
synced 2025-08-16 03:34:33 +02:00
Add WireLog::disable() and WireLog::enable() functions to temporary disable (and later enable) a log during runtime
This commit is contained in:
@@ -29,6 +29,14 @@ class WireLog extends Wire {
|
|||||||
*/
|
*/
|
||||||
protected $fileLogs = array();
|
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)
|
* 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()) {
|
public function ___save($name, $text, $options = array()) {
|
||||||
|
|
||||||
|
if(isset($this->disabled[$name]) || isset($this->disabled['*'])) return false;
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
'showUser' => true,
|
'showUser' => true,
|
||||||
'showURL' => true,
|
'showURL' => true,
|
||||||
'user' => null,
|
'user' => null,
|
||||||
'url' => '', // URL to show (default=blank, auto-detect)
|
'url' => '', // URL to show (default=blank, auto-detect)
|
||||||
'delimiter' => "\t",
|
'delimiter' => "\t",
|
||||||
);
|
);
|
||||||
|
|
||||||
$options = array_merge($defaults, $options);
|
$options = array_merge($defaults, $options);
|
||||||
// showURL option was previously named showPage
|
// showURL option was previously named showPage
|
||||||
@@ -479,4 +489,32 @@ class WireLog extends Wire {
|
|||||||
return $log;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user