ENH: Allow setting of ISO8601 via datepattern (default for systemd)

pull/364/head
Steven Hiscocks 2013-09-22 18:12:16 +01:00
parent 1f1a56174f
commit badf9d03b9
3 changed files with 16 additions and 6 deletions

View File

@ -123,6 +123,8 @@ class Beautifier:
msg = "Current date pattern set to: "
if response is None:
msg = msg + "Default Detectors"
elif response[0] is None:
msg = msg + "%s" % response[1]
else:
msg = msg + "%s (%s)" % response
elif inC[2] in ("ignoreip", "addignoreip", "delignoreip"):

View File

@ -28,7 +28,7 @@ from failmanager import FailManager
from ticket import FailTicket
from jailthread import JailThread
from datedetector import DateDetector
from datetemplate import DatePatternRegex
from datetemplate import DatePatternRegex, DateISO8601
from mytime import MyTime
from failregex import FailRegex, Regex, RegexException
@ -199,11 +199,15 @@ class Filter(JailThread):
def setDatePattern(self, pattern):
dateDetector = DateDetector()
template = DatePatternRegex()
if pattern[0] == "^": # Special extra to enable anchor
template.setPattern(pattern[1:], anchor=True)
if pattern == "ISO8601":
template = DateISO8601()
template.setName("ISO8601")
else:
template.setPattern(pattern, anchor=False)
template = DatePatternRegex()
if pattern[0] == "^": # Special extra to enable anchor
template.setPattern(pattern[1:], anchor=True)
else:
template.setPattern(pattern, anchor=False)
dateDetector.appendTemplate(template)
self.dateDetector = dateDetector
logSys.info("Date pattern set to `%r`: `%s`" %
@ -221,7 +225,10 @@ class Filter(JailThread):
if len(templates) > 1:
return None # Default Detectors in use
elif len(templates) == 1:
pattern = templates[0].getPattern()
if hasattr(templates[0], "getPattern"):
pattern = templates[0].getPattern()
else:
pattern = None
if templates[0].getRegex()[0] == "^":
pattern = "^" + pattern
return pattern, templates[0].getName()

View File

@ -57,6 +57,7 @@ class FilterSystemd(JournalFilter): # pragma: systemd no cover
# Initialise systemd-journal connection
self.__journal = journal.Reader(converters={'__CURSOR': lambda x: x})
self.__matches = []
self.setDatePattern("ISO8601")
logSys.debug("Created FilterSystemd")