Skip to content
This repository was archived by the owner on Jun 4, 2021. It is now read-only.

Switch to using module-level loggers #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions client/v1/docker_session_.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import httplib2
import six.moves.http_client

_LOGGER = logging.getLogger('containerregistry.client.docker_session')


class Push(object):
"""Push encapsulates a go/docker:push session."""
Expand Down Expand Up @@ -83,7 +85,7 @@ def __enter__(self):
# TODO(user): Consider also supporting cookies, which are
# used by Quay.io for authenticated sessions.

logging.info('Initiated upload of: %s', self._name)
_LOGGER.info('Initiated upload of: %s', self._name)
return self

def _exists(self, layer_id):
Expand Down Expand Up @@ -138,7 +140,7 @@ def _upload_one(self, image,
layer_id):
"""Upload a single layer, after checking whether it exists already."""
if self._exists(layer_id):
logging.info('Layer %s exists, skipping', layer_id)
_LOGGER.info('Layer %s exists, skipping', layer_id)
return

# TODO(user): This ordering is consistent with the docker client,
Expand All @@ -148,7 +150,7 @@ def _upload_one(self, image,
self._put_json(image, layer_id)
self._put_layer(image, layer_id)
self._put_checksum(image, layer_id)
logging.info('Layer %s pushed.', layer_id)
_LOGGER.info('Layer %s pushed.', layer_id)

def upload(self, image):
"""Upload the layers of the given image.
Expand Down Expand Up @@ -187,7 +189,7 @@ def _put_images(self):

def __exit__(self, exception_type, unused_value, unused_traceback):
if exception_type:
logging.error('Error during upload of: %s', self._name)
_LOGGER.error('Error during upload of: %s', self._name)
return

# This should complete the upload by issuing:
Expand All @@ -199,4 +201,4 @@ def __exit__(self, exception_type, unused_value, unused_traceback):
# to complete the transaction, with basic auth talking to registry.
self._put_images()

logging.info('Finished upload of: %s', self._name)
_LOGGER.info('Finished upload of: %s', self._name)
20 changes: 11 additions & 9 deletions client/v2/docker_session_.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import six.moves.http_client
import six.moves.urllib.parse

_LOGGER = logging.getLogger('containerregistry.client.docker_session')


def _tag_or_digest(name):
if isinstance(name, docker_name.Tag):
Expand Down Expand Up @@ -133,7 +135,7 @@ def _put_upload(self, image, digest):
mounted, location = self._start_upload(digest, self._mount)

if mounted:
logging.info('Layer %s mounted.', digest)
_LOGGER.info('Layer %s mounted.', digest)
return

location = self._add_digest(location, digest)
Expand All @@ -149,7 +151,7 @@ def _patch_upload(self, image,
mounted, location = self._start_upload(digest, self._mount)

if mounted:
logging.info('Layer %s mounted.', digest)
_LOGGER.info('Layer %s mounted.', digest)
return

location = self._get_absolute_url(location)
Expand Down Expand Up @@ -258,11 +260,11 @@ def _start_upload(self,
def _upload_one(self, image, digest):
"""Upload a single layer, after checking whether it exists already."""
if self._blob_exists(digest):
logging.info('Layer %s exists, skipping', digest)
_LOGGER.info('Layer %s exists, skipping', digest)
return

self._put_blob(image, digest)
logging.info('Layer %s pushed.', digest)
_LOGGER.info('Layer %s pushed.', digest)

def upload(self, image):
"""Upload the layers of the given image.
Expand All @@ -275,11 +277,11 @@ def upload(self, image):
if self._manifest_exists(image):
if isinstance(self._name, docker_name.Tag):
if self._remote_tag_digest() == image.digest():
logging.info('Tag points to the right manifest, skipping push.')
_LOGGER.info('Tag points to the right manifest, skipping push.')
return
logging.info('Manifest exists, skipping blob uploads and pushing tag.')
_LOGGER.info('Manifest exists, skipping blob uploads and pushing tag.')
else:
logging.info('Manifest exists, skipping upload.')
_LOGGER.info('Manifest exists, skipping upload.')
elif self._threads == 1:
for digest in image.blob_set():
self._upload_one(image, digest)
Expand All @@ -302,9 +304,9 @@ def __enter__(self):

def __exit__(self, exception_type, unused_value, unused_traceback):
if exception_type:
logging.error('Error during upload of: %s', self._name)
_LOGGER.error('Error during upload of: %s', self._name)
return
logging.info('Finished upload of: %s', self._name)
_LOGGER.info('Finished upload of: %s', self._name)


# pylint: disable=invalid-name
Expand Down
20 changes: 11 additions & 9 deletions client/v2_2/docker_session_.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import six.moves.http_client
import six.moves.urllib.parse

_LOGGER = logging.getLogger('containerregistry.client.docker_session')


def _tag_or_digest(name):
if isinstance(name, docker_name.Tag):
Expand Down Expand Up @@ -141,7 +143,7 @@ def _put_upload(self, image, digest):
mounted, location = self._start_upload(digest, self._mount)

if mounted:
logging.info('Layer %s mounted.', digest)
_LOGGER.info('Layer %s mounted.', digest)
return

location = self._add_digest(location, digest)
Expand All @@ -157,7 +159,7 @@ def _patch_upload(self, image,
mounted, location = self._start_upload(digest, self._mount)

if mounted:
logging.info('Layer %s mounted.', digest)
_LOGGER.info('Layer %s mounted.', digest)
return

location = self._get_absolute_url(location)
Expand Down Expand Up @@ -277,11 +279,11 @@ def _start_upload(self,
def _upload_one(self, image, digest):
"""Upload a single layer, after checking whether it exists already."""
if self._blob_exists(digest):
logging.info('Layer %s exists, skipping', digest)
_LOGGER.info('Layer %s exists, skipping', digest)
return

self._put_blob(image, digest)
logging.info('Layer %s pushed.', digest)
_LOGGER.info('Layer %s pushed.', digest)

def upload(self,
image,
Expand All @@ -297,11 +299,11 @@ def upload(self,
if self._manifest_exists(image):
if isinstance(self._name, docker_name.Tag):
if self._remote_tag_digest(image) == image.digest():
logging.info('Tag points to the right manifest, skipping push.')
_LOGGER.info('Tag points to the right manifest, skipping push.')
return
logging.info('Manifest exists, skipping blob uploads and pushing tag.')
_LOGGER.info('Manifest exists, skipping blob uploads and pushing tag.')
else:
logging.info('Manifest exists, skipping upload.')
_LOGGER.info('Manifest exists, skipping upload.')
elif isinstance(image, image_list.DockerImageList):
for _, child in image:
# TODO(user): Refactor so that the threadpool is shared.
Expand Down Expand Up @@ -329,9 +331,9 @@ def __enter__(self):

def __exit__(self, exception_type, unused_value, unused_traceback):
if exception_type:
logging.error('Error during upload of: %s', self._name)
_LOGGER.error('Error during upload of: %s', self._name)
return
logging.info('Finished upload of: %s', self._name)
_LOGGER.info('Finished upload of: %s', self._name)


# pylint: disable=invalid-name
Expand Down
3 changes: 2 additions & 1 deletion transport/retry_.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import httplib2
import six.moves.http_client

_LOGGER = logging.getLogger('containerregistry.transport.retry')
DEFAULT_SOURCE_TRANSPORT_CALLABLE = httplib2.Http
DEFAULT_MAX_RETRIES = 2
DEFAULT_BACKOFF_FACTOR = 0.5
Expand Down Expand Up @@ -103,7 +104,7 @@ def request(self, *args, **kwargs):
if retries >= self._max_retries or not self._should_retry(err):
raise

logging.error('Retrying after exception %s.', err)
_LOGGER.error('Retrying after exception %s.', err)
retries += 1
time.sleep(self._backoff_factor * (2**retries))
continue