From 46a8d5ec659c02e2a1cc82ca57b4ccef3f2dad71 Mon Sep 17 00:00:00 2001 From: Samuel Demirdjian Date: Fri, 13 Nov 2015 10:12:10 +0200 Subject: [PATCH 1/4] Add the ability to filter logs by message body using regex pattern --- classes/Kohana/Log/Filter/Body.php | 42 ++++++++++++++++++++++++++++++ classes/Log/Filter/Body.php | 3 +++ 2 files changed, 45 insertions(+) create mode 100644 classes/Kohana/Log/Filter/Body.php create mode 100644 classes/Log/Filter/Body.php diff --git a/classes/Kohana/Log/Filter/Body.php b/classes/Kohana/Log/Filter/Body.php new file mode 100644 index 000000000..2c9b2ad96 --- /dev/null +++ b/classes/Kohana/Log/Filter/Body.php @@ -0,0 +1,42 @@ +regex_pattern = $regex_pattern; + } + + public function process(array $messages) + { + $filtered = array(); + + foreach ($messages as $message) + { + if (preg_match($this->regex_pattern, $message['body'])) + { + $filtered[] = $message; + } + } + + return $filtered; + } + +} diff --git a/classes/Log/Filter/Body.php b/classes/Log/Filter/Body.php new file mode 100644 index 000000000..db0bf2543 --- /dev/null +++ b/classes/Log/Filter/Body.php @@ -0,0 +1,3 @@ + Date: Fri, 13 Nov 2015 10:12:36 +0200 Subject: [PATCH 2/4] Add the ability to filter logs by originating file using regex pattern --- classes/Kohana/Log/Filter/File.php | 42 ++++++++++++++++++++++++++++++ classes/Log/Filter/File.php | 3 +++ 2 files changed, 45 insertions(+) create mode 100644 classes/Kohana/Log/Filter/File.php create mode 100644 classes/Log/Filter/File.php diff --git a/classes/Kohana/Log/Filter/File.php b/classes/Kohana/Log/Filter/File.php new file mode 100644 index 000000000..950476a00 --- /dev/null +++ b/classes/Kohana/Log/Filter/File.php @@ -0,0 +1,42 @@ +regex_pattern = $regex_pattern; + } + + public function process(array $messages) + { + $filtered = array(); + + foreach ($messages as $message) + { + if (preg_match($this->regex_pattern, $message['file'])) + { + $filtered[] = $message; + } + } + + return $filtered; + } + +} diff --git a/classes/Log/Filter/File.php b/classes/Log/Filter/File.php new file mode 100644 index 000000000..5d1292249 --- /dev/null +++ b/classes/Log/Filter/File.php @@ -0,0 +1,3 @@ + Date: Fri, 13 Nov 2015 11:12:22 +0200 Subject: [PATCH 3/4] Add the ability to filter logs when generated through exception --- classes/Kohana/Log/Filter/Exception.php | 46 +++++++++++++++++++++++++ classes/Log/Filter/Exception.php | 3 ++ 2 files changed, 49 insertions(+) create mode 100644 classes/Kohana/Log/Filter/Exception.php create mode 100644 classes/Log/Filter/Exception.php diff --git a/classes/Kohana/Log/Filter/Exception.php b/classes/Kohana/Log/Filter/Exception.php new file mode 100644 index 000000000..de07fe993 --- /dev/null +++ b/classes/Kohana/Log/Filter/Exception.php @@ -0,0 +1,46 @@ +exception = $exception; + } + + public function process(array $messages) + { + $filtered = array(); + + foreach ($messages as $message) + { + if ( + (isset($message['exception'])) + AND + ($message['exception'] instanceof $this->exception) + ) + { + $filtered[] = $message; + } + } + + return $filtered; + } + +} diff --git a/classes/Log/Filter/Exception.php b/classes/Log/Filter/Exception.php new file mode 100644 index 000000000..3748441d8 --- /dev/null +++ b/classes/Log/Filter/Exception.php @@ -0,0 +1,3 @@ + Date: Fri, 13 Nov 2015 11:53:03 +0200 Subject: [PATCH 4/4] Add log filter union to combine results of filters (OR logic) --- classes/Kohana/Log/Filter/Union.php | 68 +++++++++++++++++++++++++++++ classes/Log/Filter/Union.php | 3 ++ 2 files changed, 71 insertions(+) create mode 100644 classes/Kohana/Log/Filter/Union.php create mode 100644 classes/Log/Filter/Union.php diff --git a/classes/Kohana/Log/Filter/Union.php b/classes/Kohana/Log/Filter/Union.php new file mode 100644 index 000000000..8b5a5ea22 --- /dev/null +++ b/classes/Kohana/Log/Filter/Union.php @@ -0,0 +1,68 @@ +attach_filter($filter); + } + } + + public function process(array $messages) + { + $filtered = array(); + + foreach ($this->filters as $filter) + { + $filtered[] = $filter->process($messages); + } + + return array_unique($filtered); + } + + /** + * Ataches a log filter + * + * @param Kohana_Log_Filter $filter + * @return Log_Filter_Union + */ + public function attach_filter(Kohana_Log_Filter $filter) + { + $this->filters[spl_object_hash($filter)] = $filter; + + return $this; + } + + /** + * Detaches a log filter + * + * @param Kohana_Log_Filter $filter + * @return Log_Filter_Union + */ + public function detach_filter(Kohana_Log_Filter $filter) + { + unset($this->filters[spl_object_hash($filter)]); + + return $this; + } + + public function filter(array $messages) + { + return $this->process($messages); + } +} diff --git a/classes/Log/Filter/Union.php b/classes/Log/Filter/Union.php new file mode 100644 index 000000000..fcc0b105b --- /dev/null +++ b/classes/Log/Filter/Union.php @@ -0,0 +1,3 @@ +