feat: add flag to disable logging to stderr
This commit is contained in:
parent
5ad98f01fe
commit
39d11a59b3
@ -6,19 +6,18 @@ import typing
|
||||
|
||||
def set_up_logging(
|
||||
config: kalpaa.config.Config,
|
||||
log_stream: bool,
|
||||
log_file: typing.Optional[str],
|
||||
create_logfile_parents: bool = True,
|
||||
):
|
||||
handlers: typing.List[logging.Handler]
|
||||
if log_file is None:
|
||||
handlers = [
|
||||
logging.StreamHandler(),
|
||||
]
|
||||
else:
|
||||
handlers: typing.List[logging.Handler] = []
|
||||
if log_stream:
|
||||
handlers.append(logging.StreamHandler())
|
||||
if log_file is not None:
|
||||
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)]
|
||||
handlers.append(logging.FileHandler(log_file))
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format=config.general_config.log_pattern,
|
||||
|
@ -73,6 +73,13 @@ def parse_args():
|
||||
default=None,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--log-stream",
|
||||
action="store_true",
|
||||
help="Log to stream",
|
||||
default=False,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-d",
|
||||
"--directory-label",
|
||||
@ -122,7 +129,11 @@ def main():
|
||||
|
||||
_logger.info(skip)
|
||||
|
||||
kalpaa.common.set_up_logging(config, str(root / f"logs/kalpaa_{label}.log"))
|
||||
kalpaa.common.set_up_logging(
|
||||
config,
|
||||
log_stream=args.log_stream,
|
||||
log_file=str(root / f"logs/kalpaa_{label}.log"),
|
||||
)
|
||||
|
||||
_logger.info(
|
||||
f"Root dir is {root}, copying over {config.general_config.indexes_json_name}, {config.general_config.dots_json_name} and {args.config_file}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user