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 console logger #241

Merged
merged 39 commits into from
Apr 22, 2022
Merged

Add console logger #241

merged 39 commits into from
Apr 22, 2022

Conversation

samet-akcay
Copy link
Contributor

Description

Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the pre-commit style and check guidelines of this project.
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

@samet-akcay samet-akcay marked this pull request as draft April 20, 2022 11:23
Copy link
Collaborator

@ashwinvaidya17 ashwinvaidya17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just two minor comments.

anomalib/utils/loggers/console.py Outdated Show resolved Hide resolved
tools/train.py Outdated
@@ -39,6 +40,7 @@ def get_args() -> Namespace:
parser = ArgumentParser()
parser.add_argument("--model", type=str, default="padim", help="Name of the algorithm to train/test")
parser.add_argument("--model_config_path", type=str, required=False, help="Path to a model config file")
parser.add_argument("--log-level", type=str, help="<DEBUG, INFO, WARNING, ERROR>")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this log-level passed to the console logger somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, it's a bit more involved than we thought. It's something I was going to bring up. This could be either addressed in a separate PR, or this one needs to be modified a little bit.

@samet-akcay samet-akcay marked this pull request as ready for review April 21, 2022 08:43
AVAILABLE_LOGGERS = ["tensorboard", "wandb", "csv"]


class UnknownLogger(Exception):
"""This is raised when the logger option in `config.yaml` file is set incorrectly."""


def get_logger(
def get_console_logger(name: Optional[str] = None, level: Union[int, str] = logging.INFO) -> Logger:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could rename this configure_logger and instead of having it return the logger, just define logger = logging.getLogger("anomalib") in train.py and the other entrypoitns. That way the logging in those entrypoint files would be more in line with the other submodules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that we already have a logger defined for experiment loggers. This is the main reason for not being able to use logger name. You could refer to this line, for further details.

I like the name configure_logger, but again in line 68, we already have get_logger

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work if the existing logger were renamed to something like experiment_logger or similar

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could rename the experiment logger to experiment_logger. This would make sense since the function is already renamed to get_experiment_logger in your PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like the following in train.py and other entrypoints?

...
configure_logger()
logger = logging.getLogger("anomalib")
...

If yes, this would cost us two lines for the sake of following the standard logging definition.

We could maybe rename this to get_logger instead, which would be a one liner in this case. And the experiment logger would also be renamed accordingly.

...
logger = get_logger("anomalib", level=logging.INFO)
...
experiment_logger = get_experiment_logger(config)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If yes, this would cost us two lines for the sake of following the standard logging definition.

It would add a single line logger = logging.getLogger("anomalib"), but this line would be placed at the top of the file, right under the imports. So it may be an additional line, but it does not clutter the train function.

Also this same line would be removed from the get_logger/configure_logger function, which would end up a lot cleaner, because it would also only require a single argument (log_level), no logic for setting the logger name, and no return type.

Copy link
Contributor

@djdameln djdameln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@samet-akcay samet-akcay merged commit ce279f9 into development Apr 22, 2022
@samet-akcay samet-akcay deleted the feature/sa/add-console-logger branch April 22, 2022 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add proper logging and remove print statements with logger via logger = logging.getLogger("pytorch_lightning")
3 participants