OLD | NEW |
| (Empty) |
1 # Copyright (c) 2001-2004 Twisted Matrix Laboratories. | |
2 # See LICENSE for details. | |
3 | |
4 # | |
5 syslog = __import__('syslog') | |
6 | |
7 import log | |
8 | |
9 class SyslogObserver: | |
10 def __init__(self, prefix): | |
11 syslog.openlog(prefix) | |
12 | |
13 def emit(self, eventDict): | |
14 edm = eventDict['message'] | |
15 if not edm: | |
16 if eventDict['isError'] and eventDict.has_key('failure'): | |
17 text = eventDict['failure'].getTraceback() | |
18 elif eventDict.has_key('format'): | |
19 text = eventDict['format'] % eventDict | |
20 else: | |
21 # we don't know how to log this | |
22 return | |
23 else: | |
24 text = ' '.join(map(str, edm)) | |
25 | |
26 lines = text.split('\n') | |
27 while lines[-1:] == ['']: | |
28 lines.pop() | |
29 | |
30 firstLine = 1 | |
31 for line in lines: | |
32 if firstLine: | |
33 firstLine=0 | |
34 else: | |
35 line = '\t%s' % line | |
36 syslog.syslog('[%s] %s' % (eventDict['system'], line)) | |
37 | |
38 def startLogging(prefix='Twisted', setStdout=1): | |
39 obs = SyslogObserver(prefix) | |
40 log.startLoggingWithObserver(obs.emit, setStdout=setStdout) | |
OLD | NEW |