testing/mozbase/docs/mozlog.rst

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:85c99037e0d1
1 :mod:`mozlog` --- Easy, configurable and uniform logging
2 ========================================================
3
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.
7
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.
12
13 .. automodule:: mozlog
14 :members: getLogger
15
16 .. autoclass:: MozLogger
17 :members: testStart, testEnd, testPass, testFail, testKnownFail
18
19 Examples
20 --------
21
22 Log to stdout::
23
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()
31
32 Log to a file::
33
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()
39
40 Log from an existing object using the LoggingMixin::
41
42 import mozlog
43 class Loggable(mozlog.LoggingMixin):
44 """Trivial class inheriting from LoggingMixin"""
45 def say_hello(self):
46 self.info("hello")
47
48 loggable = Loggable()
49 loggable.say_hello()
50
51
52 .. _logging: http://docs.python.org/library/logging.html

mercurial