From a4b19f66cbe8e98bcefcc83451e32aa32fb5a54c Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 5 Sep 2012 16:36:27 -0400 Subject: [PATCH] Removes unused, deprecated `logger` module. --- tests/test_logger.py | 59 ----------------------------------------- zipline/utils/logger.py | 52 ------------------------------------ 2 files changed, 111 deletions(-) delete mode 100644 tests/test_logger.py delete mode 100644 zipline/utils/logger.py diff --git a/tests/test_logger.py b/tests/test_logger.py deleted file mode 100644 index 7a2ae780..00000000 --- a/tests/test_logger.py +++ /dev/null @@ -1,59 +0,0 @@ -import logging -import logbook -import uuid -import zmq - -from zipline import ndict - -from zipline.utils.logger import configure_logging, tail -from zipline.utils.log_utils import ZeroMQLogHandler - -from zipline.utils.test_utils import create_receiver, drain_receiver - -from unittest2 import TestCase - - -class LoggerTestCase(TestCase): - - def setUp(self): - configure_logging() - self.LOG = logging.getLogger("ZiplineLogger") - - def test_log(self): - test_msg = uuid.uuid1().hex - self.LOG.info(test_msg) - logfile = open('/var/log/zipline/zipline.log', 'r') - with logfile: - last_line = tail(logfile, window=1) - logged_msg = last_line.split(" - ")[1] - self.assertEqual(test_msg, logged_msg) - - def test_zmq_handler(self): - socket_addr = 'tcp://127.0.0.1:10000' - ctx = zmq.Context() - socket_push = ctx.socket(zmq.PUSH) - socket_push.connect(socket_addr) - recv = create_receiver(socket_addr, ctx) - zmq_out = ZeroMQLogHandler( - socket=socket_push, - filter=lambda r, h: r.channel in ['test zmq logger'], - context=ctx, - #bubble=False - ) - - log = logbook.Logger('test zmq logger') - x = ndict({}) - x.a = 1 - ex = example(133) - with zmq_out.threadbound(): - log.info(ex.num) - - output, _ = drain_receiver(recv, count=1) - self.assertEqual(output[-1]['prefix'], 'LOG') - self.assertTrue(isinstance(output[-1]['payload']['msg'], basestring)) - - -class example(object): - - def __init__(self, num): - self.num = num diff --git a/zipline/utils/logger.py b/zipline/utils/logger.py deleted file mode 100644 index b044642f..00000000 --- a/zipline/utils/logger.py +++ /dev/null @@ -1,52 +0,0 @@ -""" -Small classes to assist with timezone calculations, LOGGER configuration, -and other common operations. -""" - -# DEPRECATED DO NOT USE - -import logging -import logging.config -from os.path import join, abspath, dirname - -def configure_logging(): - logging.config.fileConfig( - logger_path(), - disable_existing_loggers = False - ) - -def logger_path(): - import zipline - log_path = dirname(abspath(zipline.__file__)) - return join(log_path, 'logging.cfg') - - -# utility for tailing a log file. -def tail( f, window=20 ): - """ - from - http://stackoverflow.com/questions/136168/get-last-n-lines-of-a-file- \ - with-python-similar-to-tail - """ - BUFSIZ = 1024 - f.seek(0, 2) - bytes = f.tell() - size = window - block = -1 - data = [] - while size > 0 and bytes > 0: - if (bytes - BUFSIZ > 0): - # Seek back one whole BUFSIZ - f.seek(block*BUFSIZ, 2) - # read BUFFER - data.append(f.read(BUFSIZ)) - else: - # file too small, start from begining - f.seek(0,0) - # only read what was not read - data.append(f.read(bytes)) - linesFound = data[-1].count('\n') - size -= linesFound - bytes -= BUFSIZ - block -= 1 - return '\n'.join(''.join(data).splitlines()[-window:])