Skip to content

Commit b62d3d4

Browse files
committed
granian logging via json and rich
1 parent 12ab5eb commit b62d3d4

5 files changed

+72
-58
lines changed

compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
- .secrets
88
command: bash -c "
99
uvicorn app.main:app
10-
--log-config ./uvicorn-logging.json
10+
--log-config ./logging-uvicorn.json
1111
--host 0.0.0.0 --port 8080
1212
--lifespan=on --use-colors --loop uvloop --http httptools
1313
--reload --log-level debug

granian-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
env_file:
66
- .env
77
- .secrets
8-
command: granian --interface asgi --host 0.0.0.0 --port 8080 --loop uvloop app.main:app --log-level debug --log-config ./logging-config.json
8+
command: granian --interface asgi --host 0.0.0.0 --port 8080 --loop uvloop app.main:app --access-log --log-level debug --log-config ./logging-granian.json
99
volumes:
1010
- .:/home/code
1111
ports:

logging-config.json

-56
This file was deleted.

logging-granian.json

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"version": 1,
3+
"disable_existing_loggers": false,
4+
"formatters": {
5+
"default": {
6+
"()": "logging.Formatter",
7+
"fmt": "[%(process)d|%(name)-12s] %(message)s"
8+
}
9+
},
10+
"handlers": {
11+
"access": {
12+
"class": "app.utils.logging.RichConsoleHandler",
13+
"omit_repeated_times": true,
14+
"show_time": false,
15+
"enable_link_path": false,
16+
"tracebacks_show_locals": true,
17+
"rich_tracebacks": true,
18+
"formatter": "default",
19+
"width": 140,
20+
"style": "yellow"
21+
},
22+
"sqlalchemy": {
23+
"class": "app.utils.logging.RichConsoleHandler",
24+
"omit_repeated_times": true,
25+
"show_time": false,
26+
"enable_link_path": false,
27+
"tracebacks_show_locals": true,
28+
"rich_tracebacks": true,
29+
"formatter": "default",
30+
"width": 140,
31+
"style": "magenta"
32+
},
33+
"stream": {
34+
"class": "app.utils.logging.RichConsoleHandler",
35+
"omit_repeated_times": true,
36+
"show_time": false,
37+
"enable_link_path": false,
38+
"tracebacks_show_locals": true,
39+
"rich_tracebacks": true,
40+
"formatter": "default",
41+
"width": 140,
42+
"style": "white"
43+
}
44+
},
45+
"loggers": {
46+
"_granian": {
47+
"handlers": [
48+
"stream"
49+
],
50+
"propagate": false,
51+
"level": "DEBUG"
52+
},
53+
"granian.access": {
54+
"handlers": [
55+
"access"
56+
],
57+
"propagate": false,
58+
"level": "DEBUG",
59+
"qualname": "granian.access"
60+
},
61+
"sqlalchemy.engine.Engine": {
62+
"handlers": [
63+
"sqlalchemy"
64+
],
65+
"level": "ERROR",
66+
"propagate": false,
67+
"qualname": "sqlalchemy.engine.Engine"
68+
}
69+
}
70+
}
File renamed without changes.

0 commit comments

Comments
 (0)