DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b6057e17f856)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
:mod:`mozlog` --- Easy, configurable and uniform logging
========================================================

Mozlog is a python package intended to simplify and standardize logs
in the Mozilla universe. It wraps around python's logging module and
adds some additional functionality.

.. note::
  For the purposes of logging results and other output from test runs,
  :doc:`mozlog.structured<mozlog_structured>` should now be used
  instead of this module.

.. automodule:: mozlog
    :members: getLogger

.. autoclass:: MozLogger
    :members: testStart, testEnd, testPass, testFail, testKnownFail

Examples
--------

Log to stdout::

    import mozlog
    log = mozlog.getLogger('MODULE_NAME')
    log.setLevel(mozlog.INFO)
    log.info('This message will be printed to stdout')
    log.debug('This won't')
    log.testPass('A test has passed')
    mozlog.shutdown()

Log to a file::

    import mozlog
    log = mozlog.getLogger('MODULE_NAME', handler=mozlog.FileHandler('path/to/log/file'))
    log.warning('Careful!')
    log.testKnownFail('We know the cause for this failure')
    mozlog.shutdown()

Log from an existing object using the LoggingMixin::

    import mozlog
    class Loggable(mozlog.LoggingMixin):
        """Trivial class inheriting from LoggingMixin"""
        def say_hello(self):
            self.info("hello")

    loggable = Loggable()
    loggable.say_hello()


.. _logging: http://docs.python.org/library/logging.html