MCPcopy Create free account
hub / github.com/EasyIME/PIME / enable_pretty_logging

Function enable_pretty_logging

python/python3/tornado/log.py:215–262  ·  view source on GitHub ↗

Turns on formatted logging output as configured. This is called automatically by `tornado.options.parse_command_line` and `tornado.options.parse_config_file`.

(
    options: Any = None, logger: Optional[logging.Logger] = None
)

Source from the content-addressed store, hash-verified

213
214
215def enable_pretty_logging(
216 options: Any = None, logger: Optional[logging.Logger] = None
217) -> None:
218 """Turns on formatted logging output as configured.
219
220 This is called automatically by `tornado.options.parse_command_line`
221 and `tornado.options.parse_config_file`.
222 """
223 if options is None:
224 import tornado.options
225
226 options = tornado.options.options
227 if options.logging is None or options.logging.lower() == "none":
228 return
229 if logger is None:
230 logger = logging.getLogger()
231 logger.setLevel(getattr(logging, options.logging.upper()))
232 if options.log_file_prefix:
233 rotate_mode = options.log_rotate_mode
234 if rotate_mode == "size":
235 channel = logging.handlers.RotatingFileHandler(
236 filename=options.log_file_prefix,
237 maxBytes=options.log_file_max_size,
238 backupCount=options.log_file_num_backups,
239 encoding="utf-8",
240 ) # type: logging.Handler
241 elif rotate_mode == "time":
242 channel = logging.handlers.TimedRotatingFileHandler(
243 filename=options.log_file_prefix,
244 when=options.log_rotate_when,
245 interval=options.log_rotate_interval,
246 backupCount=options.log_file_num_backups,
247 encoding="utf-8",
248 )
249 else:
250 error_message = (
251 "The value of log_rotate_mode option should be "
252 + '"size" or "time", not "%s".' % rotate_mode
253 )
254 raise ValueError(error_message)
255 channel.setFormatter(LogFormatter(color=False))
256 logger.addHandler(channel)
257
258 if options.log_to_stderr or (options.log_to_stderr is None and not logger.handlers):
259 # Set up color if we are in a tty and curses is installed
260 channel = logging.StreamHandler()
261 channel.setFormatter(LogFormatter())
262 logger.addHandler(channel)
263
264
265def define_logging_options(options: Any = None) -> None:

Callers 3

test_log_fileMethod · 0.90
define_logging_optionsFunction · 0.85

Calls 2

LogFormatterClass · 0.85
upperMethod · 0.80

Tested by 2

test_log_fileMethod · 0.72