Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | :mod:`mozlog` --- Easy, configurable and uniform logging |
michael@0 | 2 | ======================================================== |
michael@0 | 3 | |
michael@0 | 4 | Mozlog is a python package intended to simplify and standardize logs |
michael@0 | 5 | in the Mozilla universe. It wraps around python's logging module and |
michael@0 | 6 | adds some additional functionality. |
michael@0 | 7 | |
michael@0 | 8 | .. note:: |
michael@0 | 9 | For the purposes of logging results and other output from test runs, |
michael@0 | 10 | :doc:`mozlog.structured<mozlog_structured>` should now be used |
michael@0 | 11 | instead of this module. |
michael@0 | 12 | |
michael@0 | 13 | .. automodule:: mozlog |
michael@0 | 14 | :members: getLogger |
michael@0 | 15 | |
michael@0 | 16 | .. autoclass:: MozLogger |
michael@0 | 17 | :members: testStart, testEnd, testPass, testFail, testKnownFail |
michael@0 | 18 | |
michael@0 | 19 | Examples |
michael@0 | 20 | -------- |
michael@0 | 21 | |
michael@0 | 22 | Log to stdout:: |
michael@0 | 23 | |
michael@0 | 24 | import mozlog |
michael@0 | 25 | log = mozlog.getLogger('MODULE_NAME') |
michael@0 | 26 | log.setLevel(mozlog.INFO) |
michael@0 | 27 | log.info('This message will be printed to stdout') |
michael@0 | 28 | log.debug('This won't') |
michael@0 | 29 | log.testPass('A test has passed') |
michael@0 | 30 | mozlog.shutdown() |
michael@0 | 31 | |
michael@0 | 32 | Log to a file:: |
michael@0 | 33 | |
michael@0 | 34 | import mozlog |
michael@0 | 35 | log = mozlog.getLogger('MODULE_NAME', handler=mozlog.FileHandler('path/to/log/file')) |
michael@0 | 36 | log.warning('Careful!') |
michael@0 | 37 | log.testKnownFail('We know the cause for this failure') |
michael@0 | 38 | mozlog.shutdown() |
michael@0 | 39 | |
michael@0 | 40 | Log from an existing object using the LoggingMixin:: |
michael@0 | 41 | |
michael@0 | 42 | import mozlog |
michael@0 | 43 | class Loggable(mozlog.LoggingMixin): |
michael@0 | 44 | """Trivial class inheriting from LoggingMixin""" |
michael@0 | 45 | def say_hello(self): |
michael@0 | 46 | self.info("hello") |
michael@0 | 47 | |
michael@0 | 48 | loggable = Loggable() |
michael@0 | 49 | loggable.say_hello() |
michael@0 | 50 | |
michael@0 | 51 | |
michael@0 | 52 | .. _logging: http://docs.python.org/library/logging.html |