robokudo.utils.logging_configuration¶
Logging configuration utilities for Robokudo.
This module provides functionality for configuring Python logging in a ROS environment. It handles:
Logger configuration from YAML files
ROS-Python logging integration
Custom log formatting
Per-module log level control
Note
ROS normally disables Python’s default logging system. This module provides a workaround to enable proper Python logging alongside ROS logging.
Classes¶
Formatter instances are used to convert a LogRecord to text. |
Functions¶
|
Configure Python logging system with ROS integration. |
Module Contents¶
- class robokudo.utils.logging_configuration.DynamicCompactFormatter(fmt=None, datefmt=None, style='%')¶
-
Bases:
logging.FormatterFormatter instances are used to convert a LogRecord to text.
Formatters need to know how a LogRecord is constructed. They are responsible for converting a LogRecord to (usually) a string which can be interpreted by either a human or an external system. The base Formatter allows a formatting string to be specified. If none is supplied, the style-dependent default value, “%(message)s”, “{message}”, or “${message}”, is used.
The Formatter can be initialized with a format string which makes use of knowledge of the LogRecord attributes - e.g. the default value mentioned above makes use of the fact that the user’s message and arguments are pre- formatted into a LogRecord’s message attribute. Currently, the useful attributes in a LogRecord are described by:
%(name)s Name of the logger (logging channel) %(levelno)s Numeric logging level for the message (DEBUG, INFO,
WARNING, ERROR, CRITICAL)
- %(levelname)s Text logging level for the message (“DEBUG”, “INFO”,
-
“WARNING”, “ERROR”, “CRITICAL”)
- %(pathname)s Full pathname of the source file where the logging
-
call was issued (if available)
%(filename)s Filename portion of pathname %(module)s Module (name portion of filename) %(lineno)d Source line number where the logging call was issued
(if available)
%(funcName)s Function name %(created)f Time when the LogRecord was created (time.time()
return value)
%(asctime)s Textual time when the LogRecord was created %(msecs)d Millisecond portion of the creation time %(relativeCreated)d Time in milliseconds when the LogRecord was created,
relative to the time the logging module was loaded (typically at application startup time)
%(thread)d Thread ID (if available) %(threadName)s Thread name (if available) %(process)d Process ID (if available) %(message)s The result of record.getMessage(), computed just as
the record is emitted
- _parse_field_width() None¶
-
Parse format string to find filename_line width
- format(record: logging.LogRecord) str¶
-
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- robokudo.utils.logging_configuration.configure_logging(logging_config_file_name: str) None¶
-
Configure Python logging system with ROS integration.
Sets up Python logging with:
Console output to stdout
Custom formatter for detailed log messages
Per-module log levels from YAML config
ROS logging integration
The YAML config file should map logger names to logging levels:
logger_name1: INFO logger_name2: DEBUG ...
- Parameters:
-
logging_config_file_name (str) – Path to YAML config file
- Raises:
-
FileNotFoundError – If config file not found
yaml.YAMLError – If config file has invalid format
Note
This is needed because ROS disables standard Python logging. See: https://github.com/ros/ros_comm/issues/1384