summaryrefslogtreecommitdiffstats
path: root/deluge/log.py
diff options
context:
space:
mode:
authorPedro Algarvio <ufs@ufsoft.org>2011-01-01 18:33:41 +0000
committerPedro Algarvio <ufs@ufsoft.org>2011-01-01 18:33:41 +0000
commit1f800bf49a4cf5ce93765dc6b7d1b102003f25ec (patch)
tree08c76ecd597a3c3f3b2a19be45b82c2b92f6b016 /deluge/log.py
parentd1b452373371d83bfce85a43c6de8f4b58fbfa5c (diff)
downloaddeluge-1f800bf49a4cf5ce93765dc6b7d1b102003f25ec.tar.gz
deluge-1f800bf49a4cf5ce93765dc6b7d1b102003f25ec.tar.bz2
deluge-1f800bf49a4cf5ce93765dc6b7d1b102003f25ec.zip
On a 64bit platform with old plugins, the deprecation code was unable to find out which was the caller module. This might also happen on other platforms although I was unable to reproduce it on x86. Anyway, handle it cleanly.
Diffstat (limited to 'deluge/log.py')
-rw-r--r--deluge/log.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/deluge/log.py b/deluge/log.py
index af610e00a..a5e8f64e1 100644
--- a/deluge/log.py
+++ b/deluge/log.py
@@ -263,21 +263,30 @@ class __BackwardsCompatibleLOG(object):
import warnings
logger_name = 'deluge'
stack = inspect.stack()
- module_stack = stack.pop(1)
+ 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__)
- for member in stack:
- module = inspect.getmodule(member[0])
- if not module:
- continue
- if module.__name__ in ('deluge.plugins.pluginbase',
- 'deluge.plugins.init'):
- logger_name += '.plugin.%s' % caller_module.__name__
- # Monkey Patch The Plugin Module
- caller_module.log = logging.getLogger(logger_name)
- break
+ caller_module_name)
+ if caller_module:
+ for member in stack:
+ module = inspect.getmodule(member[0])
+ if not module:
+ continue
+ if module.__name__ in ('deluge.plugins.pluginbase',
+ 'deluge.plugins.init'):
+ logger_name += '.plugin.%s' % caller_module_name
+ # Monkey Patch The Plugin Module
+ caller_module.log = logging.getLogger(logger_name)
+ break
+ else:
+ logging.getLogger(logger_name).warning(
+ "Unable to monkey-patch the calling module's `log` attribute! "
+ "You should really update and rebuild your plugins..."
+ )
return getattr(logging.getLogger(logger_name), name)
LOG = __BackwardsCompatibleLOG()