Skip to content

logger

FreeBodyEngine.core.logger #

colors = {'black': 30, 'red': 31, 'green': 32, 'yellow': 33, 'blue': 34, 'magenta': 35, 'cyan': 36, 'white': 37, 'reset': 0} module-attribute #

Logger(max_history_length=10000) #

Bases: Service

The engine's central logging service (registered as "logger"). Keeps an in-memory history of every log/warning/error (capped at max_history_length, oldest dropped first) and, once the "files" service is available, also mirrors each entry as a line of user://log.jsonl.

Sets up an empty log history, and reads the SUPRESS_ERRORS/ SUPRESS_WARNINGS/SUPRESS_LOGS flags to decide which message types are silenced.

history = [] instance-attribute #

log_file = None instance-attribute #

max_history_length = max_history_length instance-attribute #

next_id = 1 instance-attribute #

supress = {'ERROR': get_flag(SUPRESS_ERRORS, False), 'WARNING': get_flag(SUPRESS_WARNINGS, False), 'DEBUG': get_flag(SUPRESS_LOGS, False)} instance-attribute #

error(msg) #

Logs msg as an ERROR (printed in red) and records a stack trace for it, unless errors are suppressed. Returns the new entry's log id.

get_history() #

Returns the whole in-memory log history, formatted one line per entry.

get_traceback(log_id) #

Returns the recorded stack trace for the ERROR/WARNING entry with id log_id, or a "No log found" message if no entry has that id.

log(*msg, color='reset') #

Logs msg (joined with spaces) to the console in color, unless DEBUG logs are suppressed. Returns the new entry's log id.

warning(msg) #

Logs msg as a WARNING (printed in yellow) and records a stack trace for it, unless warnings are suppressed. Returns the new entry's log id.

get_timestamp() #

Returns the current local time as "YYYY-MM-DD HH:MM:SS.mmm".

print_colored(*text, color='reset') #

Prints text (concatenated with no separator) wrapped in the ANSI escape code for color (see colors).