mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-02 22:53:40 +00:00
Trigger a deprecation warning for code calling "getPluginLogger".
Since the plugins namespace was merged into master, calling "logging.getLogger(__name__)" will result in a properly named logger for plugins which will allow logging filtering. The previous workaround "getPluginLogger()", is now deprecated.
This commit is contained in:
parent
13db148a11
commit
abe0031c2b
@ -232,6 +232,17 @@ def setLoggerLevel(level, logger_name=None):
|
|||||||
|
|
||||||
|
|
||||||
def getPluginLogger(logger_name):
|
def getPluginLogger(logger_name):
|
||||||
|
import warnings
|
||||||
|
stack = inspect.stack()
|
||||||
|
stack.pop(0) # The logging call from this module
|
||||||
|
module_stack = stack.pop(0) # The module that called the log function
|
||||||
|
caller_module = inspect.getmodule(module_stack[0])
|
||||||
|
# In some weird cases caller_module might be None, try to continue
|
||||||
|
caller_module_name = getattr(caller_module, '__name__', '')
|
||||||
|
warnings.warn_explicit(DEPRECATION_WARNING, DeprecationWarning,
|
||||||
|
module_stack[1], module_stack[2],
|
||||||
|
caller_module_name)
|
||||||
|
|
||||||
if 'deluge.plugins.' in logger_name:
|
if 'deluge.plugins.' in logger_name:
|
||||||
return logging.getLogger(logger_name)
|
return logging.getLogger(logger_name)
|
||||||
return logging.getLogger("deluge.plugin.%s" % logger_name)
|
return logging.getLogger("deluge.plugin.%s" % logger_name)
|
||||||
@ -240,27 +251,22 @@ def getPluginLogger(logger_name):
|
|||||||
DEPRECATION_WARNING = """You seem to be using old style logging on your code, ie:
|
DEPRECATION_WARNING = """You seem to be using old style logging on your code, ie:
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
This has been deprecated in favour of an enhanced logging system and "LOG" will
|
or:
|
||||||
be removed on the next major version release of Deluge, meaning, code will break,
|
from deluge.log import getPluginLogger
|
||||||
specially plugins.
|
|
||||||
|
This has been deprecated in favour of an enhanced logging system and both "LOG"
|
||||||
|
and "getPluginLogger" will be removed on the next major version release of Deluge,
|
||||||
|
meaning, code will break, specially plugins.
|
||||||
If you're seeing this message and you're not the developer of the plugin which
|
If you're seeing this message and you're not the developer of the plugin which
|
||||||
triggered this warning, please report to it's author.
|
triggered this warning, please report to it's author.
|
||||||
If you're the developer, please stop using the above code and instead use:
|
If you're the developer, please stop using the above code and instead use:
|
||||||
|
|
||||||
from deluge.log import getPluginLogger
|
|
||||||
log = getPluginLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
The above will result in, regarding the "Label" plugin for example a log message similar to:
|
|
||||||
15:33:54 [deluge.plugin.label.core:78 ][INFO ] *** Start Label plugin ***
|
|
||||||
|
|
||||||
If you wish not to have 'deluge.plugin' on the log message you can then instead use:
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
The above will result in, regarding the "Label" plugin for example a log message similar to:
|
The above will result in, regarding the "Label" plugin for example a log message similar to:
|
||||||
15:33:54 [label.core:78 ][INFO ] *** Start Label plugin ***
|
15:33:54 [deluge.plugins.label.core:78 ][INFO ] *** Start Label plugin ***
|
||||||
|
|
||||||
Triggering code:"""
|
Triggering code:"""
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ class PluginManagerBase:
|
|||||||
log.exception(e)
|
log.exception(e)
|
||||||
continue
|
continue
|
||||||
instance.enable()
|
instance.enable()
|
||||||
if not instance.__module__.startswith("deluge.plugins"):
|
if not instance.__module__.startswith("deluge.plugins."):
|
||||||
import warnings
|
import warnings
|
||||||
warnings.warn_explicit(
|
warnings.warn_explicit(
|
||||||
DEPRECATION_WARNING % name,
|
DEPRECATION_WARNING % name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user