testing/mozbase/docs/mozlog.rst

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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

mercurial