Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
kamaki
Commits
653b0597
Commit
653b0597
authored
Sep 29, 2011
by
Giorgos Verigakis
Browse files
Improve logging
Do not use the root logger. Refs #1337
parent
6d604f07
Changes
2
Hide whitespace changes
Inline
Side-by-side
kamaki/client.py
View file @
653b0597
...
...
@@ -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
)
log
ging
.
debug
(
'%s'
,
'>'
*
40
)
log
ging
.
debug
(
'%s %s'
,
method
,
path
)
log
.
debug
(
'%s'
,
'>'
*
40
)
log
.
debug
(
'%s %s'
,
method
,
path
)
for
key
,
val
in
headers
.
items
():
log
ging
.
debug
(
'%s: %s'
,
key
,
val
)
log
ging
.
debug
(
''
)
log
.
debug
(
'%s: %s'
,
key
,
val
)
log
.
debug
(
''
)
if
body
:
log
ging
.
debug
(
body
)
log
ging
.
debug
(
''
)
log
.
debug
(
body
)
log
.
debug
(
''
)
conn
.
request
(
method
,
path
,
body
,
headers
)
resp
=
conn
.
getresponse
()
log
ging
.
debug
(
'%s'
,
'<'
*
40
)
log
ging
.
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
():
log
ging
.
info
(
'%s: %s'
,
key
.
capitalize
(),
val
)
log
ging
.
info
(
''
)
log
.
info
(
'%s: %s'
,
key
.
capitalize
(),
val
)
log
.
info
(
''
)
buf
=
resp
.
read
()
try
:
...
...
kamaki/kamaki.py
View file @
653b0597
...
...
@@ -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
l
og
.
setL
evel
(
logging
.
DEBUG
)
elif
self
.
verbose
:
level
=
logging
.
INFO
l
og
.
setL
evel
(
logging
.
INFO
)
else
:
level
=
logging
.
WARNING
l
og
.
setL
evel
(
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
:
log
ging
.
error
(
"Invalid personality argument '%s'"
,
p
)
log
.
error
(
"Invalid personality argument '%s'"
,
p
)
return
if
not
os
.
path
.
exists
(
lpath
):
log
ging
.
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
:
log
ging
.
error
(
'%s'
,
err
.
message
)
log
ging
.
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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment