Skip to content

Commit

Permalink
made log levels configurable via command line parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ-Author committed Oct 23, 2024
1 parent f7c7b5e commit e83f9b5
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions ontologytimemachine/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def _print_logger_info(context_info: str, logger: logging.Logger) -> None :
loggerpp = logging.getLogger(__name__)
#_print_logger_info("config.py getLogger(__name__)",loggerpp)
logger = logging.getLogger("ontologytimemachine.utils.config")
logger = logging.getLogger("ontologytimemachine.utils.config")
#_print_logger_info("config.py getLogger(ontologytimemachine.utils.config)",loggerpp)


Expand Down Expand Up @@ -87,7 +86,8 @@ class OntoFormatConfig:

@dataclass
class Config:
logLevel: LogLevel = LogLevel.INFO
logLevelTimeMachine: LogLevel = LogLevel.INFO
logLevelBase: LogLevel = LogLevel.INFO
ontoFormatConf: OntoFormatConfig = field(default_factory=OntoFormatConfig)
ontoVersion: OntoVersion = OntoVersion.ORIGINAL_FAILOVER_LIVE_LATEST
restrictedAccess: bool = False
Expand Down Expand Up @@ -214,9 +214,18 @@ def parse_arguments(config_str: str = "") -> Config:

# Log level
parser.add_argument(
"--logLevel",
"--logLevelTimeMachine",
type=lambda s: enum_parser(LogLevel, s),
default=default_cfg.logLevel,
default=default_cfg.logLevelTimeMachine,
choices=list(LogLevel),
help=f"Level of the logging: debug, info, warning, error. {help_suffix_template}",
)

# Log level
parser.add_argument(
"--logLevelBase",
type=lambda s: enum_parser(LogLevel, s),
default=default_cfg.logLevelTimeMachine,
choices=list(LogLevel),
help=f"Level of the logging: debug, info, warning, error. {help_suffix_template}",
)
Expand Down Expand Up @@ -267,11 +276,10 @@ def parse_arguments(config_str: str = "") -> Config:


logger2 = logger
#set the log level or proxypy and other modules #TODO make configurable via cmd line parameter
if (True):
logging.basicConfig(
level=log_level_Enum_to_python_logging(LogLevel.INFO), format="%(asctime)s - |%(name)s| %(levelname)s - %(message)s"
)
#set the log level of proxypy and other modules
logging.basicConfig(
level=log_level_Enum_to_python_logging(args.logLevelBase), format="%(asctime)s - |%(name)s| %(levelname)s - %(message)s"
)

#set the log level of the time machine independently
formatter = logging.Formatter("%(asctime)s ||| %(name)s ||| - %(levelname)s - %(message)s")
Expand All @@ -289,23 +297,27 @@ def parse_arguments(config_str: str = "") -> Config:
#logger2 = logging.getLogger("ontologytimemachine.utils.config")
#_print_logger_info("before: config.py->parse_arguments getLogger(ontologytimemachine.utils.config)",logger2)

if args.logLevel == LogLevel.DEBUG:
if args.logLevelTimeMachine == LogLevel.DEBUG:
logger.setLevel(log_level_Enum_to_python_logging(LogLevel.DEBUG))
#_print_logger_info("after: config.py->parse_arguments getLogger(ontologytimemachine.utils.config)",logger2)
logger.debug(f"Logging level set to: {args.logLevel}")
elif args.logLevel == LogLevel.WARNING:
logger.debug(f"Logging level set to: {args.logLevelTimeMachine}")
elif args.logLevelTimeMachine == LogLevel.INFO:
logger.setLevel(logging.INFO)
logger.info(f"Logging level set to: {args.logLevelTimeMachine}")
elif args.logLevelTimeMachine == LogLevel.WARNING:
logger.setLevel(logging.WARNING)
logger.warning(f"Logging level set to: {args.logLevel}")
elif args.logLevel == LogLevel.ERROR:
logger.warning(f"Logging level set to: {args.logLevelTimeMachine}")
elif args.logLevelTimeMachine == LogLevel.ERROR:
logger.setLevel(logging.ERROR)
logger.error(f"Logging level set to: {args.logLevel}")
elif args.logLevel == LogLevel.CRITICAL:
logger.error(f"Logging level set to: {args.logLevelTimeMachine}")
elif args.logLevelTimeMachine == LogLevel.CRITICAL:
logger.setLevel(logging.CRITICAL)
logger.critical(f"Logging level set to: {args.logLevel}")
logger.critical(f"Logging level set to: {args.logLevelTimeMachine}")

# Initialize the Config class with parsed arguments
config = Config(
logLevel=args.logLevel,
logLevelTimeMachine=args.logLevelTimeMachine,
logLevelBase=args.logLevelBase,
ontoFormatConf=OntoFormatConfig(
args.ontoFormat, args.ontoPrecedence, args.patchAcceptUpstream
),
Expand Down

0 comments on commit e83f9b5

Please sign in to comment.