Skip to content

Commit

Permalink
Add loguru file configuration to odpy convert (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
JessyBarrette authored Nov 16, 2023
1 parent 1086fd9 commit ab5f891
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
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

0 comments on commit ab5f891

Please sign in to comment.