From 6477f8d6ce241438434c8a38be6d565fe59bd8fc Mon Sep 17 00:00:00 2001 From: monkeyiq Date: Thu, 28 Mar 2024 11:35:04 +1000 Subject: [PATCH] Allow a specific array of exceptions to not be logged. (#1843) --- classes/exceptions/Exceptions.class.php | 27 ++++++++++++++++--------- classes/utils/Utilities.class.php | 24 ++++++++++++++++++++++ docs/v2.0/admin/configuration/index.md | 15 ++++++++++++++ 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/classes/exceptions/Exceptions.class.php b/classes/exceptions/Exceptions.class.php index e5985fd99..603418a57 100644 --- a/classes/exceptions/Exceptions.class.php +++ b/classes/exceptions/Exceptions.class.php @@ -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); + } } } } diff --git a/classes/utils/Utilities.class.php b/classes/utils/Utilities.class.php index 5b49f2135..4a08d8e6c 100644 --- a/classes/utils/Utilities.class.php +++ b/classes/utils/Utilities.class.php @@ -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 diff --git a/docs/v2.0/admin/configuration/index.md b/docs/v2.0/admin/configuration/index.md index 2a8a899d9..16719a6dc 100644 --- a/docs/v2.0/admin/configuration/index.md +++ b/docs/v2.0/admin/configuration/index.md @@ -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 @@ -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: +

+      $config['exception_skip_logging'] = array('AuthRemoteSignatureCheckFailedException');
+    
+ + + ### logs_limit_messages_from_same_ip_address * __description:__ An option to limit how frequently transfers from the same IP address are logged