Revision 653b0597

b/kamaki/client.py
39 39
from urlparse import urlparse
40 40

  
41 41

  
42
log = logging.getLogger('kamaki.client')
43

  
44

  
42 45
class ClientError(Exception):
43 46
    def __init__(self, message, status=0, details=''):
44 47
        self.message = message
......
77 80
            headers['Content-Type'] = 'application/json'
78 81
            headers['Content-Length'] = len(body)
79 82
        
80
        logging.debug('%s', '>' * 40)
81
        logging.debug('%s %s', method, path)
83
        log.debug('%s', '>' * 40)
84
        log.debug('%s %s', method, path)
82 85

  
83 86
        for key, val in headers.items():
84
            logging.debug('%s: %s', key, val)
85
        logging.debug('')
87
            log.debug('%s: %s', key, val)
88
        log.debug('')
86 89
        if body:
87
            logging.debug(body)
88
            logging.debug('')
90
            log.debug(body)
91
            log.debug('')
89 92
        
90 93
        conn.request(method, path, body, headers)
91 94

  
92 95
        resp = conn.getresponse()
93
        logging.debug('%s', '<' * 40)
94
        logging.info('%d %s', resp.status, resp.reason)
96
        log.debug('%s', '<' * 40)
97
        log.info('%d %s', resp.status, resp.reason)
95 98
        for key, val in resp.getheaders():
96
            logging.info('%s: %s', key.capitalize(), val)
97
        logging.info('')
99
            log.info('%s: %s', key.capitalize(), val)
100
        log.info('')
98 101
        
99 102
        buf = resp.read()
100 103
        try:
b/kamaki/kamaki.py
50 50
RCFILE = '.kamakirc'
51 51

  
52 52

  
53
log = logging.getLogger('kamaki')
54

  
55

  
53 56
def print_addresses(addresses, margin):
54 57
    for address in addresses:
55 58
        if address['id'] == 'public':
......
156 159
        self.parser = parser
157 160
    
158 161
    def _init_logging(self):
159
        ch = logging.StreamHandler()
160
        ch.setFormatter(logging.Formatter('%(message)s'))
161
        logger = logging.getLogger()
162
        logger.addHandler(ch)
163
        
164 162
        if self.debug:
165
            level = logging.DEBUG
163
            log.setLevel(logging.DEBUG)
166 164
        elif self.verbose:
167
            level = logging.INFO
165
            log.setLevel(logging.INFO)
168 166
        else:
169
            level = logging.WARNING
167
            log.setLevel(logging.WARNING)
170 168
        
171
        logger.setLevel(level)
172
    
173 169
    def _init_conf(self):
174 170
        if not self.api:
175 171
            self.api = os.environ.get(API_ENV, None)
......
258 254
            for p in self.personality:
259 255
                lpath, sep, rpath = p.partition(',')
260 256
                if not lpath or not rpath:
261
                    logging.error("Invalid personality argument '%s'", p)
257
                    log.error("Invalid personality argument '%s'", p)
262 258
                    return
263 259
                if not os.path.exists(lpath):
264
                    logging.error("File %s does not exist", lpath)
260
                    log.error("File %s does not exist", lpath)
265 261
                    return
266 262
                with open(lpath) as f:
267 263
                    personality.append((rpath, f.read()))
......
663 659
        cmd = cls(argv)
664 660
        cmd.execute()
665 661
    except ClientError, err:
666
        logging.error('%s', err.message)
667
        logging.info('%s', err.details)
662
        log.error('%s', err.message)
663
        log.info('%s', err.details)
668 664

  
669 665

  
670 666
if __name__ == '__main__':
667
    ch = logging.StreamHandler()
668
    ch.setFormatter(logging.Formatter('%(message)s'))
669
    log.addHandler(ch)
670
    
671 671
    main()

Also available in: Unified diff