Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loguru file configuration to odpy convert #63

Merged
merged 8 commits into from
Nov 16, 2023
1 change: 1 addition & 0 deletions ocean_data_parser/batch/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def _get_config(config: dict = None, **kwargs) -> dict:
}
config["output"].update(output_kwarg)
config["registry"].update(registry_kwarg)

return config

def get_excluded_files(self) -> list:
Expand Down
30 changes: 28 additions & 2 deletions ocean_data_parser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,34 @@ def emit(self, record):
default="INFO",
envvar="ODPY_LOG_FILE_LEVEL",
)
@click.option(
"--log-file-rotation",
type=str,
help="Rotate log file at a given interval. Given value must be compatible with pandas.TimeDelta",
default=None,
)
@click.option(
"--log-file-retention",
type=str,
help="Delete log file after a given time period. Given value must be compatible with pandas.TimeDelta",
default=None,
)
@click.option(
"--show-arguments",
is_flag=True,
default=False,
help="Print present argument values",
hidden=True,
)
def main(verbose, log_level, log_file, log_file_level, show_arguments):
def main(
verbose,
log_level,
log_file,
log_file_level,
log_file_rotation,
log_file_retention,
show_arguments,
):
"""Ocean Data Parser command line main interface."""
log_format = VERBOSE_LOG_FORMAT if verbose else LOG_FORMAT
logger.add(
Expand All @@ -102,7 +122,13 @@ def main(verbose, log_level, log_file, log_file_level, show_arguments):
format=VERBOSE_LOG_FORMAT if verbose else LOG_FORMAT,
)
if log_file:
logger.add(log_file, level=log_file_level, format=log_format)
logger.add(
log_file,
level=log_file_level,
format=log_format,
rotation=log_file_rotation,
retention=log_file_retention,
)

logger.info("ocean-data-parser[{}]: log-level={}", __version__, log_level)
if show_arguments:
Expand Down