--- a/log_formatter.py Tue Feb 10 22:59:52 2009 +0200
+++ b/log_formatter.py Tue Feb 10 23:00:11 2009 +0200
@@ -53,15 +53,22 @@
else :
timestamp_fmt = self.timestamp_fmt
-
- # build timestamp
- timestamp = dtz.strftime(timestamp_fmt)
+
+ # breakdown source
+ source_nickname, source_username, source_hostname, source_chanflag = line.source
+ target_nickname = line.target
# format with dict
return template % dict(
- timestamp = timestamp,
- source = line.source,
- data = line.data,
+ channel_name = line.channel.name,
+ datetime = dtz.strftime('%a %b %d %H:%M:%S %Y'),
+ timestamp = dtz.strftime(timestamp_fmt),
+ source_nickname = source_nickname,
+ source_username = source_username,
+ source_hostname = source_hostname,
+ source_chanflag = source_chanflag,
+ target_nickname = target_nickname,
+ message = line.data,
)
def format_txt (self, lines, full_timestamps=False) :
@@ -98,11 +105,15 @@
abstract
-class BaseHTMLFormatter (object) :
+class BaseHTMLFormatter (LogFormatter) :
"""
Implements some HTML-formatting utils
"""
+
+ # parameters
+ html_fixedwidth = True
+ # regexp to match URLs
URL_REGEXP = re.compile(r"http://\S+")
def _process_links (self, line) :
@@ -120,35 +131,7 @@
return '<a href="%(url_link)s">%(url_html)s</a>' % dict(url_link=url_link, url_html=url_html)
return self.URL_REGEXP.sub(_encode_url, line)
-
-class IrssiTextFormatter (RSSFormatter, PILImageFormatter, LogFormatter) :
- """
- Implements format_txt for irssi-style output
- """
-
- # format definitions by type
- __FMT = {
- LogTypes.RAW : "%(timestamp)s %(data)s",
- }
-
- def format_txt (self, lines, full_timestamps=False) :
- # ...handle each line
- for line in lines :
- # using __TYPES
- yield line, self._format_line_text(line, self.__FMT, full_timestamps)
-
-class IrssiFormatter (IrssiTextFormatter, BaseHTMLFormatter) :
- """
- Implements plain black-and-white irssi-style formatting
- """
-
- # name
- name = 'irssi'
- title = "Irssi (plain)"
-
- # parameters
- html_fixedwidth = True
-
+
def format_html (self, lines, **kwargs) :
"""
Just uses format_txt, but processes links, etc
@@ -165,6 +148,66 @@
# yield
yield line, html
+
+class IrssiTextFormatter (RSSFormatter, PILImageFormatter, LogFormatter) :
+ """
+ Implements format_txt for irssi-style output
+ """
+
+ # format definitions by type
+ __FMT = {
+ LogTypes.RAW : "%(timestamp)s %(data)s",
+ LogTypes.LOG_OPEN : "--- Log opened %(datetime)s",
+ LogTypes.LOG_CLOSE : "--- Log closed %(datetime)s",
+
+ LogTypes.MSG : "%(timestamp)s <%(source_chanflag)s%(source_nickname)s> %(message)s",
+ LogTypes.NOTICE : "%(timestamp)s -%(source_nickname)s- %(message)s",
+ LogTypes.ACTION : "%(timestamp)s * %(source_nickname)s %(message)s",
+
+ LogTypes.JOIN : "%(timestamp)s -!- %(source_nickname)s [%(source_username)s@%(source_hostname)s] has joined %(channel_name)s",
+ LogTypes.PART : "%(timestamp)s -!- %(source_nickname)s [%(source_username)s@%(source_hostname)s] has left %(channel_name)s [%(message)s]",
+ LogTypes.KICK : "%(timestamp)s -!- %(target_nickname)s was kicked from %(channel_name)s by %(source_nickname)s [%(message)s]",
+ LogTypes.MODE : "%(timestamp)s -!- mode/%(channel_name)s [%(message)s] by %(source_nickname)s",
+
+ LogTypes.NICK : "%(timestamp)s -!- %(source_nickname)s is now known as %(target_nickname)s",
+ LogTypes.QUIT : "%(timestamp)s -!- %(source_nickname)s [%(source_username)s@%(source_hostname)s] has quit [%(message)s]",
+
+ LogTypes.TOPIC : "%(timestamp)s -!- %(source_nickname)s changed the topic of %(channel_name)s to: %(message)s",
+
+ LogTypes.SELF_NOTICE: "%(timestamp)s -%(source_nickname)s- %(message)s",
+ LogTypes.SELF_NICK : "%(timestamp)s -!- %(source_nickname)s is now known as %(target_nickname)s",
+ }
+
+ def format_txt (self, lines, full_timestamps=False) :
+ # ...handle each line
+ for line in lines :
+ # using __TYPES
+ yield line, self._format_line_text(line, self.__FMT, full_timestamps)
+
+class IrssiFormatter (BaseHTMLFormatter, IrssiTextFormatter) :
+ """
+ Implements plain black-and-white irssi-style formatting
+ """
+
+ # name
+ name = 'irssi'
+ title = "Irssi (plain)"
+
+class DebugFormatter (BaseHTMLFormatter) :
+ """
+ Implements a raw debug-style formatting of LogLines
+ """
+
+ # name
+ name = 'debug'
+ title = "Raw debugging format"
+
+ def format_txt (self, lines, full_timestamps=False) :
+ # iterate
+ for line in lines :
+ # just dump
+ yield line, repr(line)
+
def by_name (name) :
"""
Lookup and return a class LogFormatter by name