Logging Configuration
Configure the logger with custom settings using Python's standard logging module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format_string
|
Optional[str]
|
The format string for log messages. If None, a default format will be used. |
None
|
level
|
str
|
The minimum logging level. Default: "INFO" |
'INFO'
|
sink
|
Union[PathLike[str], TextIO, BinaryIO]
|
Where to send the log. Default: sys.stderr Can be a file path, TextIO, or BinaryIO. |
stderr
|
include_correlation_id
|
bool
|
Whether to include correlation ID in log messages. Default: True |
True
|
use_colors
|
bool
|
Whether to use colored output for console logging. Automatically disabled for file output. Default: True |
True
|
Returns:
| Type | Description |
|---|---|
Logger
|
logging.Logger: The configured logger object |
Example
from airia import configure_logging
# Basic configuration with colors
logger = configure_logging()
# Disable colors
logger = configure_logging(use_colors=False)
# File-based logging (colors automatically disabled)
file_logger = configure_logging(
level="DEBUG",
sink="app.log",
include_correlation_id=True
)
# Console output
console_logger = configure_logging(
level="INFO",
sink=sys.stdout
)
Source code in airia/logs.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |