Use bytes instead of unicode with isinstance.
[portage.git] / pym / portage / elog / mod_syslog.py
1 # elog/mod_syslog.py - elog dispatch module
2 # Copyright 2006-2011 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 import sys
6 import syslog
7 from portage.const import EBUILD_PHASES
8 from portage import _encodings
9
10 _pri = {
11         "INFO"   : syslog.LOG_INFO, 
12         "WARN"   : syslog.LOG_WARNING, 
13         "ERROR"  : syslog.LOG_ERR, 
14         "LOG"    : syslog.LOG_NOTICE,
15         "QA"     : syslog.LOG_WARNING
16 }
17
18 def process(mysettings, key, logentries, fulltext):
19         syslog.openlog("portage", syslog.LOG_ERR | syslog.LOG_WARNING | syslog.LOG_INFO | syslog.LOG_NOTICE, syslog.LOG_LOCAL5)
20         for phase in EBUILD_PHASES:
21                 if not phase in logentries:
22                         continue
23                 for msgtype,msgcontent in logentries[phase]:
24                         for line in msgcontent:
25                                 line = "%s: %s: %s" % (key, phase, line)
26                                 if sys.hexversion < 0x3000000 and not isinstance(line, bytes):
27                                         # Avoid TypeError from syslog.syslog()
28                                         line = line.encode(_encodings['content'], 
29                                                 'backslashreplace')
30                                 syslog.syslog(_pri[msgtype], line.rstrip("\n"))
31         syslog.closelog()