Add INFO log level potential with --verbose flag
Simply adds a new -v/--verbose CLI option which configures logging at the INFO log level. Also changes the debug logging in sync.get() to log a non-200 HTTP return code, which fixes the Storyboard story 2000084, where a ValueError was being raised by trying to JSON-decode a non-200 response body. Change-Id: Ieabc606e0570ddf3d3af67bb926cad79b0e87591 Closes-story: 2000084
This commit is contained in:
parent
259008cea5
commit
823c587a12
@ -130,17 +130,30 @@ class SearchDialog(mywid.ButtonDialog):
|
||||
|
||||
class App(object):
|
||||
def __init__(self, server=None, palette='default', keymap='default',
|
||||
debug=False, disable_sync=False, fetch_missing_refs=False,
|
||||
path=config.DEFAULT_CONFIG_PATH):
|
||||
debug=False, verbose=False, disable_sync=False,
|
||||
fetch_missing_refs=False, path=config.DEFAULT_CONFIG_PATH):
|
||||
self.server = server
|
||||
self.config = config.Config(server, palette, keymap, path)
|
||||
if debug:
|
||||
level = logging.DEBUG
|
||||
elif verbose:
|
||||
level = logging.INFO
|
||||
else:
|
||||
level = logging.WARNING
|
||||
logging.basicConfig(filename=self.config.log_file, filemode='w',
|
||||
format='%(asctime)s %(message)s',
|
||||
level=level)
|
||||
# Python2.6 Logger.setLevel doesn't convert string name
|
||||
# to integer code. Here, we set the requests logger level to
|
||||
# be less verbose, since our logging output duplicates some
|
||||
# requests logging content in places.
|
||||
req_level_name = 'WARN'
|
||||
req_logger = logging.getLogger('requests')
|
||||
if sys.version_info < (2, 7):
|
||||
level = logging.getLevelName(req_level_name)
|
||||
req_logger.setLevel(level)
|
||||
else:
|
||||
req_logger.setLevel(req_level_name)
|
||||
self.log = logging.getLogger('gertty.App')
|
||||
self.log.debug("Starting")
|
||||
|
||||
@ -422,6 +435,8 @@ def main():
|
||||
parser.add_argument('-c', dest='path',
|
||||
default=config.DEFAULT_CONFIG_PATH,
|
||||
help='path to config file')
|
||||
parser.add_argument('-v', dest='verbose', action='store_true',
|
||||
help='enable more verbose logging')
|
||||
parser.add_argument('-d', dest='debug', action='store_true',
|
||||
help='enable debug logging')
|
||||
parser.add_argument('--no-sync', dest='no_sync', action='store_true',
|
||||
@ -443,8 +458,8 @@ def main():
|
||||
parser.add_argument('server', nargs='?',
|
||||
help='the server to use (as specified in config file)')
|
||||
args = parser.parse_args()
|
||||
g = App(args.server, args.palette, args.keymap, args.debug, args.no_sync,
|
||||
args.fetch_missing_refs, args.path)
|
||||
g = App(args.server, args.palette, args.keymap, args.debug, args.verbose,
|
||||
args.no_sync, args.fetch_missing_refs, args.path)
|
||||
g.run()
|
||||
|
||||
|
||||
|
@ -947,9 +947,15 @@ class Sync(object):
|
||||
headers = {'Accept': 'application/json',
|
||||
'Accept-Encoding': 'gzip',
|
||||
'User-Agent': self.user_agent})
|
||||
self.log.debug('Received: %s' % (r.text,))
|
||||
ret = json.loads(r.text[4:])
|
||||
return ret
|
||||
if r.status_code == 200:
|
||||
ret = json.loads(r.text[4:])
|
||||
if len(ret):
|
||||
self.log.debug('200 OK, Received: %s' % (ret,))
|
||||
else:
|
||||
self.log.debug('200 OK, No body.')
|
||||
return ret
|
||||
else:
|
||||
self.log.warn('HTTP response: %d', r.status_code)
|
||||
|
||||
def post(self, path, data):
|
||||
url = self.url(path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user