mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-25 04:02:45 +01:00
core: queue messages for logging when 'log' isn't available during init
Closes #428.
This commit is contained in:
parent
7892e37bfa
commit
a8c1a46e3d
25
conf.py
25
conf.py
@ -12,6 +12,7 @@ except ImportError:
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os.path
|
import os.path
|
||||||
|
import logging
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from . import world
|
from . import world
|
||||||
@ -53,6 +54,12 @@ def validate(condition, errmsg):
|
|||||||
if not condition:
|
if not condition:
|
||||||
raise ConfigValidationError(errmsg)
|
raise ConfigValidationError(errmsg)
|
||||||
|
|
||||||
|
def _log(level, text, *args, logger=None, **kwargs):
|
||||||
|
if logger:
|
||||||
|
logger.log(level, text, *args, **kwargs)
|
||||||
|
else:
|
||||||
|
world.log_queue.append((level, text))
|
||||||
|
|
||||||
def validateConf(conf, logger=None):
|
def validateConf(conf, logger=None):
|
||||||
"""Validates a parsed configuration dict."""
|
"""Validates a parsed configuration dict."""
|
||||||
validate(type(conf) == dict,
|
validate(type(conf) == dict,
|
||||||
@ -60,14 +67,8 @@ def validateConf(conf, logger=None):
|
|||||||
% type(conf).__name__)
|
% type(conf).__name__)
|
||||||
|
|
||||||
if 'pylink' in conf and 'bot' in conf:
|
if 'pylink' in conf and 'bot' in conf:
|
||||||
e = ("Since PyLink 1.2, the 'pylink:' and 'bot:' configuration sections have been condensed "
|
_log(logging.WARNING, "Since PyLink 1.2, the 'pylink:' and 'bot:' configuration sections have been condensed "
|
||||||
"into one. You should merge any options under these sections into one 'pylink:' block.")
|
"into one. You should merge any options under these sections into one 'pylink:' block.")
|
||||||
if logger:
|
|
||||||
logger.warning(e)
|
|
||||||
else:
|
|
||||||
# FIXME: we need a better fallback when log isn't available on first
|
|
||||||
# start.
|
|
||||||
print('WARNING: %s' % e)
|
|
||||||
|
|
||||||
new_block = conf['bot'].copy()
|
new_block = conf['bot'].copy()
|
||||||
new_block.update(conf['pylink'])
|
new_block.update(conf['pylink'])
|
||||||
@ -84,14 +85,8 @@ def validateConf(conf, logger=None):
|
|||||||
# Make sure at least one form of authentication is valid.
|
# Make sure at least one form of authentication is valid.
|
||||||
# Also we'll warn them that login:user/login:password is deprecated
|
# Also we'll warn them that login:user/login:password is deprecated
|
||||||
if conf['login'].get('password') or conf['login'].get('user'):
|
if conf['login'].get('password') or conf['login'].get('user'):
|
||||||
e = "The 'login:user' and 'login:password' options are deprecated since PyLink 1.1. " \
|
_log(logging.WARNING, "The 'login:user' and 'login:password' options are deprecated since PyLink 1.1. "
|
||||||
"Please switch to the new 'login:accounts' format as outlined in the example config."
|
"Please switch to the new 'login:accounts' format as outlined in the example config.")
|
||||||
if logger:
|
|
||||||
logger.warning(e)
|
|
||||||
else:
|
|
||||||
# FIXME: we need a better fallback when log isn't available on first
|
|
||||||
# start.
|
|
||||||
print('WARNING: %s' % e)
|
|
||||||
|
|
||||||
old_login_valid = type(conf['login'].get('password')) == type(conf['login'].get('user')) == str
|
old_login_valid = type(conf['login'].get('password')) == type(conf['login'].get('user')) == str
|
||||||
newlogins = conf['login'].get('accounts', {})
|
newlogins = conf['login'].get('accounts', {})
|
||||||
|
7
log.py
7
log.py
@ -42,6 +42,13 @@ log.addHandler(world.stdout_handler)
|
|||||||
# the root logger. https://stackoverflow.com/questions/16624695
|
# the root logger. https://stackoverflow.com/questions/16624695
|
||||||
log.setLevel(1)
|
log.setLevel(1)
|
||||||
|
|
||||||
|
log.debug("log: Emptying log_queue")
|
||||||
|
# Process and empty the log queue
|
||||||
|
while world.log_queue:
|
||||||
|
level, text = world.log_queue.popleft()
|
||||||
|
log.log(level, text)
|
||||||
|
log.debug("log: Emptied log_queue")
|
||||||
|
|
||||||
def makeFileLogger(filename, level=None):
|
def makeFileLogger(filename, level=None):
|
||||||
"""
|
"""
|
||||||
Initializes a file logging target with the given filename and level.
|
Initializes a file logging target with the given filename and level.
|
||||||
|
6
world.py
6
world.py
@ -2,7 +2,7 @@
|
|||||||
world.py: Stores global variables for PyLink, including lists of active IRC objects and plugins.
|
world.py: Stores global variables for PyLink, including lists of active IRC objects and plugins.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict, deque
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -29,3 +29,7 @@ source = "https://github.com/GLolol/PyLink" # CHANGE THIS IF YOU'RE FORKING!!
|
|||||||
|
|
||||||
# Fallback hostname used in various places internally when hostname isn't configured.
|
# Fallback hostname used in various places internally when hostname isn't configured.
|
||||||
fallback_hostname = 'pylink.int'
|
fallback_hostname = 'pylink.int'
|
||||||
|
|
||||||
|
# Defines messages to be logged as soon as the log system is set up, for modules like conf that are
|
||||||
|
# initialized before log. This is processed (and then not used again) when the log module loads.
|
||||||
|
log_queue = deque()
|
||||||
|
Loading…
Reference in New Issue
Block a user