From: Josh Roesslein Date: Mon, 12 Oct 2009 05:56:36 +0000 (-0500) Subject: Remove logging system. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=81c47a480287f907d04665fe57fd7d13e62661ac;p=tweepy.git Remove logging system. --- diff --git a/CHANGES b/CHANGES index a930be1..570e395 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,9 @@ during upgrade will be listed here. Added the Cursor object to help with pagination within the API. Please see the pagination tutorial for more details. This is the recommended way for using the 'page' and 'cursor' parameters. +- Logging removed. Having our own mini-logging system just feels like overkill. + Turns out it was not really needed that much. Simply just exposing the last + HTTPResponse object should be good enough for most debugging. 1.0.1 -> 1.1 ======================= diff --git a/tweepy/__init__.py b/tweepy/__init__.py index dfd35b8..3a84522 100644 --- a/tweepy/__init__.py +++ b/tweepy/__init__.py @@ -13,7 +13,6 @@ from . api import API from . cache import Cache, MemoryCache, FileCache, MemCache from . auth import BasicAuthHandler, OAuthHandler from . streaming import Stream, StreamListener -from . logging import TweepyLogger, DummyLogger, ConsoleLogger, FileLogger from . cursor import Cursor # Global, unauthenticated instance of API diff --git a/tweepy/api.py b/tweepy/api.py index 4ebfcd3..591b88c 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -8,7 +8,6 @@ import mimetypes from . binder import bind_api from . error import TweepError from . auth import BasicAuthHandler, OAuthHandler -from . logging import DummyLogger from tweepy.parsers import * @@ -16,7 +15,7 @@ class API(object): """Twitter API""" def __init__(self, auth_handler=None, host='twitter.com', cache=None, - secure=False, api_root='', validate=True, logger=DummyLogger()): + secure=False, api_root='', validate=True): # you may access these freely self.auth_handler = auth_handler self.host = host @@ -24,7 +23,6 @@ class API(object): self.cache = cache self.secure = secure self.validate = validate - self.logger = logger # not a good idea to touch these self._username = None diff --git a/tweepy/binder.py b/tweepy/binder.py index 7a29f5b..bf00139 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -29,16 +29,10 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False, if require_auth and not api.auth_handler: raise TweepError('Authentication required!') - # Log some useful infomation - api.logger.debug('Starting request...') - api.logger.debug(' path: %s' % path) - api.logger.debug(' method: %s' % method) - # check for post_data parameter if 'post_data' in kargs: post_data = kargs['post_data'] del kargs['post_data'] - api.logger.debug(' post data: %s' % post_data) else: post_data = None @@ -60,7 +54,6 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False, del kargs['headers'] else: headers = {} - api.logger.debug(' headers: %s' % headers) # build parameter dict if allowed_param: @@ -82,7 +75,6 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False, if len(args) > 0 or len(kargs) > 0: raise TweepError('This method takes no parameters!') parameters = None - api.logger.debug(' parameters: %s' % parameters) # Build url with parameters if parameters: @@ -101,7 +93,6 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False, result._api = api else: cache_result._api = api - api.logger.debug("Cache hit!") return cache_result # get scheme and host @@ -134,9 +125,6 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False, # Get response resp = conn.getresponse() - api.logger.debug('Received response...') - api.logger.debug(' headers: %s' % resp.getheaders()) - api.logger.debug(' status code: %s' % resp.status) # If request was successful, quit the loop if resp.status == 200: @@ -153,7 +141,6 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False, error_msg = parse_error(resp.read()) except Exception: error_msg = "Twitter error response: status code = %s" % resp.status - api.logger.error(' Error: %s' % error_msg) raise TweepError(error_msg) # Parse json respone body @@ -196,9 +183,6 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False, # store result in cache if api.cache and method == 'GET': api.cache.store(url, out) - api.logger.debug(" caching result") - - api.logger.debug('request done.') return out diff --git a/tweepy/logging.py b/tweepy/logging.py deleted file mode 100644 index dc57c6f..0000000 --- a/tweepy/logging.py +++ /dev/null @@ -1,58 +0,0 @@ -# Tweepy -# Copyright 2009 Joshua Roesslein -# See LICENSE - -class TweepyLogger(object): - - DEBUG = 1 - WARNING = 2 - ERROR = 3 - - def debug(self, message): - """Output a debug log message""" - self.log(TweepyLogger.DEBUG, message) - - def warning(self, message): - """Output warning log message""" - self.log(TweepyLogger.WARNING, message) - - def error(self, message): - """Output error log message""" - self.log(TweepyLogger.ERROR, message) - - def log(self, level, message): - """Implement this method to handle log messages""" - raise NotImplementedError - - def format(self, message): - """Override this method to apply custom formating of messages""" - return message - -class DummyLogger(TweepyLogger): - """This logger just discards log messages""" - - def log(self, level, message): - return - -class ConsoleLogger(TweepyLogger): - """Outputs log messages to stdout""" - - def __init__(self, active_log_level=TweepyLogger.DEBUG): - self.active_log_level = active_log_level - - def log(self, level, message): - if level <= self.active_log_level: - print message - -class FileLogger(TweepyLogger): - """Outputs log message to file""" - - def __init__(self, filepath, active_log_level=TweepyLogger.DEBUG): - self.active_log_level = active_log_level - self.file = open(filepath, 'w') - - def log(self, level, message): - if level <= self.active_log_level: - self.file.write(message + '\n') - self.file.flush() -