utils: add support for logging to stdout

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-12-05 19:20:03 -05:00
parent aba5bdf339
commit aaa6ec8eb2
1 changed files with 7 additions and 1 deletions

View File

@ -6,6 +6,7 @@
import logging
import logging.handlers
import os
import sys
import subprocess
import asyncio
from queue import SimpleQueue as Queue
@ -75,9 +76,14 @@ def setup_logging(log_file, software_version):
root_logger.setLevel(logging.INFO)
file_hdlr = MoonrakerLoggingHandler(
software_version, log_file, when='midnight', backupCount=2)
stdout_hdlr = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(
'%(asctime)s [%(filename)s:%(funcName)s()] - %(message)s')
file_hdlr.setFormatter(formatter)
listener = logging.handlers.QueueListener(queue, file_hdlr)
stdout_fmt = logging.Formatter(
'[%(filename)s:%(funcName)s()] - %(message)s')
stdout_hdlr.setFormatter(stdout_fmt)
listener = logging.handlers.QueueListener(
queue, file_hdlr, stdout_hdlr)
listener.start()
return listener