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

Remove loglevels functionality #684

Closed
jodal opened this issue Jan 31, 2014 · 6 comments
Closed

Remove loglevels functionality #684

jodal opened this issue Jan 31, 2014 · 6 comments
Assignees
Labels
C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal
Milestone

Comments

@jodal
Copy link
Member

jodal commented Jan 31, 2014

As it can only be used to decrease the amount of logging from a sublogger, not increase it, this feature is barely useful as currently implemented.

@jodal
Copy link
Member Author

jodal commented Feb 6, 2014

@txomon claimed that the loglevels functionality can be used by increasing the verbosity of everything, then reducing the verbosity explicitly on e.g. the mopidy logger, and then increasing the verbosity of a specific backend or similar. In concrete terms:

mopidy -v -o loglevels/mopidy=info -o loglevels/mopidy.mpd=debug

...should give you debug logging for mopidy.mpd and nothing else.

I've tried this, and it doesn't seem to work on v0.17.0 (pre the recent log setup changes) or on v0.18.1. Thus, I'm still claiming that we should remove the loglevels config section.

@adamcik
Copy link
Member

adamcik commented Feb 6, 2014

I believe something along the lines of the following should do the trick. We could even refactor this further putting mopidy, mopidy_* and root values in the loglevels dict if done right.

I.e. I think we should reconsider if keeping this is as simple as the diff below.

diff --git a/mopidy/utils/log.py b/mopidy/utils/log.py
index 6004b9f..c3a6a3d 100644
--- a/mopidy/utils/log.py
+++ b/mopidy/utils/log.py
@@ -62,10 +62,15 @@ LOG_LEVELS = {


 class VerbosityFilter(logging.Filter):
-    def __init__(self, verbosity_level):
+    def __init__(self, verbosity_level, loglevels):
         self.verbosity_level = verbosity_level
+        self.loglevels = loglevels

     def filter(self, record):
+        for name, required_log_level in self.loglevels.items():
+            if record.name == name or record.name.startswith(name + '.'):
+                return record.levelno >= required_log_level
+
         if record.name.startswith('mopidy'):
             required_log_level = LOG_LEVELS[self.verbosity_level]['mopidy']
         else:
@@ -79,7 +84,7 @@ def setup_console_logging(config, verbosity_level):
     if verbosity_level > max(LOG_LEVELS.keys()):
         verbosity_level = max(LOG_LEVELS.keys())

-    verbosity_filter = VerbosityFilter(verbosity_level)
+    verbosity_filter = VerbosityFilter(verbosity_level, config['loglevels'])

     if verbosity_level < 1:
         log_format = config['logging']['console_format']

@jodal
Copy link
Member Author

jodal commented Feb 6, 2014

I was just about to push the removal of this, but your fix seems beautifully simple. I'll give it a try.

@jodal
Copy link
Member Author

jodal commented Feb 6, 2014

Fixed by 40cadbf.

@jodal jodal closed this as completed Feb 6, 2014
@txomon
Copy link
Member

txomon commented Feb 6, 2014

Thanks!!! I promise I use it!! I will do a nice use of it :)

@jodal jodal self-assigned this Feb 6, 2014
@jodal
Copy link
Member Author

jodal commented Feb 7, 2014

Related fixes: 1ef1116 and 5551d09.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: A PR with an enhancement or an issue with an enhancement proposal
Projects
None yet
Development

No branches or pull requests

3 participants