Skip to content

senxor.log

senxor.log

Logging utilities for Senxor devices.

get_logger(*args, **kwargs)

Get a structured logger instance.

Parameters:

Name Type Description Default
*args Any

Positional arguments to pass to structlog.get_logger.

()
**kwargs Any

Keyword arguments to pass to structlog.get_logger.

{}

Returns:

Type Description
BoundLogger

A structured logger instance.

Examples:

>>> from senxor.log import get_logger
>>> logger = get_logger(device_id="1")
>>> logger.warning("This is a warning message.")
[warning  ] This is a warning message.    device_id=1

setup_console_logger(log_level=logging.INFO)

Setup a console logger.

This logger is used to log messages to the console, can output colored and formatted messages.

Parameters:

Name Type Description Default
log_level int

The log level to use, by default logging.INFO

INFO

setup_file_logger(path, log_level=logging.INFO, *, file_mode='wt+', log_as_json=False, log_to_console=True)

Setup a file logger.

This logger is used to log messages to the console and a file, can output formatted messages.

Parameters:

Name Type Description Default
path Path | str

The path to the log file.

required
log_level int

The log level to use for the file, by default logging.NOTSET

INFO
file_mode str

The mode to open the log file in, by default "wt+"

'wt+'
log_as_json bool

Whether to log to the file in JSON format, by default False

False
log_to_console bool

Whether to log to the console, by default True

True

setup_standard_logger()

Setup a standard logger.

This logger redirects all messages to the built-in logging module. It is the default logger for senxor. This logger is used by default when senxor is used as a library, which means that senxor should not have any side effects on the logging system.

Instead, use setup_console_logger or setup_file_logger to setup a logger for your application.