Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
1 :mod:`mozlog` --- Easy, configurable and uniform logging
2 ========================================================
4 Mozlog is a python package intended to simplify and standardize logs
5 in the Mozilla universe. It wraps around python's logging module and
6 adds some additional functionality.
8 .. note::
9 For the purposes of logging results and other output from test runs,
10 :doc:`mozlog.structured<mozlog_structured>` should now be used
11 instead of this module.
13 .. automodule:: mozlog
14 :members: getLogger
16 .. autoclass:: MozLogger
17 :members: testStart, testEnd, testPass, testFail, testKnownFail
19 Examples
20 --------
22 Log to stdout::
24 import mozlog
25 log = mozlog.getLogger('MODULE_NAME')
26 log.setLevel(mozlog.INFO)
27 log.info('This message will be printed to stdout')
28 log.debug('This won't')
29 log.testPass('A test has passed')
30 mozlog.shutdown()
32 Log to a file::
34 import mozlog
35 log = mozlog.getLogger('MODULE_NAME', handler=mozlog.FileHandler('path/to/log/file'))
36 log.warning('Careful!')
37 log.testKnownFail('We know the cause for this failure')
38 mozlog.shutdown()
40 Log from an existing object using the LoggingMixin::
42 import mozlog
43 class Loggable(mozlog.LoggingMixin):
44 """Trivial class inheriting from LoggingMixin"""
45 def say_hello(self):
46 self.info("hello")
48 loggable = Loggable()
49 loggable.say_hello()
52 .. _logging: http://docs.python.org/library/logging.html