From 44e10984304ffae2f092494257aa759d270d24e5 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 5 Aug 2004 05:40:32 +0000 Subject: [PATCH] Added optional line wrapping to logs. --- ChangeLog | 3 +++ src/log.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index 4727320c1..07a3b3da7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ + * Added supybot.log.stdout.wrap, to allow optional (defaulting to + True) wrapping of stdout logs. + * Added supybot.databases.plugins.channelSpecific, a channel value that determines whether the database used for channel-based plugins will be a channel-specific database or a global database. diff --git a/src/log.py b/src/log.py index 6b3a1b946..ee05108c5 100644 --- a/src/log.py +++ b/src/log.py @@ -40,6 +40,7 @@ import types import atexit import logging import operator +import textwrap import traceback import supybot.ansi as ansi @@ -85,6 +86,15 @@ class StdoutStreamHandler(logging.StreamHandler): finally: logging._releaseLock() + def format(self, record): + s = logging.StreamHandler.format(self, record) + if record.levelname != 'ERROR' and conf.supybot.log.stdout.wrap(): + # We check for ERROR there because otherwise, tracebacks (which are + # already wrapped by Python itself) wrap oddly. + prefixLen = len(record.name) + 2 # ": " + s = textwrap.fill(s, width=78, subsequent_indent=' '*prefixLen) + return s + def emit(self, record): if conf.supybot.log.stdout() and not conf.daemonized: try: @@ -279,6 +289,10 @@ conf.registerGlobalValue(conf.supybot.log.stdout, 'colorized', BooleanRequiredFalseOnWindows(False, """Determines whether the bot's logs to stdout (if enabled) will be colorized with ANSI color.""")) +conf.registerGlobalValue(conf.supybot.log.stdout, 'wrap', + registry.Boolean(True, """Determines whether the bot will wrap its logs + when they're output to stdout.""")) + conf.registerGlobalValue(conf.supybot.log, 'timestampFormat', registry.String('[%d-%b-%Y %H:%M:%S]', """Determines the format string for timestamps in logfiles. Refer to the Python documentation for the time