testing/mozbase/docs/mozlog.rst

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial