Logging
Default logging settings and key-value logger.
In Python, logging can be a surprisingly complex topic.
So Plain aims for easy-to-use defaults that "just work".
app_logger
The default app_logger
doesn't do much!
But it is paired with the default settings to actually show the logs like you would expect, without any additional configuration.
from plain.logs import app_logger
def example_function():
app_logger.info("Hey!")
app_logger.kv
1import logging
2import logging.config
3from os import environ
4
5
6def configure_logging(logging_settings):
7 # Load the defaults
8 default_logging = {
9 "version": 1,
10 "disable_existing_loggers": False,
11 "formatters": {
12 "simple": {
13 "format": "[%(levelname)s] %(message)s",
14 },
15 },
16 "handlers": {
17 "console": {
18 "level": "INFO",
19 "class": "logging.StreamHandler",
20 "formatter": "simple",
21 },
22 },
23 "loggers": {
24 "plain": {
25 "handlers": ["console"],
26 "level": environ.get("PLAIN_LOG_LEVEL", "INFO"),
27 },
28 "app": {
29 "handlers": ["console"],
30 "level": environ.get("APP_LOG_LEVEL", "INFO"),
31 "propagate": False,
32 },
33 },
34 }
35 logging.config.dictConfig(default_logging)
36
37 # Then customize it from settings
38 if logging_settings:
39 logging.config.dictConfig(logging_settings)