kalpa/kalpaa/common/cli_utils.py
Deepak Mallubhotla a731a81c6a
Some checks failed
gitea-physics/kalpa/pipeline/head There was a failure building this commit
feat: many disparate updates for modernising
2025-02-21 15:58:12 -06:00

29 lines
733 B
Python

import pathlib
import logging
import kalpaa.config
import typing
def set_up_logging(
config: kalpaa.config.Config,
log_file: typing.Optional[str],
create_logfile_parents: bool = True,
):
handlers: typing.List[logging.Handler]
if log_file is None:
handlers = [
logging.StreamHandler(),
]
else:
if create_logfile_parents:
# create any parent directories for the log file if needed.
pathlib.Path(log_file).parent.mkdir(parents=True, exist_ok=True)
handlers = [logging.StreamHandler(), logging.FileHandler(log_file)]
logging.basicConfig(
level=logging.DEBUG,
format=config.general_config.log_pattern,
handlers=handlers,
)
logging.getLogger("pdme").setLevel(logging.ERROR)
logging.captureWarnings(True)