add plain text output capability
[logparse.git] / logparse / parsers / cron.py
index 2c7289b2a7315e0b04dc7c9b88c71b7d7de66f8e..3aba1408624e6eb7b59bcef80fcef26bcca3b20e 100644 (file)
@@ -14,9 +14,8 @@ import logging
 logger = logging.getLogger(__name__)
 
 def parse_log():
-    output = ''
     logger.debug("Starting cron section")
-    output += opentag('div', 1, 'cron', 'section')
+    section = Section("cron")
     matches = re.findall('.*CMD\s*\(\s*(?!.*cd)(.*)\)', readlog(config.prefs['logs']['cron']))
     num = sum(1 for line in matches)
     commands = []
@@ -26,13 +25,11 @@ def parse_log():
     #logger.debug("found cron command " + str(commands))
     logger.info("Found " + str(num) + " cron jobs")
     subtitle = str(num) + " cron jobs run"
-    output += writetitle("cron")
-    output += writedata(subtitle)
+    section.add_data(Data(subtitle))
     if (len(matches) > 0):
-        commands = addtag(commands, 'code')
-        commands = orderbyfreq(commands)
+        commands = ("`{0}`".format(x) for x in commands)
+        commands = orderbyfreq(list(commands))
         commands = truncl(commands, config.prefs['maxcmd'])
-        output += writedata("top cron commands", [c for c in commands])
-    output += closetag('div', 1)
+        section.add_data(Data("top cron commands", commands))
     logger.info("Finished cron section")
-    return output
+    return section