August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
Provides a way to generate debugging (logging) output on standard output that can be filtered to just what is needed at the time.
What debugging output actually gets output (and what is filtered out) is controlled by two things: what section the debugging output is under and the level of detail of a given piece of output.
Each call to output debugging information specifies what section it belongs to and the level of detail it represents.
The filtering of this is configured from a configuration file (see Axon.deugConfigFile for information on the format) which lists each expected section and the maximum level of detail that will be output for that section.
Create a debug object:
debugger = Axon.debug.debug()
Specify the configuration to use, either specifying a file, or letting the debugger choose its own defaults:
debugger.useConfig(filename="my_debug_config_file")
Any subsequent debug objects you create will use the same configuration when you call their useConfig() method - irrespective of whether you specify a filename or not!
Call the note() method whenever you potentially want debugging output; specifying the "section name" and minimum debug level under which it should be reported:
while 1:
...
assert self.debugger.note("MyObject.main", 10, "loop begins")
...
if something_happened():
...
assert self.debugger.note("MyObject.main", 5, "received ", msg)
...
The note() method always returns True, meaning you can wrap it in an assert statement. If you then use python's "-O" command line flag, assert statements will be ignored, completely removing any performance overhead the due to the debugging output.
All debug objects share the same initial configuration - when you call their useConfig() method, all pick up the same configuration file that was specified on the first call.
However, after the useConfig() call you can customise the configuration of individual debug objects.
You can increase or decrease the maximum level of detail that will be output for a given section:
debugger.increaseDebug("MyObject.main")
debugger.decreaseDebug("MyObject.main")
You can add (or replace) the configuration for individual debugging sections - ie. (re)specify what the maximum level of detail will be for a given section:
debugger.addDebugSections()
Or you can replace the entire set:
replacementSections = { "MyObject.main" : 10,
"MyObject.init" : 5,
...
}
debugger.addDebug(**replacementSections)
debug([assertBadDebug]) -> new debug object.
Object for outputting debugging output, filtered as required. Only outputs debugging data for section names it recognises - as specified in a debug config file.
Keyword arguments:
Add several debug sections. Each argument's name corresponds to a section name fo rwhich debug output can be generated. The value is the maximum debug level for which there will be output.
This does not affect the configuration of other debug objects.
Add a section name for which debug output can be generated, specifying a maximum debug level for which there will be output.
This does not affect the configuration of other debug objects.
Returns true if we are debugging this level, doesn't try to enforce correctness
Output a debug message.
Specify the 'section' the debug message should come under. The user will have specified the maximum 'level' to be outputted for that section.
Always returns True, so can be used as argument to an assert statement. This means you can then disable debugging output (and any associated performance overhead) by using python's "-O" command line flag.
Keyword arguments:
Output a debug messge (never filtered)
Keyword arguments:
Decreases the maximum debug level for which output will be generated for the specified section.
This does not affect the configuration of other debug objects.
Increases the maximum debug level for which output will be generated for the specified section.
This does not affect the configuration of other debug objects.
Output a debug message.
Specify the 'section' the debug message should come under. The user will have specified the maximum 'level' to be outputted for that section.
Always returns True, so can be used as argument to an assert statement. This means you can then disable debugging output (and any associated performance overhead) by using python's "-O" command line flag.
Keyword arguments:
INTERNAL Reads specified debug configuration file.
Uses Axon.debugConfigFile
Set the debug sections. Replaces any existing ones.
Each argument's name corresponds to a section name fo rwhich debug output can be generated. The value is the maximum debug level for which there will be output.
This does not affect the configuration of other debug objects.
Instruct this object to set up its debugging configuration.
If this, or another debug object has previously set it up, then that is applied for this object; otherwise it is loaded from the specified file. However, if no file is specified or the file could not be read, then alternative defaults are used. This configuration is then used for all future debug objects.
Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!
Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.
-- Automatic documentation generator, 09 Dec 2009 at 04:00:25 UTC/GMT