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):
|
class App(object):
|
||||||
def __init__(self, server=None, palette='default', keymap='default',
|
def __init__(self, server=None, palette='default', keymap='default',
|
||||||
debug=False, disable_sync=False, fetch_missing_refs=False,
|
debug=False, verbose=False, disable_sync=False,
|
||||||
path=config.DEFAULT_CONFIG_PATH):
|
fetch_missing_refs=False, path=config.DEFAULT_CONFIG_PATH):
|
||||||
self.server = server
|
self.server = server
|
||||||
self.config = config.Config(server, palette, keymap, path)
|
self.config = config.Config(server, palette, keymap, path)
|
||||||
if debug:
|
if debug:
|
||||||
level = logging.DEBUG
|
level = logging.DEBUG
|
||||||
|
elif verbose:
|
||||||
|
level = logging.INFO
|
||||||
else:
|
else:
|
||||||
level = logging.WARNING
|
level = logging.WARNING
|
||||||
logging.basicConfig(filename=self.config.log_file, filemode='w',
|
logging.basicConfig(filename=self.config.log_file, filemode='w',
|
||||||
format='%(asctime)s %(message)s',
|
format='%(asctime)s %(message)s',
|
||||||
level=level)
|
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 = logging.getLogger('gertty.App')
|
||||||
self.log.debug("Starting")
|
self.log.debug("Starting")
|
||||||
|
|
||||||
@ -422,6 +435,8 @@ def main():
|
|||||||
parser.add_argument('-c', dest='path',
|
parser.add_argument('-c', dest='path',
|
||||||
default=config.DEFAULT_CONFIG_PATH,
|
default=config.DEFAULT_CONFIG_PATH,
|
||||||
help='path to config file')
|
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',
|
parser.add_argument('-d', dest='debug', action='store_true',
|
||||||
help='enable debug logging')
|
help='enable debug logging')
|
||||||
parser.add_argument('--no-sync', dest='no_sync', action='store_true',
|
parser.add_argument('--no-sync', dest='no_sync', action='store_true',
|
||||||
@ -443,8 +458,8 @@ def main():
|
|||||||
parser.add_argument('server', nargs='?',
|
parser.add_argument('server', nargs='?',
|
||||||
help='the server to use (as specified in config file)')
|
help='the server to use (as specified in config file)')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
g = App(args.server, args.palette, args.keymap, args.debug, args.no_sync,
|
g = App(args.server, args.palette, args.keymap, args.debug, args.verbose,
|
||||||
args.fetch_missing_refs, args.path)
|
args.no_sync, args.fetch_missing_refs, args.path)
|
||||||
g.run()
|
g.run()
|
||||||
|
|
||||||
|
|
||||||
|
@ -947,9 +947,15 @@ class Sync(object):
|
|||||||
headers = {'Accept': 'application/json',
|
headers = {'Accept': 'application/json',
|
||||||
'Accept-Encoding': 'gzip',
|
'Accept-Encoding': 'gzip',
|
||||||
'User-Agent': self.user_agent})
|
'User-Agent': self.user_agent})
|
||||||
self.log.debug('Received: %s' % (r.text,))
|
if r.status_code == 200:
|
||||||
ret = json.loads(r.text[4:])
|
ret = json.loads(r.text[4:])
|
||||||
return ret
|
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):
|
def post(self, path, data):
|
||||||
url = self.url(path)
|
url = self.url(path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user