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(
|
def set_up_logging(
|
||||||
config: kalpaa.config.Config,
|
config: kalpaa.config.Config,
|
||||||
|
log_stream: bool,
|
||||||
log_file: typing.Optional[str],
|
log_file: typing.Optional[str],
|
||||||
create_logfile_parents: bool = True,
|
create_logfile_parents: bool = True,
|
||||||
):
|
):
|
||||||
handlers: typing.List[logging.Handler]
|
handlers: typing.List[logging.Handler] = []
|
||||||
if log_file is None:
|
if log_stream:
|
||||||
handlers = [
|
handlers.append(logging.StreamHandler())
|
||||||
logging.StreamHandler(),
|
if log_file is not None:
|
||||||
]
|
|
||||||
else:
|
|
||||||
if create_logfile_parents:
|
if create_logfile_parents:
|
||||||
# create any parent directories for the log file if needed.
|
# create any parent directories for the log file if needed.
|
||||||
pathlib.Path(log_file).parent.mkdir(parents=True, exist_ok=True)
|
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(
|
logging.basicConfig(
|
||||||
level=logging.DEBUG,
|
level=logging.DEBUG,
|
||||||
format=config.general_config.log_pattern,
|
format=config.general_config.log_pattern,
|
||||||
|
@ -73,6 +73,13 @@ def parse_args():
|
|||||||
default=None,
|
default=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--log-stream",
|
||||||
|
action="store_true",
|
||||||
|
help="Log to stream",
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-d",
|
"-d",
|
||||||
"--directory-label",
|
"--directory-label",
|
||||||
@ -122,7 +129,11 @@ def main():
|
|||||||
|
|
||||||
_logger.info(skip)
|
_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(
|
_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}"
|
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