Skip to content

Commit

Permalink
Allow a specific array of exceptions to not be logged. (#1843)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyiq committed Mar 28, 2024
1 parent b0ba279 commit 6477f8d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
27 changes: 18 additions & 9 deletions classes/exceptions/Exceptions.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,25 @@ public function __construct($msg_code, $log = null)
if ($log && (!is_array($log) || !preg_match('`[a-z]`', key($log)))) {
$log = array('exception' => $log);
}

$exceptionClassName = get_class($this);
if (Utilities::configMatchInArray(
'exception_skip_logging',
$exceptionClassName
)) {
// skip logging this
} else {

// Log info
if ($log) {
foreach ($log as $category => $lines) {
if (!is_array($lines)) {
$lines = array($lines);
}

foreach ($lines as $line) {
$this->log($category, $line);
// Log info
if ($log) {
foreach ($log as $category => $lines) {
if (!is_array($lines)) {
$lines = array($lines);
}

foreach ($lines as $line) {
$this->log($category, $line);
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions classes/utils/Utilities.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,30 @@ public static function configMatch($configkey, $needle)
return false;
}

/**
* This is like configMatch but expects the config key to be an array and will
* need an explicit string match of the $needle in the value for the key to be
* considered a match.
*/
public static function configMatchInArray($configkey, $needle)
{
$cfg = Config::get($configkey);
if( !$cfg ) {
return false;
}
if (!is_array($cfg) && !strlen($cfg)) {
return false;
}

// we now know the key is active, so get it as an array
$a = Config::getArray($configkey);

if (in_array( $needle, $a )) {
return true;
}
return false;
}

/**
* Read a value from an array validating the result.
* If the array doesn't have the key or validation fails
Expand Down
15 changes: 15 additions & 0 deletions docs/v2.0/admin/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ A note about colours;
* [logs_limit_messages_from_same_ip_address](#logs_limit_messages_from_same_ip_address)
* [trackingevents_lifetime](#trackingevents_lifetime)
* [client_ip_key](#client_ip_key)
* [exception_skip_logging](#exception_skip_logging)

## Webservices API

Expand Down Expand Up @@ -3129,6 +3130,20 @@ $config['log_facilities'] =
* __comment:__ Client identifier. Usually the default is fine, however when you have reverse proxy setups, you may need to change this to HTTP_CLIENT_IP, HTTP_X_REAL_IP, HTTP_X_FORWARDED_FOR, depending on your setup.


### exception_skip_logging

* __description:__ An array of exception class names to ignore during logging
* __mandatory:__ no
* __type:__ array of string
* __default__:
* __available:__ v2.48
* __comment:__ A list of php exception class names to not trigger logging messages. For example:
<pre><code>
$config['exception_skip_logging'] = array('AuthRemoteSignatureCheckFailedException');
</code></pre>



### logs_limit_messages_from_same_ip_address

* __description:__ An option to limit how frequently transfers from the same IP address are logged
Expand Down

0 comments on commit 6477f8d

Please sign in to comment.