@@ -178,34 +178,37 @@ def format(self, record):
178
178
log_record = self .process_log_record (log_record )
179
179
return self .serialize_log_record (log_record )
180
180
181
- def _formatter_factory (name = None , fmt = None , style = None ):
182
- if name is None :
183
- name = 'plaintext'
184
-
185
- if fmt is None :
186
- fmt = '%(asctime)s %(levelname)s %(message)s'
187
-
188
- if style is None :
189
- style = None
190
- # determine the style based on the logging format.
191
- for style in _STYLES :
192
- _style = _STYLES [style ][0 ](fmt )
193
- try :
194
- _style .validate ()
195
- break # exit the loop if fmt passes style validation
196
- except ValueError :
197
- style = None
198
-
199
- if style is None :
200
- raise ValueError ('Invalid logging format: %s' % fmt )
201
-
202
- if name == 'plaintext' :
203
- return PlainTextFormatter (fmt , style = style )
204
- elif name == 'json' :
205
- return CustomJsonFormatter (fmt , style = style )
206
- else :
207
- raise ValueError ('Invalid formatter name: %s' % name )
208
181
182
+ class FormatterFacotry :
183
+ def get_formatter (self , name = None , fmt = None , style = None ):
184
+ if name is None :
185
+ name = 'plaintext'
186
+
187
+ if fmt is None :
188
+ fmt = '%(asctime)s %(levelname)s %(message)s'
189
+
190
+ if style is None :
191
+ style = None
192
+ # determine the style based on the logging format.
193
+ for style in _STYLES :
194
+ _style = _STYLES [style ][0 ](fmt )
195
+ try :
196
+ _style .validate ()
197
+ break # exit the loop if fmt passes style validation
198
+ except ValueError :
199
+ style = None
200
+
201
+ if style is None :
202
+ raise ValueError ('Invalid logging format: %s' % fmt )
203
+
204
+ if name == 'plaintext' :
205
+ return PlainTextFormatter (fmt , style = style )
206
+ elif name == 'json' :
207
+ return CustomJsonFormatter (fmt , style = style )
208
+ else :
209
+ raise ValueError ('Invalid formatter name: %s' % name )
210
+
211
+ _formatter_factory = FormatterFacotry ().get_formatter
209
212
BASIC_FORMATTER = _formatter_factory (name = 'plaintext' , fmt = BASIC_FORMAT )
210
213
211
214
class Handler :
0 commit comments