1# Logs
2
3**Logging configuration and utilities.**
4
5In Python, configuring logging can be surprisingly complex. For most use cases, Plain provides a [default configuration](./configure.py) that "just works".
6
7By default, both the `plain` and `app` loggers are set to the `INFO` level. You can quickly change this by using the `PLAIN_LOG_LEVEL` and `APP_LOG_LEVEL` environment variables.
8
9## `app_logger`
10
11The `app_logger` is a pre-configured logger you can use inside your app code.
12
13```python
14from plain.logs import app_logger
15
16
17def example_function():
18 app_logger.info("Hey!")
19```
20
21## `app_logger.kv`
22
23The key-value logging format is popular for outputting more structured logs that are still human-readable.
24
25```python
26from plain.logs import app_logger
27
28
29def example_function():
30 app_logger.kv("Example log line with", example_key="example_value")
31```
32
33## Logging settings
34
35You can further configure your logging with `settings.LOGGING`.
36
37```python
38# app/settings.py
39LOGGING = {
40 "version": 1,
41 "disable_existing_loggers": False,
42 "handlers": {
43 "console": {
44 "class": "logging.StreamHandler",
45 },
46 },
47 "loggers": {
48 "mylogger": {
49 "handlers": ["console"],
50 "level": "DEBUG",
51 },
52 },
53}
54```