You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python log formatter for Google Cloud according to [v2 specification](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry) using [python-json-logger](https://github.com/madzak/python-json-logger) formatter
8
+
9
+
Inspired by Elixir's [logger_json](https://github.com/Nebo15/logger_json)
10
+
11
+
## Instalation
12
+
13
+
### Pipenv
14
+
15
+
```
16
+
pipenv install google_cloud_logger
17
+
```
18
+
19
+
### Pip
20
+
21
+
```
22
+
pip install google_cloud_logger
23
+
```
24
+
25
+
## Usage
26
+
27
+
```python
28
+
LOG_CONFIG= {
29
+
"version": 1,
30
+
"formatters": {
31
+
"json": {
32
+
"()": "google_cloud_logger.GoogleCloudFormatter",
33
+
"application_info": {
34
+
"type": "python-application",
35
+
"name": "Example Application"
36
+
},
37
+
"format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s"
38
+
}
39
+
},
40
+
"handlers": {
41
+
"json": {
42
+
"class": "logging.StreamHandler",
43
+
"formatter": "json"
44
+
}
45
+
},
46
+
"loggers": {
47
+
"root": {
48
+
"level": "INFO",
49
+
"handlers": ["json"]
50
+
}
51
+
}
52
+
}
53
+
import logging
54
+
55
+
from logging import config
56
+
57
+
config.dictConfig(LOG_CONFIG) # load log config from dict
58
+
59
+
logger = logging.getLogger("root") # get root logger instance
60
+
61
+
62
+
logger.info("farofa", extra={"extra": "extra"}) # log message with extra arguments
0 commit comments