f451 Labs RPI Logger module
This module has been integrated into the f451 Labs Common module and the GitHub repo will be removed shortly.
Overview
The f451 Labs RPI Logger module encapsulates the default Python ‘Logging’ class and adds a few more features that are commonly used in f451 Labs RPI projects.
Core functions
This module includes the following functions:
- load_settings() — Initialize TOML parser and load settings file.
- set_log_level() — Set/update log level after initialization
- set_log_file() — Set/update log file after initialization
- debug() — Print debug message to stdout.
- log() — Write log message/data at any log level
- log_debug() — Write log message/data at ‘debug’ level
- log_info() — Write log message/data at ‘info’ level
- log_warning() — Write log message/data at ‘warning’ level
- log_error() — Write log message/data at ’error’ level
Please refer to the GitHub repo for source code and documentation.
Dependencies
This module depends on the following libraries:
How to use
Using the module is straightforward. Simply import
it into your code and instantiate a Logger
object which you can then use throughout your code.
# Import f451 Labs Logger
from f451_logger.logger import Logger
# This is optional, but useful if you want to
# use predefined constant for logging levels
import logging
# Instantiate using defaults ...
myLogger = Logger()
# ... or with custom log level and log file values
myLogger = Logger(
logLvl=logging.ERROR,
logFile="path/to/mylogfile.log"
)
# Call 'log_xxxx' methods to log messages
myLogger.log_info("Hello world!")
myLogger.log_error("Oops! Something broke :-(")
# Call 'debug' method to show message in console
myLogger.debug("Hello world!")
myVar = 2
myLogger.debug(myVar)