diff -r 85345abbd46a -r 43ac75054d5c log_formatter.py --- a/log_formatter.py Tue Feb 10 01:24:59 2009 +0200 +++ b/log_formatter.py Tue Feb 10 02:57:16 2009 +0200 @@ -5,6 +5,7 @@ import re, xml.sax.saxutils from log_line import LogTypes +from log_formatter_pil import PILImageFormatter class LogFormatter (object) : """ @@ -21,13 +22,17 @@ # use a fixed-width font for HTML output html_fixedwidth = True - def __init__ (self, tz, timestamp_fmt="%H:%M:%S") : + def __init__ (self, tz, timestamp_fmt, img_ttf_path, img_font_size) : """ - Initialize to format timestamps with the given timezone and timestamp + Initialize to format timestamps with the given timezone and timestamp. + + Use the given TTF font to render image text with the given size, if given, otherwise, a default one. """ self.tz = tz self.timestamp_fmt = timestamp_fmt + self.img_ttf_path = img_ttf_path + self.img_font_size = img_font_size def _format_line_text (self, line, template_dict, full_timestamp=False) : """ @@ -77,6 +82,11 @@ """ abstract + + def format_png (self, lines) : + """ + Format as a PNG image, returning the binary PNG data + """ class BaseHTMLFormatter (object) : """ @@ -101,7 +111,7 @@ return self.URL_REGEXP.sub(_encode_url, line) -class IrssiTextFormatter (LogFormatter) : +class IrssiTextFormatter (PILImageFormatter, LogFormatter) : """ Implements format_txt for irssi-style output """ @@ -129,13 +139,13 @@ # parameters html_fixedwidth = True - def format_html (self, lines, full_timestamps=False) : + def format_html (self, lines, **kwargs) : """ Just uses format_txt, but processes links, etc """ # format using IrssiTextFormatter - for line, txt in self.format_txt(lines, full_timestamps) : + for line, txt in self.format_txt(lines, **kwargs) : # escape HTML html = xml.sax.saxutils.escape(txt) @@ -145,11 +155,6 @@ # yield yield line, html -# define formatters by name -FORMATTERS = { - 'irssi': IrssiFormatter, -} - def by_name (name) : """ Lookup and return a class LogFormatter by name