commit f773a8a72bcc470cb03e7af1fa1b79e895bbcd9a Author: Damian Johnson atagar@torproject.org Date: Sat Jun 18 17:36:03 2011 -0700
Config option for log regex patterns
Allowing the regular expression log filters to be preconfigured in the user's armrrc. --- armrc.sample | 4 ++++ src/cli/logPanel.py | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/armrc.sample b/armrc.sample index a81c9d8..54e3f7b 100644 --- a/armrc.sample +++ b/armrc.sample @@ -76,6 +76,8 @@ features.confirmQuit true # maxRefreshRate # rate limiting (in milliseconds) for drawing the log if updates are made # rapidly (for instance, when at the DEBUG runlevel) +# regex +# preconfigured regular expression pattern, up to five will be loaded
features.log.showDateDividers true features.log.showDuplicateEntries false @@ -84,6 +86,8 @@ features.log.maxLinesPerEntry 4 features.log.prepopulate true features.log.prepopulateReadLimit 5000 features.log.maxRefreshRate 300 +#features.log.regex My First Regex Pattern +#features.log.regex ^My Second Regex Pattern$
# Paremters for the config panel # --------------------------- diff --git a/src/cli/logPanel.py b/src/cli/logPanel.py index fc3bfc3..2561416 100644 --- a/src/cli/logPanel.py +++ b/src/cli/logPanel.py @@ -48,12 +48,14 @@ DEFAULT_CONFIG = {"features.logFile": "", "features.log.prepopulate": True, "features.log.prepopulateReadLimit": 5000, "features.log.maxRefreshRate": 300, + "features.log.regex": [], "cache.logPanel.size": 1000, "log.logPanel.prepopulateSuccess": log.INFO, "log.logPanel.prepopulateFailed": log.WARN, "log.logPanel.logFileOpened": log.NOTICE, "log.logPanel.logFileWriteFailed": log.ERR, - "log.logPanel.forceDoubleRedraw": log.DEBUG} + "log.logPanel.forceDoubleRedraw": log.DEBUG, + "log.configEntryTypeError": log.NOTICE}
DUPLICATE_MSG = " [%i duplicate%s hidden]"
@@ -562,6 +564,9 @@ class LogPanel(panel.Panel, threading.Thread): # config options. loadLogMessages()
+ # regex filters the user has defined + self.filterOptions = [] + self._config = dict(DEFAULT_CONFIG)
if config: @@ -570,6 +575,17 @@ class LogPanel(panel.Panel, threading.Thread): "features.log.prepopulateReadLimit": 0, "features.log.maxRefreshRate": 10, "cache.logPanel.size": 1000}) + + for filter in self._config["features.log.regex"]: + # checks if we can't have more filters + if len(self.filterOptions) >= MAX_REGEX_FILTERS: break + + try: + re.compile(filter) + self.filterOptions.append(filter) + except re.error, exc: + msg = "Invalid regular expression pattern (%s): %s" % (exc, filter) + log.log(self._config["log.configEntryTypeError"], msg)
# collapses duplicate log entries if false, showing only the most recent self.showDuplicates = self._config["features.log.showDuplicateEntries"] @@ -582,7 +598,6 @@ class LogPanel(panel.Panel, threading.Thread): self.msgLog = [] # log entries, sorted by the timestamp self.loggedEvents = loggedEvents # events we're listening to self.regexFilter = None # filter for presented log events (no filtering if None) - self.filterOptions = [] # filters the user has input self.lastContentHeight = 0 # height of the rendered content when last drawn self.logFile = None # file log messages are saved to (skipped if None) self.scroll = 0
tor-commits@lists.torproject.org