-
Notifications
You must be signed in to change notification settings - Fork 0
Logging
Standard python applications use the native logging module. It publishes log messages as one of the following levels:
- debug
- info
- warning
- error
- critical
Messages are published with their relevant loggers as e.g.
log.info("This is a info message")Setting up the handlers and publish destinations has been defined in the daqpytools repo, so you will not need to set them up yourself, just to be aware of where each one publishes.
One of the key features that logging offers is the inheritance of handlers. Logger instances are defined with inheritance, such that if one logger is named e.g. daqpytools_logger and another is named daqpytools_logger.new_feature, whenever the daqpytools_logger.new_feature logger publishes a message, it will use all the handlers associated with itself and its parents (defined as .` separated names). Be careful of how you choose to define your logging structure.
To setup an instance of logging, you need to
from daqpytools.logging.logger import get_daq_logger
log = get_daq_logger(<args>)
log.info(<message>)such that args are
-
logger_name- this is the name of the logger that will appear in your target -
log_level- this is one of the levels defined in # What does python logging involve? -
use_parent_handlers- if set toFalse, will not use parent handlers for publishing. Set toTrueby default to behave like the native tool. -
rich_handler- assigns a rich handler -
file_handler_path- if assigned, will set up a file handler and publish messages there -
stream_stdout_handler- assigns a stdout handler -
stream_stderr_handler- assigns a stderr handler Note - at least one handler must be allocated, otherwiseget_daq_loggerwill throw. There is no other limit to how many handlers are assigned to a single instance of logging.
The defined instance of logging supports the following handlers:
- stream stdout - publishes to the standard output stream
- stream stderr - publishes to the standard error stream
- file - publishesd to file
- rich - as stream stdout, publishes to the standard output stream but supports color to more simply visualize what is being published.
This is an optimization from the python library. To save as many clocks as possible, the record is first filtered by the logger and then by its handlers.