Skip to content

senxor.log

senxor.log

Logging utilities for Senxor devices.

get_logger(logger_name='senxor', *args, **kwargs)

Get a structured logger instance.

Parameters:

Name Type Description Default

logger_name

str

The name of the logger, by default "senxor"

'senxor'

*args

Any

Positional arguments to pass to structlog.get_logger.

()

**kwargs

Any

Keyword arguments to pass to structlog.get_logger.

{}

Returns:

Type Description
SenxorLogger

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_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.

setup_console_logger(log_level='INFO', logger_name='senxor', *, add_logger_name=False)

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 | str | None

The log level to use, by default logging.INFO

'INFO'

logger_name

str

The name of the logger, by default "senxor"

'senxor'

add_logger_name

bool

Whether to add the logger name to the console output, by default False

False

setup_file_logger(file_path, file_mode='w', log_level='INFO', logger_name='senxor', *, watch_file=False, json_format=False)

Setup a file logger.

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

Parameters:

Name Type Description Default

file_path

Path | str

The path to the log file.

required

file_mode

str

The mode to use for the log file, by default "w"

'w'

log_level

int | str

The log level to use, by default logging.INFO

'INFO'

logger_name

str

The name of the logger, by default "senxor"

'senxor'

watch_file

bool

Whether to use the logging.handlers.WatchedFileHandler handler, by default False

False

json_format

bool

Whether to use the structlog.processors.JSONRenderer formatter, by default False

False