Commit 653b0597 authored by Giorgos Verigakis's avatar Giorgos Verigakis
Browse files

Improve logging

Do not use the root logger.

Refs #1337
parent 6d604f07
......@@ -39,6 +39,9 @@ from httplib import HTTPConnection, HTTPSConnection
from urlparse import urlparse
log = logging.getLogger('kamaki.client')
class ClientError(Exception):
def __init__(self, message, status=0, details=''):
self.message = message
......@@ -77,24 +80,24 @@ class Client(object):
headers['Content-Type'] = 'application/json'
headers['Content-Length'] = len(body)
logging.debug('%s', '>' * 40)
logging.debug('%s %s', method, path)
log.debug('%s', '>' * 40)
log.debug('%s %s', method, path)
for key, val in headers.items():
logging.debug('%s: %s', key, val)
logging.debug('')
log.debug('%s: %s', key, val)
log.debug('')
if body:
logging.debug(body)
logging.debug('')
log.debug(body)
log.debug('')
conn.request(method, path, body, headers)
resp = conn.getresponse()
logging.debug('%s', '<' * 40)
logging.info('%d %s', resp.status, resp.reason)
log.debug('%s', '<' * 40)
log.info('%d %s', resp.status, resp.reason)
for key, val in resp.getheaders():
logging.info('%s: %s', key.capitalize(), val)
logging.info('')
log.info('%s: %s', key.capitalize(), val)
log.info('')
buf = resp.read()
try:
......
......@@ -50,6 +50,9 @@ TOKEN_ENV = 'KAMAKI_TOKEN'
RCFILE = '.kamakirc'
log = logging.getLogger('kamaki')
def print_addresses(addresses, margin):
for address in addresses:
if address['id'] == 'public':
......@@ -156,20 +159,13 @@ class Command(object):
self.parser = parser
def _init_logging(self):
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter('%(message)s'))
logger = logging.getLogger()
logger.addHandler(ch)
if self.debug:
level = logging.DEBUG
log.setLevel(logging.DEBUG)
elif self.verbose:
level = logging.INFO
log.setLevel(logging.INFO)
else:
level = logging.WARNING
log.setLevel(logging.WARNING)
logger.setLevel(level)
def _init_conf(self):
if not self.api:
self.api = os.environ.get(API_ENV, None)
......@@ -258,10 +254,10 @@ class CreateServer(Command):
for p in self.personality:
lpath, sep, rpath = p.partition(',')
if not lpath or not rpath:
logging.error("Invalid personality argument '%s'", p)
log.error("Invalid personality argument '%s'", p)
return
if not os.path.exists(lpath):
logging.error("File %s does not exist", lpath)
log.error("File %s does not exist", lpath)
return
with open(lpath) as f:
personality.append((rpath, f.read()))
......@@ -663,9 +659,13 @@ def main():
cmd = cls(argv)
cmd.execute()
except ClientError, err:
logging.error('%s', err.message)
logging.info('%s', err.details)
log.error('%s', err.message)
log.info('%s', err.details)
if __name__ == '__main__':
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter('%(message)s'))
log.addHandler(ch)
main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment