From 1a824e4c2e81898acec6df800718d387d830e26b Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 13 Jan 2004 18:03:01 +0000 Subject: [PATCH] Added loglevel RFE. --- src/Admin.py | 15 +++++++++++++++ src/log.py | 8 +++++--- src/privmsgs.py | 2 ++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Admin.py b/src/Admin.py index 3e858f3c1..9178d059e 100755 --- a/src/Admin.py +++ b/src/Admin.py @@ -41,10 +41,12 @@ import fix import time import pprint import string +import logging import smtplib import textwrap from itertools import imap +import log import conf import ircdb import utils @@ -369,6 +371,19 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg): irc.replySuccess() reportbug = privmsgs.thread(reportbug) + def loglevel(self, irc, msg, args): + """{DEBUG,INFO,WARNING,ERROR,CRITICAL} + + Sets the logging level of the bot's logs. + """ + level = privmsgs.getArgs(args) + try: + level = getattr(logging, level.upper()) + except AttributeError: + raise callbacks.ArgumentError + log.setLevel(level) + irc.replySuccess() + Class = Admin diff --git a/src/log.py b/src/log.py index 9ccd36fbb..45bcc4791 100644 --- a/src/log.py +++ b/src/log.py @@ -150,16 +150,16 @@ pluginFormatter = Formatter('%(levelname)s %(asctime)s %(name)s %(message)s') _logger = logging.getLogger('supybot') _handler = BetterFileHandler(os.path.join(conf.logDir, 'misc.log')) _handler.setFormatter(formatter) -_handler.setLevel(conf.minimumLogPriority) +_handler.setLevel(-1) _logger.addHandler(_handler) -_logger.setLevel(-1) +_logger.setLevel(conf.minimumLogPriority) if conf.stdoutLogging: _stdoutHandler = BetterStreamHandler(sys.stdout) _formatString = '%(name)s: %(levelname)s %(message)s' _stdoutFormatter = ColorizedFormatter(_formatString) _stdoutHandler.setFormatter(_stdoutFormatter) - _stdoutHandler.setLevel(conf.minimumLogPriority) + _stdoutHandler.setLevel(-1) _logger.addHandler(_stdoutHandler) debug = _logger.debug @@ -169,6 +169,8 @@ error = _logger.error critical = _logger.critical exception = _logger.exception +setLevel = _logger.setLevel + atexit.register(logging.shutdown) def getPluginLogger(name): diff --git a/src/privmsgs.py b/src/privmsgs.py index 0ac32de86..1f73b9c95 100644 --- a/src/privmsgs.py +++ b/src/privmsgs.py @@ -44,6 +44,7 @@ import threading import conf import ircdb import world +import ircmsgs import ircutils import callbacks import structures @@ -78,6 +79,7 @@ def getArgs(args, required=1, optional=0): let the caller handle sending the help message. """ assert not isinstance(args, str), 'args should be a list.' + assert not isinstance(args, ircmsgs.IrcMsg), 'args should be a list.' if len(args) < required: raise callbacks.ArgumentError if len(args) < required + optional: