mirror of https://github.com/docker/docker-py.git
Merge pull request #11 from kstaken/logging-config
Allow control over the logging done by BuilderClient
This commit is contained in:
commit
9e4fb4003c
|
@ -73,8 +73,8 @@ class Client(requests.Session):
|
|||
|
||||
return self.post(url, json.dumps(data2), **kwargs)
|
||||
|
||||
def build(self, dockerfile, tag=None):
|
||||
bc = BuilderClient(self)
|
||||
def build(self, dockerfile, tag=None, logger=None):
|
||||
bc = BuilderClient(self, logger)
|
||||
img_id = None
|
||||
try:
|
||||
img_id = bc.build(dockerfile, tag=tag)
|
||||
|
@ -292,7 +292,7 @@ class Client(requests.Session):
|
|||
|
||||
|
||||
class BuilderClient(object):
|
||||
def __init__(self, client):
|
||||
def __init__(self, client, logger=None):
|
||||
self.client = client
|
||||
self.tmp_containers = {}
|
||||
self.tmp_images = {}
|
||||
|
@ -302,6 +302,9 @@ class BuilderClient(object):
|
|||
self.need_commit = False
|
||||
self.config = {}
|
||||
|
||||
if logger:
|
||||
self.logger = logger
|
||||
else:
|
||||
self.logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
|
||||
level='INFO')
|
||||
|
@ -313,9 +316,15 @@ class BuilderClient(object):
|
|||
# The build is unsuccessful, remove temporary containers and images
|
||||
self.client.remove_container(*self.tmp_containers)
|
||||
self.client.remove_image(*self.tmp_images)
|
||||
|
||||
res = ''
|
||||
try:
|
||||
self.logs.flush()
|
||||
res = self.logs.getvalue()
|
||||
#self.logs.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return res
|
||||
|
||||
def build(self, dockerfile, tag=None):
|
||||
|
|
Loading…
Reference in New Issue