moonraker: add software version to system_args

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-11-17 20:13:10 -05:00
parent 2e9c6de5d0
commit b0469da462
3 changed files with 10 additions and 6 deletions

View File

@ -89,5 +89,7 @@ def get_configuration(server, system_args):
if server_cfg.get('enable_debug_logging', True):
logging.getLogger().setLevel(logging.DEBUG)
config['system_args'] = {'logfile': system_args.logfile}
config['system_args'] = {
'logfile': system_args.logfile,
'software_version': system_args.software_version}
return ConfigHelper(server, config, 'server')

View File

@ -553,9 +553,11 @@ def main():
system_args = parser.parse_args()
# Setup Logging
version = utils.get_software_version()
log_file = os.path.normpath(os.path.expanduser(system_args.logfile))
system_args.logfile = log_file
ql = utils.setup_logging(log_file)
system_args.software_version = version
ql = utils.setup_logging(log_file, version)
if sys.version_info < (3, 7):
msg = f"Moonraker requires Python 3.7 or above. " \

View File

@ -28,10 +28,10 @@ class LocalQueueHandler(logging.handlers.QueueHandler):
self.handleError(record)
class MoonrakerLoggingHandler(logging.handlers.TimedRotatingFileHandler):
def __init__(self, filename, **kwargs):
def __init__(self, software_version, filename, **kwargs):
super(MoonrakerLoggingHandler, self).__init__(filename, **kwargs)
self.header = "Moonraker Log Start...\n"
self.header += "Git Version: " + get_software_version() + "\n"
self.header += f"Git Version: {software_version}\n"
self.header += "="*80 + "\n"
if self.stream is not None:
self.stream.write(self.header)
@ -67,14 +67,14 @@ def get_software_version():
return "?"
def setup_logging(log_file):
def setup_logging(log_file, software_version):
root_logger = logging.getLogger()
queue = Queue()
queue_handler = LocalQueueHandler(queue)
root_logger.addHandler(queue_handler)
root_logger.setLevel(logging.INFO)
file_hdlr = MoonrakerLoggingHandler(
log_file, when='midnight', backupCount=2)
software_version, log_file, when='midnight', backupCount=2)
formatter = logging.Formatter(
'%(asctime)s [%(filename)s:%(funcName)s()] - %(message)s')
file_hdlr.setFormatter(formatter)