Package conary :: Package lib :: Module xmllog
[hide private]
[frames] | no frames]

Source Code for Module conary.lib.xmllog

 1  # 
 2  # Copyright (c) 2008 rPath, Inc. 
 3  # 
 4  # This program is distributed under the terms of the Common Public License, 
 5  # version 1.0. A copy of this license should have been distributed with this 
 6  # source file in a file called LICENSE. If it is not present, the license 
 7  # is always available at http://www.rpath.com/permanent/licenses/CPL-1.0. 
 8  # 
 9  # This program is distributed in the hope that it will be useful, but 
10  # without any warranty; without even the implied warranty of merchantability 
11  # or fitness for a particular purpose. See the Common Public License for 
12  # full details. 
13  # 
14   
15   
16  import logging 
17   
18  from conary.lib import logger 
19   
20 -class XmlHandler(logging.StreamHandler):
21 """Xml logging class compatible with python's built in logging structures. 22 23 This class defines an interface to logger.XmlWriter that's compatible 24 with python's logging module. Note that logger.XmlWriter expects to write 25 a complete log from start to finish. This is because it attempts to produce 26 well formed XML. It also employs some compression filters that don't 27 define an append mode, so not allowing append is more consistent. This 28 deviates from normal python logging assumptions. Use with caution."""
29 - def __init__(self, path):
30 stream = logger.XmlLogWriter(path) 31 stream.start() 32 logging.StreamHandler.__init__(self, stream)
33
34 - def close(self):
35 self.stream.flush() 36 self.stream.close() 37 logging.StreamHandler.close(self)
38
39 - def emit(self, record):
40 # by forcing a newline as a separate even we ensure that all newlines 41 # in the log message will be present but escaped and we will have one 42 # line per logging event 43 self.stream.log(record.getMessage(), record.levelname)
44
45 - def pushDescriptor(self, descriptor):
46 return self.stream.pushDescriptor(descriptor)
47
48 - def popDescriptor(self, descriptor = None):
49 return self.stream.popDescriptor(descriptor)
50
51 - def addRecordData(self, key, val):
52 return self.stream.addRecordData(key, val)
53
54 - def delRecordData(self, key):
55 return self.stream.delRecordData(key)
56