Welcome to tracing’s documentation!

tracing – fast debug trace messages

This module provides fast debugging log messages that can be turned on and off during runtime.

It is sometimes practical to add a lot of debugging log messages to a program, but having them enabled all the time results in very large log files. Also, logging that much takes quite a bit of time. Yet, keeping the logging statements can be a good idea so that they can be enabled if there is a problem that needs debugging, as long as there is a way to disable them in normal production mode.

This module provides a way to achieve that. For example:

# in the main program
import tracing

tracing.trace_add_pattern('foobar')
tracing.trace_add_pattern('yeehaa')

...

# in some other module
tracing.trace('start procedure')
tracing.trace('arg1=%s', arg1)
tracing.trace('arg2=%s', arg2)

Only calls that happen in files whose names contain foobar or yeehaa will actually be logged. Pattern matching is based on substring checking only, for speed, so there is no globbing or regular expression matching.

tracing.trace(msg, *args)

Log a trace message if the calling module’s name matches a pattern.

If any arguments are given, the message is formatted as if with msg % args, otherwise the message is written out as is.

tracing.trace_add_pattern(pattern)
Add a module name pattern.
tracing.trace_clear_patterns()

Remove all module name patterns.

After this, nothing will be traced. This is also the initial state.

Table Of Contents

This Page