Skip to content

Issues in logging framework #29

@SangameshIwx

Description

@SangameshIwx

System Info

This issue is system agnostic

Information

  • The official example scripts
  • My own modified scripts

🐛 Describe the bug

  • Ideally, if the log level is not specified via CLI arguments, it should fall back to the log level defined in the config file (if any); otherwise, it should default to INFO.
    However, due to the following snippet, it always falls back to INFO when the CLI argument is not provided, and ignores any log details specified in the config:
@click.option(
    "--log-level",
    type=click.Choice(
        ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], case_sensitive=False
    ),
    default="INFO", ## Because of this.
    help="Set the logging level",
)
  • Even if the above is fixed (by removing the default), the following code will still fail:
if not log_level:
        log_config = config_dict.get("logging", {})
        level = log_config.get("level", "INFO")
        logger.set_level(level) 
        export_path = log_config.get("export_path")
        if export_path:
            # Replace timestamp placeholder
            if "${TIMESTAMP}" in export_path:
                timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
                export_path = export_path.replace("${TIMESTAMP}", timestamp)
            atexit.register(logger.export_json, export_path)
            logger.info(f"Will export logs to {export_path} on exit.")

Because the logger (which is expected to be a logging manager) is not instantiated, leading to the following error:
The error is

logger.set_level(level)
    ^^^^^^
NameError: name 'logger' is not defined
  • Additionally, the atexit module is not imported, which will also cause a runtime error.
  • And finally, this line will also fail:
    logger.info(f"Will export logs to {export_path} on exit.") and even this fails. since logger is not defined.

Error logs

Some of the errors logs:

logger.set_level(level)
    ^^^^^^
NameError: name 'logger' is not defined

Expected behavior

  • If --log-level is passed via CLI, use it.
    Else, if the config file (config.yaml) contains a logging level, use that.
    If neither is provided, fall back to INFO

  • If the export path is given in the config, then export the logs to the given path.
    But right now, I even feel, the metrics will always be empty in the logs that gets generated, even this need to be checked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions