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
{{ message }}
This repository was archived by the owner on Dec 21, 2024. It is now read-only.
You can also add extra fields to your json output by specifying a dict in place of message, as well as by specifying an extra={} argument.
60
+
You can also add extra fields to your json output by specifying a dict in place of message, as well as by specifying an `extra={}` argument.
61
+
48
62
Contents of these dictionaries will be added at the root level of the entry and may override basic fields.
63
+
64
+
You can also use the `add_fields` method to add to or generally normalize the set of default set of fields, it is be called for every log event. For example, to unify default fields with those provided by [structlog](http://www.structlog.org/) you could do something like this:
To use the module with a config file using the [`fileConfig` function](https://docs.python.org/3/library/logging.config.html#logging.config.fileConfig), use the class `pythonjsonlogger.jsonlogger.JsonFormatter`. Here is a sample config file.
67
104
68
-
[loggers]
69
-
keys = root,custom
70
-
71
-
[logger_root]
72
-
handlers =
73
-
74
-
[logger_custom]
75
-
level = INFO
76
-
handlers = custom
77
-
qualname = custom
78
-
79
-
[handlers]
80
-
keys = custom
81
-
82
-
[handler_custom]
83
-
class = StreamHandler
84
-
level = INFO
85
-
formatter = json
86
-
args = (sys.stdout,)
87
-
88
-
[formatters]
89
-
keys = json
90
-
91
-
[formatter_json]
92
-
format = %(message)s
93
-
class = pythonjsonlogger.jsonlogger.JsonFormatter
94
-
95
-
Example
96
-
=======
105
+
```ini
106
+
[loggers]
107
+
keys = root,custom
108
+
109
+
[logger_root]
110
+
handlers =
111
+
112
+
[logger_custom]
113
+
level = INFO
114
+
handlers = custom
115
+
qualname = custom
116
+
117
+
[handlers]
118
+
keys = custom
119
+
120
+
[handler_custom]
121
+
class = StreamHandler
122
+
level = INFO
123
+
formatter = json
124
+
args = (sys.stdout,)
125
+
126
+
[formatters]
127
+
keys = json
128
+
129
+
[formatter_json]
130
+
format = %(message)s
131
+
class = pythonjsonlogger.jsonlogger.JsonFormatter
132
+
```
133
+
134
+
Example Output
135
+
==============
97
136
98
137
Sample JSON with a full formatter (basically the log message from the unit test). Every log message will appear on 1 line like a typical logger.
0 commit comments