From ffd296ef997b1b60a210fde15326d6af8a7c0231 Mon Sep 17 00:00:00 2001 From: stahn Date: Tue, 10 Mar 2026 09:21:39 +0100 Subject: [PATCH 1/3] eos/options.py aktualisiert --- eos/options.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/eos/options.py b/eos/options.py index 233e41e..2683f23 100644 --- a/eos/options.py +++ b/eos/options.py @@ -526,6 +526,13 @@ class ReflectivityOutputConfig(ArgParsable): 'help': '?', }, ) + logFile: bool = field( + default = False, + metadata = { + 'group': 'output', + 'help': 'write log file "eos.log"', + } + ) plot: bool = field( default=False, metadata={ From 927a18e64bbf258fcbf2f12fe80a71d96a13ff8d Mon Sep 17 00:00:00 2001 From: jochenstahn Date: Tue, 10 Mar 2026 13:42:59 +0100 Subject: [PATCH 2/3] logfile nor optional --- eos/logconfig.py | 34 +++++++++++++++++++++------------- eos/options.py | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/eos/logconfig.py b/eos/logconfig.py index b93b104..38b9c34 100644 --- a/eos/logconfig.py +++ b/eos/logconfig.py @@ -4,6 +4,7 @@ Setup for the logging of eos. import sys import logging import logging.handlers +from .options import ReflectivityOutputConfig def setup_logging(): logger = logging.getLogger() # logging.getLogger('quicknxs') @@ -19,19 +20,26 @@ def setup_logging(): console.setLevel(logging.WARNING) logger.addHandler(console) - # if os.path.exists('amor_eos.log'): - # rollover = True - # else: - # rollover = False - logfile = logging.handlers.RotatingFileHandler('amor_eos.log', encoding='utf8', mode='w', - maxBytes=200*1024**2, backupCount=20) - # if rollover: logfile.doRollover() - formatter = logging.Formatter( - '[%(levelname).4s] - %(asctime)s - %(filename)s:%(lineno)i:%(funcName)s %(message)s', - '') - logfile.setFormatter(formatter) - logfile.setLevel(logging.DEBUG) - logger.addHandler(logfile) + if ReflectivityOutputConfig.logFile: + # if os.path.exists('amor_eos.log'): + # rollover = True + # else: + # rollover = False + logfile = logging.handlers.RotatingFileHandler( + 'amor_eos.log', + encoding='utf8', + mode='w', + maxBytes=200*1024**2, + backupCount=20, + ) + # if rollover: logfile.doRollover() + formatter = logging.Formatter( + '[%(levelname).4s] - %(asctime)s - %(filename)s:%(lineno)i:%(funcName)s %(message)s', + '', + ) + logfile.setFormatter(formatter) + logfile.setLevel(logging.DEBUG) + logger.addHandler(logfile) def update_loglevel(verbose=0): if verbose==1: diff --git a/eos/options.py b/eos/options.py index 2683f23..7f56a55 100644 --- a/eos/options.py +++ b/eos/options.py @@ -530,7 +530,7 @@ class ReflectivityOutputConfig(ArgParsable): default = False, metadata = { 'group': 'output', - 'help': 'write log file "eos.log"', + 'help': 'write log file "amor_eos.log"', } ) plot: bool = field( From 3cd2d1a0a96a6659bb06339168cfc6e41aa9cdd5 Mon Sep 17 00:00:00 2001 From: Artur Glavic Date: Tue, 10 Mar 2026 14:34:17 +0100 Subject: [PATCH 3/3] Setup logfile only in eos when command-line parameter set --- eos/__main__.py | 4 +++- eos/logconfig.py | 40 ++++++++++++++++++---------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/eos/__main__.py b/eos/__main__.py index b8a6e1b..c3fff27 100644 --- a/eos/__main__.py +++ b/eos/__main__.py @@ -10,7 +10,7 @@ import logging # need to do absolute import here as pyinstaller requires it from eos.options import ReflectivityConfig, ReaderConfig, ExperimentConfig, ReflectivityReductionConfig, ReflectivityOutputConfig from eos.command_line import commandLineArgs -from eos.logconfig import setup_logging, update_loglevel +from eos.logconfig import setup_logging, update_loglevel, setup_logfile def main(): @@ -27,6 +27,8 @@ def main(): output_config = ReflectivityOutputConfig.from_args(clas) config = ReflectivityConfig(reader_config, experiment_config, reduction_config, output_config) + if output_config.logFile: + setup_logfile() logging.warning('######## eos - data reduction for Amor ########') # only import heavy module if sufficient command line parameters were provided diff --git a/eos/logconfig.py b/eos/logconfig.py index 38b9c34..6893d81 100644 --- a/eos/logconfig.py +++ b/eos/logconfig.py @@ -4,10 +4,9 @@ Setup for the logging of eos. import sys import logging import logging.handlers -from .options import ReflectivityOutputConfig def setup_logging(): - logger = logging.getLogger() # logging.getLogger('quicknxs') + logger = logging.getLogger() logger.setLevel(logging.DEBUG) # rename levels to make clear warning is can be a normal message logging.addLevelName(logging.INFO, 'VERB') @@ -20,26 +19,23 @@ def setup_logging(): console.setLevel(logging.WARNING) logger.addHandler(console) - if ReflectivityOutputConfig.logFile: - # if os.path.exists('amor_eos.log'): - # rollover = True - # else: - # rollover = False - logfile = logging.handlers.RotatingFileHandler( - 'amor_eos.log', - encoding='utf8', - mode='w', - maxBytes=200*1024**2, - backupCount=20, - ) - # if rollover: logfile.doRollover() - formatter = logging.Formatter( - '[%(levelname).4s] - %(asctime)s - %(filename)s:%(lineno)i:%(funcName)s %(message)s', - '', - ) - logfile.setFormatter(formatter) - logfile.setLevel(logging.DEBUG) - logger.addHandler(logfile) + +def setup_logfile(): + logfile = logging.handlers.RotatingFileHandler( + 'amor_eos.log', + encoding='utf8', + mode='w', + maxBytes=200*1024**2, + backupCount=20, + ) + formatter = logging.Formatter( + '[%(levelname).4s] - %(asctime)s - %(filename)s:%(lineno)i:%(funcName)s %(message)s', + '', + ) + logfile.setFormatter(formatter) + logfile.setLevel(logging.DEBUG) + logger = logging.getLogger() + logger.addHandler(logfile) def update_loglevel(verbose=0): if verbose==1: