Configuration#
hanaro uses `appsettings2` as its configuration surface, so all logging settings can come from JSON, YAML, TOML, environment variables, or CLI arguments. All logging configuration lives under the logging key.
{
"logging": {
"level": "DEBUG",
"format": "[%(asctime)s] %(message)s",
"datefmt": "%Y-%m-%dT%H:%M:%S",
"bidi": true,
"allow_queued_logger": true,
"filters": {},
"handlers": []
}
}
Environment variable equivalent: LOGGING__LEVEL=WARNING
Each top-level option is described below.
- logging__level#
Root logger level. Default is
"DEBUG". Accepted values:"DEBUG"|"INFO"|"WARNING"|"ERROR"|"CRITICAL".
- logging__format#
Log message format string passed to
logging.Formatter. Default is Python’sBASIC_FORMAT.
- logging__datefmt#
Date format string passed to
logging.Formatter. Default is"%Y-%m-%dT%H:%M:%S".
- logging__bidi#
Enable or disable the
BidiFormatteron all console handlers. Default istrue. Requirespython-bidito be installed.When
true:BidiFormatteris automatically applied to anyconsolehandler in your logging config.BidiFormatteris automatically applied to anylogging.StreamHandlerthat does not have another formatter applied.BidiFormatteris applied if a default logging configuration is used (i.e. no handlers configured).
Disablement examples:
{ "logging": { "bidi": false } }
from appsettings2 import get_configuration from hanaro import configure_logging configuration = get_configuration() configuration['logging__bidi'] = False configure_logging(configuration)
- logging__allow_queued_logger#
When
true(default),get_logger()returns aQueuedHandler-backed logger when called from non-main threads. Set tofalseto disable this behaviour.
- logging__filters#
A dictionary of filter rules. Each key is a logger name (exact string or regex pattern). See the Filters section below.
- logging__handlers#
A list of handler definitions. Each handler has a
typefield. See the Handlers section below.
Filters#
Each filter entry specifies a logger-name pattern and a minimum level:
"source": {
"level": "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL",
"regex": true | false
}
source(REQUIRED) The name of the logger to filter. Can be an exact match or a regex pattern.level(OPTIONAL) The minimum logging level required for log records to bypass the filter. Default isDEBUG.regex(OPTIONAL)trueifsourceis treated as a regex, otherwise it is a literal string. Default istrue.
Example configuration:
"logging": {
"filters": {
"asyncio": { "level": "WARNING" },
"mysql\\..*": { "level": "ERROR" },
"urllib3\\..*": { "level": "WARNING", "regex": false }
}
}
Regex notes#
Regexes are implemented using Python’s re module and are auto-anchored: ^ and $ specifiers are applied automatically. A value of 'test' becomes '^test$'.
If there is an undesired result, set "regex": false to use literal matching instead. For example, foo.bar would unintentionally match foo_bar with regex (because . matches any character), but works as a literal match when regex is false.
Handlers#
The handlers list supports three handler type values:
type |
Required |
Optional |
|---|---|---|
|
— |
|
|
— |
|
|
||
|
|
|
Console handler — writes to sys.stdout.
{
"type": "console",
"level": "DEBUG"
}
File handler — uses RotatingFileHandler with auto-rotation.
{
"type": "file",
"path": "logs/", // default: "logs"
"name": "debug.log", // default: "<level>_<date>.log"
"max_size": "4MiB", // default: 4MiB; supports KiB/MiB/GiB suffix
"max_count": 10, // default: 10
"level": "DEBUG",
"format": "[%(asctime)s] %(message)s"
}
Custom handler — import any logging.Handler subclass.
{
"type": "custom",
"class": "myapp.handlers.WebhookHandler", // myapp/handlers.py: WebhookHandler(logging.Handler)
"level": "ERROR",
"format": "%(message)s",
"args": { "url": "https://hooks.example.com" } // passed as kwargs to the constructor
}
Defaults Summary#
Setting |
Default |
|---|---|
Root level |
|
Format |
Python’s |
Date format |
|
Console handler |
Yes (if no handlers configured) |
Bidi support |
|
File max_size |
|
File max_count |
|
File path |
|
File name |
|