diff --git a/sopel/logger.py b/sopel/logger.py index a3b2c035ba..417b454c5f 100644 --- a/sopel/logger.py +++ b/sopel/logger.py @@ -5,7 +5,7 @@ import os from logging.config import dictConfig -from .tools import deprecated +from sopel import plugins class IrcLoggingHandler(logging.Handler): @@ -119,49 +119,23 @@ def setup_logging(settings): dictConfig(logging_config) -@deprecated( - 'Use `sopel.logger.get_plugin_logger` instead', - version='7.0', - removed_in='8.0') def get_logger(name=None): """Return a logger for a module, if the name is given. - This is equivalent to ``logging.getLogger('sopel.modules.' + name)`` when - name is given, and ``logging.getLogger('sopel')`` when it is not. - The latter case is intended for use in Sopel's core; modules should call - ``get_logger(__name__)`` to get a logger. - .. deprecated:: 7.0 Use ``logging.getLogger(__name__)`` in Sopel's code instead, and - :func:`get_plugin_logger` for external plugins. + :func:`sopel.plugins.get_logger` for external plugins. + + This will warn a deprecation warning in Sopel 8.0 then removed in 9.0. """ - if name: - return logging.getLogger('sopel.modules.' + name) - else: + if not name: return logging.getLogger('sopel') + parts = name.strip().split('.') + if len(parts) > 1 or parts[0] in ['sopel', 'sopel_modules']: + return logging.getLogger(name) -def get_plugin_logger(plugin_name): - """Return a logger for a plugin. - - :param str plugin_name: name of the plugin - :return: the logger for the given plugin - - This:: - - from sopel import logger - LOGGER = logger.get_plugin_logger('my_custom_plugin') - - is equivalent to this:: - - import logging - LOGGER = logging.getLogger('sopel.externals.my_custom_plugin') - - Internally, Sopel configures logging for the ``sopel`` namespace, so - external plugins can't benefit from it with ``logging.getLogger(__name__)`` - as they won't be in the same namespace. This function uses the - ``plugin_name`` with a prefix inside this namespace. - """ - return logging.getLogger('sopel.externals.%s' % plugin_name) + # assume it's a plugin name, as intended by the original get_logger + return plugins.get_logger(name) diff --git a/sopel/plugins/__init__.py b/sopel/plugins/__init__.py index c473ade9d6..4fd33bad1f 100644 --- a/sopel/plugins/__init__.py +++ b/sopel/plugins/__init__.py @@ -29,6 +29,7 @@ import collections import imp import itertools +import logging import os import pkg_resources @@ -207,3 +208,27 @@ def get_usable_plugins(settings): plugins_info['coretasks'] = core_info return plugins_info + + +def get_logger(plugin_name): + """Return a logger for a plugin. + + :param str plugin_name: name of the plugin + :return: the logger for the given plugin + + This:: + + from sopel import plugins + LOGGER = plugins.get_logger('my_custom_plugin') + + is equivalent to this:: + + import logging + LOGGER = logging.getLogger('sopel.externals.my_custom_plugin') + + Internally, Sopel configures logging for the ``sopel`` namespace, so + external plugins can't benefit from it with ``logging.getLogger(__name__)`` + as they won't be in the same namespace. This function uses the + ``plugin_name`` with a prefix inside this namespace. + """ + return logging.getLogger('sopel.externals.%s' % plugin_name)