Global Configuration¶
- ctxlog.config.configure(level=LogLevel.INFO, timefmt='iso', utc=False, handlers=None)[source]¶
Configure the global settings for ctxlog.
This function should be called once, typically at application startup.
- Parameters:
level (
Union[LogLevel,Literal['debug','info','warning','error','critical'],int]) – The global log level. Can be a LogLevel enum value, a string, or an int.timefmt (
str) – Timestamp format for log entries. Use ‘iso’ for ISO8601, or provide a custom strftime format string.utc (
bool) – If True, use UTC for timestamps. Default is False (local time).handlers (
Optional[List[Handler]]) – List of output handlers. If None, a default ConsoleHandler will be used.
- Return type:
Example
Configure ctxlog at startup:
ctxlog.configure( level=ctxlog.LogLevel.INFO, timefmt="iso", utc=True, handlers=[ ctxlog.ConsoleHandler(serialize=False, color=True, use_stderr=False), ctxlog.FileHandler( level=ctxlog.LogLevel.DEBUG, serialize=True, file_path="./app.log", rotation=ctxlog.FileRotation( size="20MB", # mutually exclusive with time time="00.00", # mutually exclusive with size keep=12, compress_old=True ), ), ] )