Beispiel #1
0
def _setup_logging_to_stdout(stdout_log_level):
	"""Creates a stream handler at the given log level and attaches it to
	the root logger.
	"""
	stream_handler = logging.StreamHandler()
	stream_handler.setLevel(stdout_log_level)
	stream_handler.setFormatter(logging.Formatter('[%(levelname)7s] %(message)s'))
	
	handler = CurrentThreadHandler(target_handler=stream_handler)
	handler.setLevel(stdout_log_level)
	logging.root.addHandler(handler)
Beispiel #2
0
def _setup_error_logging_to_file():
	"""Creates a handler which logs to a file in the case of an error, and
	attaches it to the root logger.
	"""
	file_handler = logging.FileHandler(ERROR_LOG_FILE, delay=True)
	file_handler.setFormatter(logging.Formatter('%(asctime)s [%(levelname)7s] %(message)s'))
	file_handler.setLevel(logging.DEBUG)

	accident_handler = AccidentHandler(target=file_handler, capacity=9999, flush_level='ERROR')
	accident_handler.setLevel(logging.DEBUG)

	thread_handler = CurrentThreadHandler(target_handler=accident_handler)
	thread_handler.setLevel(logging.DEBUG)

	logging.root.addHandler(thread_handler)