better_launch.utils.better_logging moduleο
- class better_launch.utils.better_logging.PrettyLogFormatter(format: str = '[{levelcolor_start}{levelname}{levelcolor_end}] [{sourcecolor_start}{name}{sourcecolor_end}] [{asctime}]\n{message}', timestamp_format: str = '%Y-%m-%d %H:%M:%S.%f', *, defaults: dict[str, Any] = None, roslog_pattern: str = '%%(\\w+)%%([\\d.]+)%%(.*)', pattern_info: list[str] = ('levelname', 'created', 'msg'), source_colors: str | int | Iterable[int] | dict[str, Any] = 222, log_colors: str | int | Iterable[int] | dict[str, Any] = None, no_colors: bool = False)ο
Bases:
Formatter
- default_file_format = '[{levelname}] [{asctime}] {message}'ο
- default_screen_format = '[{levelcolor_start}{levelname}{levelcolor_end}] [{sourcecolor_start}{name}{sourcecolor_end}] [{asctime}]\n{message}'ο
- format(record)ο
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.
- formatTime(record, datefmt=None)ο
Return the creation time of the specified LogRecord as formatted text.
This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behaviour is as follows: if datefmt (a string) is specified, it is used with time.strftime() to format the creation time of the record. Otherwise, an ISO8601-like (or RFC 3339-like) format is used. The resulting string is returned. This function uses a user-configurable function to convert the creation time to a tuple. By default, time.localtime() is used; to change this for a particular formatter instance, set the βconverterβ attribute to a function with the same signature as time.localtime() or time.gmtime(). To change it for all formatters, for example if you want all logging times to be shown in GMT, set the βconverterβ attribute in the Formatter class.
- format_color(color: Any) str ο
- get_loglevel_color(level: int | str) tuple[str, str] ο
- get_source_color(source: str) str ο
Return the color associated with the provided source.
- class better_launch.utils.better_logging.RecordForwarder(*args, **kwargs)ο
Bases:
RecordForwarder
- format(record)ο
Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter for the module.
- setFormatterFor(logger, formatter)ο
Set formatter for a given logger instance or logger name.
- unsetFormatterFor(logger)ο
Unset formatter for a given logger instance or logger name, if any.
- class better_launch.utils.better_logging.StubbornHandler(actual_handler: Handler, level: int = 20)ο
Bases:
Handler
This handler resists the common changes ROS2 attempts to make for its logging so that our formatters can work properly.
The ROS2 launch system assigns the same formatter to many sources using special wrappers. However, we donβt want our log forwarders and formatters to be replaced just like that.
Parametersο
- actual_handlerlogging.Handler
The handler which will actually handle any incoming log records.
- emit(record)ο
Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so raises a NotImplementedError.
- format(record)ο
Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter for the module.
- setFormatterFor(logger, formatter)ο
- unsetFormatterFor(logger)ο
- better_launch.utils.better_logging.configure_logger(logger: Logger, config: Literal['screen', 'log', 'own_log', 'none'] | Iterable[Literal['screen', 'log', 'own_log', 'none']] = None, screen_formatter: Formatter = None, log_formatter: Formatter = None) None ο
- better_launch.utils.better_logging.init_logging(log_config: LaunchConfig, screen_log_format: str = None, file_log_format: str = None, colormode: Literal['default', 'severity', 'source', 'none', 'rainbow'] = 'default') None ο