class Reporter(object): (source)
Info/warning/error reporter and system_message element generator.
Five levels of system messages are defined, along with corresponding
methods: debug()
, info()
, warning()
, error()
, and severe()
.
There is typically one Reporter object per process. A Reporter object is instantiated with thresholds for reporting (generating warnings) and halting processing (raising exceptions), a switch to turn debug output on or off, and an I/O stream for warnings. These are stored as instance attributes.
When a system message is generated, its level is compared to the stored thresholds, and a warning or error is generated as appropriate. Debug messages are produced if the stored debug switch is on, independently of other thresholds. Message output is sent to the stored warning stream if not set to ''.
The Reporter class also employs a modified form of the "Observer" pattern
[GoF95] to track system messages generated. The attach_observer
method
should be called before parsing, with a bound method or function which
accepts system messages. The observer can be removed with
detach_observer
, and another added in its place.
[GoF95] | Gamma, Helm, Johnson, Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading, MA, USA, 1995. |
Method | __init__ |
No summary |
Method | attach_observer |
The observer parameter is a function or bound method which takes one argument, a nodes.system_message instance. |
Method | debug |
Level-0, "DEBUG": an internal reporting issue. Typically, there is no effect on the processing. Level-0 system messages are handled separately from the others. |
Method | detach_observer |
Undocumented |
Method | error |
Level-3, "ERROR": an error that should be addressed. If ignored, the output will contain errors. |
Method | info |
Level-1, "INFO": a minor issue that can be ignored. Typically there is no effect on processing, and level-1 system messages are not reported. |
Method | notify_observers |
Undocumented |
Method | set_conditions |
Undocumented |
Method | severe |
Level-4, "SEVERE": a severe error that must be addressed. If ignored, the output will contain severe errors. Typically level-4 system messages are turned into exceptions which halt processing. |
Method | system_message |
Return a system_message object. |
Method | warning |
Level-2, "WARNING": an issue that should be addressed. If ignored, there may be unpredictable problems with the output. |
Constant | DEBUG_LEVEL |
Undocumented |
Constant | ERROR_LEVEL |
Undocumented |
Constant | INFO_LEVEL |
Undocumented |
Constant | SEVERE_LEVEL |
Undocumented |
Constant | WARNING_LEVEL |
Undocumented |
Class Variable | levels |
List of names for system message levels, indexed by level. |
Instance Variable | debug_flag |
Show debug (level=0) system messages? |
Instance Variable | encoding |
The output character encoding. |
Instance Variable | error_handler |
The character encoding error handler. |
Instance Variable | halt_level |
The level at or above which SystemMessage exceptions will be raised, halting execution. |
Instance Variable | max_level |
The highest level system message generated so far. |
Instance Variable | observers |
List of bound methods or functions to call with each system_message created. |
Instance Variable | report_level |
The level at or above which warning output will be sent to self.stream . |
Instance Variable | source |
The path to or description of the source data. |
Instance Variable | stream |
Where warning output is sent. |
Parameters | |
source | The path to or description of the source data. |
report_level | The level at or above which warning output will
be sent to stream . |
halt_level | The level at or above which SystemMessage
exceptions will be raised, halting execution. |
stream | Where warning output is sent. Can be file-like (has a
.write method), a string (file name, opened for writing),
'' (empty string) or False (for discarding all stream messages)
or None (implies sys.stderr ; default). |
debug | Show debug (level=0) system messages? |
encoding | The output encoding. |
error_handler | The error handler for stderr output encoding. |
observer
parameter is a function or bound method which takes one
argument, a nodes.system_message
instance.SystemMessage
exceptions
will be raised, halting execution.