Revert "Remove logbook and replace it with logging".

This reverts the commit range f367c38..978ba2d.

Issue #121 is currently blocking the 0.3.1 release.
main
Vincent Driessen 12 years ago
parent a6e57dd7c0
commit 1ab8c19696

@ -17,8 +17,6 @@
makes it possible to distinguish between a job that explicitly returned makes it possible to distinguish between a job that explicitly returned
`None` and a job that isn't finished yet (see `status` property). `None` and a job that isn't finished yet (see `status` property).
- Remove `logbook` dependency (in favor of `logging`)
- Custom exception handlers can now be configured in addition to, or to fully - Custom exception handlers can now be configured in addition to, or to fully
replace, moving failed jobs to the failed queue. Relevant documentation replace, moving failed jobs to the failed queue. Relevant documentation
[here](http://python-rq.org/docs/exceptions/) and [here](http://python-rq.org/docs/exceptions/) and

@ -1,3 +1,4 @@
redis redis
times times
logbook
argparse argparse

@ -1,44 +1,42 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys import sys
import argparse import argparse
import logging import logbook
import logging.config from logbook import handlers
from rq import Queue, Worker from rq import Queue, Worker
from redis.exceptions import ConnectionError from redis.exceptions import ConnectionError
from rq.scripts import add_standard_arguments from rq.scripts import add_standard_arguments
from rq.scripts import setup_redis from rq.scripts import setup_redis
logger = logging.getLogger(__name__)
def format_colors(record, handler):
from rq.utils import make_colorizer
if record.level == logbook.WARNING:
colorize = make_colorizer('darkyellow')
elif record.level >= logbook.ERROR:
colorize = make_colorizer('darkred')
else:
colorize = lambda x: x
return '%s: %s' % (record.time.strftime('%H:%M:%S'), colorize(record.msg))
def setup_loghandlers(args): def setup_loghandlers(args):
logging.config.dictConfig({ if args.verbose:
"version": 1, loglevel = logbook.DEBUG
"disable_existing_loggers": False, formatter = None
else:
"formatters": { loglevel = logbook.INFO
"console": { formatter = format_colors
"format": "%(asctime)s %(message)s",
"datefmt": "%H:%M:%S", handlers.NullHandler(bubble=False).push_application()
}, handler = handlers.StreamHandler(sys.stdout, level=loglevel, bubble=False)
}, if formatter:
handler.formatter = formatter
"handlers": { handler.push_application()
"console": { handler = handlers.StderrHandler(level=logbook.WARNING, bubble=False)
"level": "DEBUG", if formatter:
#"class": "logging.StreamHandler", handler.formatter = formatter
"class": "rq.utils.ColorizingStreamHandler", handler.push_application()
"formatter": "console",
"exclude": ["%(asctime)s"],
},
},
"root": {
"handlers": ["console"],
"level": "DEBUG" if args.verbose else "INFO"
}
})
def parse_args(): def parse_args():
@ -83,7 +81,6 @@ def main():
setup_loghandlers(args) setup_loghandlers(args)
setup_redis(args) setup_redis(args)
try: try:
queues = map(Queue, args.queues) queues = map(Queue, args.queues)
w = Worker(queues, name=args.name) w = Worker(queues, name=args.name)

@ -5,7 +5,6 @@ Miscellaneous helper functions.
The formatter for ANSI colored console output is heavily based on Pygments The formatter for ANSI colored console output is heavily based on Pygments
terminal colorizing code, originally by Georg Brandl. terminal colorizing code, originally by Georg Brandl.
""" """
import logging
import os import os
@ -116,34 +115,3 @@ def make_colorizer(color):
def inner(text): def inner(text):
return colorizer.colorize(color, text) return colorizer.colorize(color, text)
return inner return inner
class ColorizingStreamHandler(logging.StreamHandler):
levels = {
logging.WARNING: make_colorizer('darkyellow'),
logging.ERROR: make_colorizer('darkred'),
logging.CRITICAL: make_colorizer('darkred'),
}
def __init__(self, exclude=None, *args, **kwargs):
self.exclude = exclude
super(ColorizingStreamHandler, self).__init__(*args, **kwargs)
@property
def is_tty(self):
isatty = getattr(self.stream, 'isatty', None)
return isatty and isatty()
def format(self, record):
message = logging.StreamHandler.format(self, record)
if self.is_tty:
colorize = self.levels.get(record.levelno, lambda x: x)
# Don't colorize any traceback
parts = message.split('\n', 1)
parts[0] = " ".join([parts[0].split(" ", 1)[0], colorize(parts[0].split(" ", 1)[1])])
message = '\n'.join(parts)
return message

@ -11,8 +11,12 @@ except ImportError:
import socket import socket
import signal import signal
import traceback import traceback
import logging
from cPickle import dumps from cPickle import dumps
try:
from logbook import Logger
Logger = Logger # Does nothing except it shuts up pyflakes annoying error
except ImportError:
from logging import Logger
from .queue import Queue, get_failed_queue from .queue import Queue, get_failed_queue
from .connections import get_current_connection from .connections import get_current_connection
from .job import Status from .job import Status
@ -25,8 +29,6 @@ green = make_colorizer('darkgreen')
yellow = make_colorizer('darkyellow') yellow = make_colorizer('darkyellow')
blue = make_colorizer('darkblue') blue = make_colorizer('darkblue')
logger = logging.getLogger(__name__)
class StopRequested(Exception): class StopRequested(Exception):
pass pass
@ -110,7 +112,7 @@ class Worker(object):
self._is_horse = False self._is_horse = False
self._horse_pid = 0 self._horse_pid = 0
self._stopped = False self._stopped = False
self.log = logger self.log = Logger('worker')
self.failed_queue = get_failed_queue(connection=self.connection) self.failed_queue = get_failed_queue(connection=self.connection)
# By default, push the "move-to-failed-queue" exception handler onto # By default, push the "move-to-failed-queue" exception handler onto
@ -370,7 +372,7 @@ class Worker(object):
signal.signal(signal.SIGTERM, signal.SIG_DFL) signal.signal(signal.SIGTERM, signal.SIG_DFL)
self._is_horse = True self._is_horse = True
self.log = logger self.log = Logger('horse')
success = self.perform_job(job) success = self.perform_job(job)

@ -1,2 +1,2 @@
[bdist_rpm] [bdist_rpm]
requires = redis procname requires = redis procname logbook

@ -18,6 +18,7 @@ def get_version():
def get_dependencies(): def get_dependencies():
deps = ['redis >= 2.4.0', 'times'] deps = ['redis >= 2.4.0', 'times']
deps += ['logbook'] # should be soft dependency?
if sys.version_info < (2, 7) or \ if sys.version_info < (2, 7) or \
(sys.version_info >= (3, 0) and sys.version_info < (3, 1)): (sys.version_info >= (3, 0) and sys.version_info < (3, 1)):
deps += ['importlib'] deps += ['importlib']

@ -1,7 +1,6 @@
import logging
import unittest import unittest
from redis import Redis from redis import Redis
from logbook import NullHandler
from rq import push_connection, pop_connection from rq import push_connection, pop_connection
@ -48,8 +47,9 @@ class RQTestCase(unittest.TestCase):
# Store the connection (for sanity checking) # Store the connection (for sanity checking)
cls.testconn = testconn cls.testconn = testconn
# Shut up logging # Shut up logbook
logging.disable("ERROR") cls.log_handler = NullHandler()
cls.log_handler.push_thread()
def setUp(self): def setUp(self):
# Flush beforewards (we like our hygiene) # Flush beforewards (we like our hygiene)
@ -66,7 +66,7 @@ class RQTestCase(unittest.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
logging.disable(logging.NOTSET) cls.log_handler.pop_thread()
# Pop the connection to Redis # Pop the connection to Redis
testconn = pop_connection() testconn = pop_connection()

Loading…
Cancel
Save