@@ -90,6 +90,7 @@ def __init__(self, *args, **kwargs):
90
90
the formatted string
91
91
:param rename_fields: an optional dict, used to rename field names in the output.
92
92
Rename message to @message: {'message': '@message'}
93
+ :param static_fields: an optional dict, used to add fields with static values to all logs
93
94
:param json_indent: indent parameter for json.dumps
94
95
:param json_ensure_ascii: ensure_ascii parameter for json.dumps
95
96
:param reserved_attrs: an optional list of fields that will be skipped when
@@ -107,6 +108,7 @@ def __init__(self, *args, **kwargs):
107
108
self .json_ensure_ascii = kwargs .pop ("json_ensure_ascii" , True )
108
109
self .prefix = kwargs .pop ("prefix" , "" )
109
110
self .rename_fields = kwargs .pop ("rename_fields" , {})
111
+ self .static_fields = kwargs .pop ("static_fields" , {})
110
112
reserved_attrs = kwargs .pop ("reserved_attrs" , RESERVED_ATTRS )
111
113
self .reserved_attrs = dict (zip (reserved_attrs , reserved_attrs ))
112
114
self .timestamp = kwargs .pop ("timestamp" , False )
@@ -155,6 +157,7 @@ def add_fields(self, log_record, record, message_dict):
155
157
log_record [self .rename_fields [field ]] = record .__dict__ .get (field )
156
158
else :
157
159
log_record [field ] = record .__dict__ .get (field )
160
+ log_record .update (self .static_fields )
158
161
log_record .update (message_dict )
159
162
merge_record_extra (record , log_record , reserved = self ._skip_fields )
160
163
0 commit comments