summaryrefslogtreecommitdiffstats
path: root/deluge/log.py
diff options
context:
space:
mode:
authorPedro Algarvio <pedro@algarvio.me>2011-06-04 09:02:53 +0100
committerPedro Algarvio <pedro@algarvio.me>2011-06-04 09:02:53 +0100
commitabe0031c2bf369fd433321cb591728c390ef419d (patch)
tree4fa2b0ac963b4c71c703af6000da393164273972 /deluge/log.py
parent13db148a1127e627e284c7f756dd9c3fe633edd3 (diff)
downloaddeluge-abe0031c2bf369fd433321cb591728c390ef419d.tar.gz
deluge-abe0031c2bf369fd433321cb591728c390ef419d.tar.bz2
deluge-abe0031c2bf369fd433321cb591728c390ef419d.zip
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.
Diffstat (limited to 'deluge/log.py')
-rw-r--r--deluge/log.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/deluge/log.py b/deluge/log.py
index c2a40da6f..034a0aea7 100644
--- a/deluge/log.py
+++ b/deluge/log.py
@@ -232,6 +232,17 @@ def setLoggerLevel(level, logger_name=None):
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:
return logging.getLogger(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:
from deluge.log import LOG as log
-This has been deprecated in favour of an enhanced logging system and "LOG" will
-be removed on the next major version release of Deluge, meaning, code will break,
-specially plugins.
+or:
+ from deluge.log import getPluginLogger
+
+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
triggered this warning, please report to it's author.
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
+ log = logging.getLogger(__name__)
- import logging
- log = logging.getLogger(__name__)
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:"""