9 class LogFormatter (object) : |
9 class LogFormatter (object) : |
10 """ |
10 """ |
11 Provides a method to format series of LogLines into various output formats, with varying themes. |
11 Provides a method to format series of LogLines into various output formats, with varying themes. |
12 """ |
12 """ |
13 |
13 |
14 # the formatter's code name |
14 # machine-readable name |
15 name = None |
15 name = None |
16 |
16 |
|
17 # human-readable name |
|
18 title = None |
|
19 |
|
20 ## parameters |
|
21 # use a fixed-width font for HTML output |
|
22 html_fixedwidth = True |
|
23 |
17 def __init__ (self, tz, timestamp_fmt="%H:%M:%S") : |
24 def __init__ (self, tz, timestamp_fmt="%H:%M:%S") : |
18 """ |
25 """ |
19 Initialize to format timestamps with the given timezone and timestamp |
26 Initialize to format timestamps with the given timezone and timestamp |
20 """ |
27 """ |
21 |
28 |
106 |
113 |
107 def format_txt (self, lines, full_timestamps=False) : |
114 def format_txt (self, lines, full_timestamps=False) : |
108 # ...handle each line |
115 # ...handle each line |
109 for line in lines : |
116 for line in lines : |
110 # using __TYPES |
117 # using __TYPES |
111 yield self._format_line_text(line, self.__FMT, full_timestamps) |
118 yield line, self._format_line_text(line, self.__FMT, full_timestamps) |
112 |
119 |
113 class IrssiFormatter (IrssiTextFormatter, BaseHTMLFormatter) : |
120 class IrssiFormatter (IrssiTextFormatter, BaseHTMLFormatter) : |
114 """ |
121 """ |
115 Implements plain black-and-white irssi-style formatting |
122 Implements plain black-and-white irssi-style formatting |
116 """ |
123 """ |
117 |
124 |
|
125 # name |
118 name = 'irssi' |
126 name = 'irssi' |
119 title = "Irssi (plain)" |
127 title = "Irssi (plain)" |
120 |
128 |
|
129 # parameters |
|
130 html_fixedwidth = True |
|
131 |
121 def format_html (self, lines, full_timestamps=False) : |
132 def format_html (self, lines, full_timestamps=False) : |
122 """ |
133 """ |
123 Just uses format_txt, but wraps in <pre></pre> |
134 Just uses format_txt, but processes links, etc |
124 """ |
135 """ |
125 |
136 |
126 # open pre |
|
127 yield "<pre>" |
|
128 |
|
129 # format using IrssiTextFormatter |
137 # format using IrssiTextFormatter |
130 for line in self.format_txt(lines, full_timestamps) : |
138 for line, txt in self.format_txt(lines, full_timestamps) : |
131 # escape HTML |
139 # escape HTML |
132 line = xml.sax.saxutils.escape(line) |
140 html = xml.sax.saxutils.escape(txt) |
133 |
141 |
134 # process links |
142 # process links |
135 line = self._process_links(line) |
143 html = self._process_links(html) |
136 |
144 |
137 # yield |
145 # yield |
138 yield line |
146 yield line, html |
139 |
|
140 # close pre |
|
141 yield "</pre>" |
|
142 |
147 |
143 # define formatters by name |
148 # define formatters by name |
144 FORMATTERS = { |
149 FORMATTERS = { |
145 'irssi': IrssiFormatter, |
150 'irssi': IrssiFormatter, |
146 } |
151 } |