duo_ai.utils.logging

Classes

ElapsedFormatter

Formatter for logging that prepends elapsed time since initialization.

Functions

configure_logging(log_file)

Configure logging to output to both a file and the console with elapsed time formatting.

Module Contents

duo_ai.utils.logging.configure_logging(log_file)[source]

Configure logging to output to both a file and the console with elapsed time formatting.

Sets up logging handlers and a custom exception hook for uncaught exceptions.

Parameters:

log_file (str) – Path to the log file where logs will be written.

Return type:

None

Examples

>>> configure_logging('experiment.log')
class duo_ai.utils.logging.ElapsedFormatter[source]

Formatter for logging that prepends elapsed time since initialization.

Parameters:

None

start_time

The time when the formatter was initialized.

Type:

datetime.datetime

Examples

>>> formatter = ElapsedFormatter()
>>> formatter.format_time(datetime.now() - formatter.start_time)
'0:00:01'
start_time
format_time(t)[source]

Format a timedelta as a string, omitting microseconds.

Parameters:

t (datetime.timedelta) – Time difference to format.

Returns:

Formatted time string.

Return type:

str

format(record)[source]

Format a log record with elapsed time and log level.

Parameters:

record (logging.LogRecord) – The log record to format.

Returns:

Formatted log string.

Return type:

str