mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-23 18:54:05 +01:00
parent
caade5a308
commit
60a0bcdc7a
5
conf.py
5
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
|
||||
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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.
|
||||
|
19
log.py
19
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)
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user