1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/docs/mozlog.rst Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +:mod:`mozlog` --- Easy, configurable and uniform logging 1.5 +======================================================== 1.6 + 1.7 +Mozlog is a python package intended to simplify and standardize logs 1.8 +in the Mozilla universe. It wraps around python's logging module and 1.9 +adds some additional functionality. 1.10 + 1.11 +.. note:: 1.12 + For the purposes of logging results and other output from test runs, 1.13 + :doc:`mozlog.structured<mozlog_structured>` should now be used 1.14 + instead of this module. 1.15 + 1.16 +.. automodule:: mozlog 1.17 + :members: getLogger 1.18 + 1.19 +.. autoclass:: MozLogger 1.20 + :members: testStart, testEnd, testPass, testFail, testKnownFail 1.21 + 1.22 +Examples 1.23 +-------- 1.24 + 1.25 +Log to stdout:: 1.26 + 1.27 + import mozlog 1.28 + log = mozlog.getLogger('MODULE_NAME') 1.29 + log.setLevel(mozlog.INFO) 1.30 + log.info('This message will be printed to stdout') 1.31 + log.debug('This won't') 1.32 + log.testPass('A test has passed') 1.33 + mozlog.shutdown() 1.34 + 1.35 +Log to a file:: 1.36 + 1.37 + import mozlog 1.38 + log = mozlog.getLogger('MODULE_NAME', handler=mozlog.FileHandler('path/to/log/file')) 1.39 + log.warning('Careful!') 1.40 + log.testKnownFail('We know the cause for this failure') 1.41 + mozlog.shutdown() 1.42 + 1.43 +Log from an existing object using the LoggingMixin:: 1.44 + 1.45 + import mozlog 1.46 + class Loggable(mozlog.LoggingMixin): 1.47 + """Trivial class inheriting from LoggingMixin""" 1.48 + def say_hello(self): 1.49 + self.info("hello") 1.50 + 1.51 + loggable = Loggable() 1.52 + loggable.say_hello() 1.53 + 1.54 + 1.55 +.. _logging: http://docs.python.org/library/logging.html