From 2b484191264721466754cd44949ba48c1785136d Mon Sep 17 00:00:00 2001 From: victorsndvg Date: Thu, 18 Oct 2018 13:42:53 +0200 Subject: [PATCH 1/4] Update LogFilter.py Clean prints --- Logger/LogFilter.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Logger/LogFilter.py b/Logger/LogFilter.py index 48f95b0..e4d91b3 100644 --- a/Logger/LogFilter.py +++ b/Logger/LogFilter.py @@ -6,8 +6,6 @@ def __init__(self, attributes): self.pattern = attributes.pop('pattern') self.attributes = attributes self.regex = re.compile(self.pattern) - print(self.attributes) - print(self.to_json('blah')) def match(self, string): return self.regex.match(string) From f272dbdcf8b1796512788b28b8f562f2e19e1a9e Mon Sep 17 00:00:00 2001 From: victorsndvg Date: Fri, 19 Oct 2018 15:02:29 +0200 Subject: [PATCH 2/4] Add skip log lines feature Add more flexibility for the regex method used (future implementation) --- Logger/LogBuffer.py | 11 ++++++----- Logger/LogFilter.py | 30 +++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Logger/LogBuffer.py b/Logger/LogBuffer.py index 5b45c32..6b7a337 100644 --- a/Logger/LogBuffer.py +++ b/Logger/LogBuffer.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os, re, json -from LogFilter import LogFilter, LogFilterSet +import os, re, json, logging +from LogFilter import LogFilter, LogFilterSet, LogSkipException class LogBuffer(): @@ -11,8 +11,10 @@ def __init__(self, filters): self.stack = [] def append(self, string): - self.stack.append(self.filters.apply(string)) - #print self.filters.apply(string) + try: + self.stack.append(self.filters.apply(string)) + except LogSkipException as skip: + logging.debug(str(skip)) def push(self, string): self.temp += string @@ -32,4 +34,3 @@ def pop(self): if self.stack: return self.stack.pop(0) - diff --git a/Logger/LogFilter.py b/Logger/LogFilter.py index e4d91b3..81be69d 100644 --- a/Logger/LogFilter.py +++ b/Logger/LogFilter.py @@ -1,14 +1,27 @@ import os, re, json +class LogSkipException(Exception): + + def __init__(self, pattern, message): + self.expression = pattern + self.message = message + super(Exception, self).__init__('[SKIP] pattern: "'+str(pattern)+'", string: "'+message+'"') + + class LogFilter(): def __init__(self, attributes): - self.pattern = attributes.pop('pattern') - self.attributes = attributes + self.pattern = attributes.pop('pattern') self.regex = re.compile(self.pattern) + self.action = getattr(self.regex, attributes.pop('action', 'match'), self.regex.match) + self.serialize = self.skip if attributes.pop('ignore', False) else self.to_json + self.attributes = attributes - def match(self, string): - return self.regex.match(string) + def skip(self, string): + raise LogSkipException(self.pattern, string) + + def apply(self, string): + return self.action(string) def to_json(self, string): tmp = {'string':string} @@ -20,16 +33,19 @@ class DummyLogFilter(LogFilter): def __init__(self, pattern): self.attributes = {} + self.serialize = self.to_json - def match(self, string): + def apply(self, string): return True class LogFilterSet(): def __init__(self, filters): - self.filters = filters + self.filters = filters or [] self.filters.append(DummyLogFilter(pattern="*")) def apply(self, string): for filter in self.filters: - if filter.match(string): return filter.to_json(string) + if filter.apply(string): + return filter.serialize(string) + From 902e1589adf0d0fd88539f45df28da41c376a699 Mon Sep 17 00:00:00 2001 From: victorsndvg Date: Wed, 31 Oct 2018 17:04:04 +0100 Subject: [PATCH 3/4] Update LogFilter.py Change 'ignore' by 'skip' for coherence --- Logger/LogFilter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Logger/LogFilter.py b/Logger/LogFilter.py index 81be69d..25ddbb8 100644 --- a/Logger/LogFilter.py +++ b/Logger/LogFilter.py @@ -14,7 +14,7 @@ def __init__(self, attributes): self.pattern = attributes.pop('pattern') self.regex = re.compile(self.pattern) self.action = getattr(self.regex, attributes.pop('action', 'match'), self.regex.match) - self.serialize = self.skip if attributes.pop('ignore', False) else self.to_json + self.serialize = self.skip if attributes.pop('skip', False) else self.to_json self.attributes = attributes def skip(self, string): From 4d004d4c6f3df18f86eaa3fadf12ecbdc058ec0b Mon Sep 17 00:00:00 2001 From: victorsndvg Date: Wed, 18 Dec 2019 10:30:53 +0100 Subject: [PATCH 4/4] default config --- test/config.yaml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/config.yaml b/test/config.yaml index 4444f1b..e83c49d 100644 --- a/test/config.yaml +++ b/test/config.yaml @@ -1,13 +1,12 @@ { - "host": "im.srv.cesga.es", + "host": "localhost", "port": 5672, - "user": "mso4sc", - "pass": "remotelogger", + "user": "guest", + "pass": "guest", "exchange": "exchange", "exchange_type": "direct", - "routing_key": "routing_key2", - "queue": "queue11", + "routing_key": "routing_key", + "queue": "queue", "heartbeat": 0, "blocked_connection_timeout": 300 } -