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.
This commit is contained in:
parent
d1b4523733
commit
1f800bf49a
|
@ -263,21 +263,30 @@ class __BackwardsCompatibleLOG(object):
|
||||||
import warnings
|
import warnings
|
||||||
logger_name = 'deluge'
|
logger_name = 'deluge'
|
||||||
stack = inspect.stack()
|
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])
|
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,
|
warnings.warn_explicit(DEPRECATION_WARNING, DeprecationWarning,
|
||||||
module_stack[1], module_stack[2],
|
module_stack[1], module_stack[2],
|
||||||
caller_module.__name__)
|
caller_module_name)
|
||||||
for member in stack:
|
if caller_module:
|
||||||
module = inspect.getmodule(member[0])
|
for member in stack:
|
||||||
if not module:
|
module = inspect.getmodule(member[0])
|
||||||
continue
|
if not module:
|
||||||
if module.__name__ in ('deluge.plugins.pluginbase',
|
continue
|
||||||
'deluge.plugins.init'):
|
if module.__name__ in ('deluge.plugins.pluginbase',
|
||||||
logger_name += '.plugin.%s' % caller_module.__name__
|
'deluge.plugins.init'):
|
||||||
# Monkey Patch The Plugin Module
|
logger_name += '.plugin.%s' % caller_module_name
|
||||||
caller_module.log = logging.getLogger(logger_name)
|
# Monkey Patch The Plugin Module
|
||||||
break
|
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)
|
return getattr(logging.getLogger(logger_name), name)
|
||||||
|
|
||||||
LOG = __BackwardsCompatibleLOG()
|
LOG = __BackwardsCompatibleLOG()
|
||||||
|
|
Loading…
Reference in New Issue