Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
liyanhui1228 authored and dhermes committed May 16, 2017
1 parent 0a33dbb commit 881a2da
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
41 changes: 14 additions & 27 deletions logging/google/cloud/logging/handlers/app_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

"""Logging handler for App Engine Flexible
Sends logs to the Stackdriver Logging API with the appropriate resource and labels for App Engine logs.
Sends logs to the Stackdriver Logging API with the appropriate resource
and labels for App Engine logs.
"""

import os
Expand All @@ -23,49 +24,35 @@
from google.cloud.logging.handlers.transports import BackgroundThreadTransport
from google.cloud.logging.resource import Resource

_DEFAULT_GAE_LOGGER_NAME = 'app'

_GAE_PROJECT_ENV = 'GCLOUD_PROJECT'
_GAE_SERVICE_ENV = 'GAE_SERVICE'
_GAE_VERSION_ENV = 'GAE_VERSION'


class AppEngineHandler(CloudLoggingHandler):
"""A handler that directly makes Stackdriver logging API calls.
This handler can be used to route Python standard logging messages directly
to the Stackdriver Logging API.
This handler supports both an asynchronous and synchronous transport.
"""A logging handler that sends App Engine-formatted logs to Stackdriver.
:type client: :class:`google.cloud.logging.client`
:param client: the authenticated Google Cloud Logging client for this
handler to use
:type name: str
:param name: the name of the custom log in Stackdriver Logging. Defaults
to 'python'. The name of the Python logger will be represented
in the ``python_logger`` field.
:type transport: type
:param transport: Class for creating new transport objects. It should
extend from the base :class:`.Transport` type and
implement :meth`.Transport.send`. Defaults to
:class:`.BackgroundThreadTransport`. The other
option is :class:`.SyncTransport`.
:type resource: :class:`~google.cloud.logging.resource.Resource`
:param resource: Monitored resource of the entry, defaults
to the global resource type.
:param transport: The transport class. It should be a subclass
of :class:`.Transport`. If unspecified,
:class:`.BackgroundThreadTransport`will be used.
"""

DEFAULT_LOGGER_NAME = 'app'

def __init__(self, client,
transport=BackgroundThreadTransport):
super(AppEngineHandler, self).__init__(client, name=self.DEFAULT_LOGGER_NAME,
transport=transport, resource=self.gae_resource)
super(AppEngineHandler, self).__init__(
client,
name=_DEFAULT_GAE_LOGGER_NAME,
transport=transport,
resource=self.get_gae_resource())

@property
def gae_resource(self):
def get_gae_resource(self):
gae_resource = Resource(
type='gae_app',
labels={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def enqueue(self, record, message, resource=None):
:type message: str
:param message: The message from the ``LogRecord`` after being
formatted by the associated log formatters.
:type resource: :class:`~google.cloud.logging.resource.Resource`
:param resource: (Optional) Monitored resource of the entry
"""
Expand Down
5 changes: 3 additions & 2 deletions logging/google/cloud/logging/handlers/transports/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"""

from google.cloud.logging.handlers.transports.base import Transport
from google.cloud.logging.resource import Resource


class SyncTransport(Transport):
Expand All @@ -41,4 +40,6 @@ def send(self, record, message, resource=None):
formatted by the associated log formatters.
"""
info = {'message': message, 'python_logger': record.name}
self.logger.log_struct(info, severity=record.levelname, resource=resource)
self.logger.log_struct(info,
severity=record.levelname,
resource=resource)
3 changes: 1 addition & 2 deletions logging/tests/unit/handlers/test_app_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class TestAppEngineHandlerHandler(unittest.TestCase):

PROJECT = 'PROJECT'

def _get_target_class(self):
Expand Down Expand Up @@ -47,7 +46,7 @@ def test_ctor(self):
def test_emit(self):
client = _Client(self.PROJECT)
handler = self._make_one(client, transport=_Transport)
gae_resource = handler.gae_resource
gae_resource = handler.get_gae_resource()
logname = 'loggername'
message = 'hello world'
record = logging.LogRecord(logname, logging, None, None, message,
Expand Down

0 comments on commit 881a2da

Please sign in to comment.