From 60a0bcdc7a95dae670d722fcb747289a980d13c6 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 2 Jun 2017 08:42:32 -0700 Subject: [PATCH] Rename config option log:stdout -> log:console Closes #386. --- conf.py | 5 +++++ coremods/control.py | 6 +++--- example-conf.yml | 6 ++++-- log.py | 19 ++++++++++--------- plugins/commands.py | 4 ++-- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/conf.py b/conf.py index b6e6dac..85c0bdc 100644 --- a/conf.py +++ b/conf.py @@ -101,6 +101,11 @@ def validateConf(conf, logger=None): if newlogins and not old_login_valid: validate(conf.get('permissions'), "New-style accounts enabled but no permissions block was found. You will not be able to administrate your PyLink instance!") + if conf['logging'].get('stdout'): + _log(logging.WARNING, 'The log:stdout option is deprecated since PyLink 1.2 in favour of ' + '(a more correctly named) log:console. Please update your ' + 'configuration accordingly!', logger=logger) + return conf diff --git a/coremods/control.py b/coremods/control.py index 995c3c5..90cbc26 100644 --- a/coremods/control.py +++ b/coremods/control.py @@ -8,7 +8,7 @@ import sys import atexit from pylinkirc import world, utils, conf, classes -from pylinkirc.log import log, makeFileLogger, stopFileLoggers, stdoutLogLevel +from pylinkirc.log import log, makeFileLogger, stopFileLoggers, getConsoleLogLevel from . import permissions tried_shutdown = False @@ -96,8 +96,8 @@ def _rehash(): for filename, config in files.items(): makeFileLogger(filename, config.get('loglevel')) - log.debug('rehash: updating STDOUT log level') - world.stdout_handler.setLevel(stdoutLogLevel()) + log.debug('rehash: updating console log level') + world.console_handler.setLevel(getConsoleLogLevel()) # Reset permissions. log.debug('rehash: resetting permissions') diff --git a/example-conf.yml b/example-conf.yml index 5cca36e..603843d 100644 --- a/example-conf.yml +++ b/example-conf.yml @@ -463,10 +463,12 @@ logging: # This configuration block defines targets that PyLink should log commands, # errors, etc., to. - # This sets the level for STDOUT logging, which is always enabled. Valid + # This sets the level for console logging, which is always enabled. Valid # settings include DEBUG, INFO, WARNING, ERROR, and CRITICAL: see # https://docs.python.org/3/library/logging.html#logging-levels for details. - stdout: INFO + # Prior to PyLink 1.2, this option was erroneously named 'log:stdout', even though the actual + # logging output goes to stderr. That option name (log:stdout) is now *deprecated*. + console: INFO channels: # Logs to channels on the specified networks. diff --git a/log.py b/log.py index 90db529..eee8cad 100644 --- a/log.py +++ b/log.py @@ -22,20 +22,21 @@ os.makedirs(logdir, exist_ok=True) _format = '%(asctime)s [%(levelname)s] %(message)s' logformatter = logging.Formatter(_format) -def stdoutLogLevel(): +def getConsoleLogLevel(): """ - Returns the configured STDOUT log level. + Returns the configured console log level. """ - return conf.conf['logging'].get('stdout') or 'INFO' + logconf = conf.conf['logging'] + return logconf.get('console', logconf.get('stdout')) or 'INFO' # Set up logging to STDERR -world.stdout_handler = logging.StreamHandler() -world.stdout_handler.setFormatter(logformatter) -world.stdout_handler.setLevel(stdoutLogLevel()) +world.console_handler = logging.StreamHandler() +world.console_handler.setFormatter(logformatter) +world.console_handler.setLevel(getConsoleLogLevel()) # Get the main logger object; plugins can import this variable for convenience. log = logging.getLogger() -log.addHandler(world.stdout_handler) +log.addHandler(world.console_handler) # This is confusing, but we have to set the root logger to accept all events. Only this way # can other loggers filter out events on their own, instead of having everything dropped by @@ -62,8 +63,8 @@ def makeFileLogger(filename, level=None): filelogger = logging.handlers.RotatingFileHandler(target, maxBytes=maxbytes, backupCount=backups) filelogger.setFormatter(logformatter) - # If no log level is specified, use the same one as STDOUT. - level = level or stdout_level + # If no log level is specified, use the same one as the console logger. + level = level or getConsoleLogLevel() filelogger.setLevel(level) log.addHandler(filelogger) diff --git a/plugins/commands.py b/plugins/commands.py index 377c809..c358e8e 100644 --- a/plugins/commands.py +++ b/plugins/commands.py @@ -209,10 +209,10 @@ def loglevel(irc, source, args): irc.error('Unknown log level "%s".' % level) return else: - world.stdout_handler.setLevel(loglevel) + world.console_handler.setLevel(loglevel) irc.reply("Done.") except IndexError: - irc.reply(world.stdout_handler.level) + irc.reply(world.console_handler.level) @utils.add_cmd def mkpasswd(irc, source, args):