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

Use a named logger instead of the root logger #89

Open
vgiotsas opened this issue Feb 23, 2018 · 1 comment · May be fixed by #92
Open

Use a named logger instead of the root logger #89

vgiotsas opened this issue Feb 23, 2018 · 1 comment · May be fixed by #92

Comments

@vgiotsas
Copy link

Currently (v. 1.2.1) all the warnings are logged using the root logger which isn't very helpful since the logging messages do not identify which module emitted the warning message, which is especially problematic when using sagan in scripts that include other libraries that also don't use named loggers.

For libraries, the best practice for logging is to use Loggers with name __name__ to ensure no name collisions.

@danielquinn
Copy link
Collaborator

I have a handy code snippet that I use these days to keep logging easy. Maybe this would help?

import logging


class LogMixin(object):
    """
    Use this mixin to do logging:

      self.logger.debug("My debugging message")
    """
    _logger = None

    @property
    def logger(self):

        if self._logger:
            return self._logger
        self._logger = logging.getLogger(self.__class__.__module__)

        return self.logger

cunha added a commit to cunha/ripe-atlas-sagan that referenced this issue Jun 16, 2021
The library currently uses the root logger, which prevents
applications from separating their logs from the library's.

With this change, applications can silence or redirect sagan
logs by reconfiguring the "ripe" logger.  In particular, the
following will print only `FATAL` messages from sagan:

```
def main():
    ripe_logger = logging.getLogger("ripe")
    ripe_logger.setLevel(logging.FATAL)
    ...
```

close RIPE-NCC#89
@cunha cunha linked a pull request Jun 16, 2021 that will close this issue
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 a pull request may close this issue.

2 participants