diff --git a/moonraker/confighelper.py b/moonraker/confighelper.py index 0578887..aa9880f 100644 --- a/moonraker/confighelper.py +++ b/moonraker/confighelper.py @@ -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') diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index 7b55cdf..c2f79bc 100644 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -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. " \ diff --git a/moonraker/utils.py b/moonraker/utils.py index 75b7835..fde1640 100644 --- a/moonraker/utils.py +++ b/moonraker/utils.py @@ -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)