|
23 | 23 | from google.cloud.logging.handlers.transports import BackgroundThreadTransport |
24 | 24 | from google.cloud.logging.resource import Resource |
25 | 25 |
|
| 26 | +_DEFAULT_GAE_LOGGER_NAME = 'app' |
| 27 | + |
26 | 28 | _GAE_PROJECT_ENV = 'GCLOUD_PROJECT' |
27 | 29 | _GAE_SERVICE_ENV = 'GAE_SERVICE' |
28 | 30 | _GAE_VERSION_ENV = 'GAE_VERSION' |
29 | 31 |
|
30 | 32 |
|
31 | 33 | class AppEngineHandler(CloudLoggingHandler): |
32 | | - """A handler that directly makes Stackdriver logging API calls. |
33 | | -
|
34 | | - This handler can be used to route Python standard logging messages directly |
35 | | - to the Stackdriver Logging API. |
36 | | -
|
37 | | - This handler supports both an asynchronous and synchronous transport. |
| 34 | + """A logging handler that sends App Engine-formatted logs to Stackdriver. |
38 | 35 |
|
39 | 36 | :type client: :class:`google.cloud.logging.client` |
40 | 37 | :param client: the authenticated Google Cloud Logging client for this |
41 | 38 | handler to use |
42 | 39 |
|
43 | | - :type name: str |
44 | | - :param name: the name of the custom log in Stackdriver Logging. Defaults |
45 | | - to 'python'. The name of the Python logger will be represented |
46 | | - in the ``python_logger`` field. |
47 | | -
|
48 | 40 | :type transport: type |
49 | | - :param transport: Class for creating new transport objects. It should |
50 | | - extend from the base :class:`.Transport` type and |
51 | | - implement :meth`.Transport.send`. Defaults to |
52 | | - :class:`.BackgroundThreadTransport`. The other |
53 | | - option is :class:`.SyncTransport`. |
54 | | -
|
55 | | - :type resource: :class:`~google.cloud.logging.resource.Resource` |
56 | | - :param resource: Monitored resource of the entry, defaults |
57 | | - to the global resource type. |
| 41 | + :param transport: The transport class. It should be a subclass of :class:`.Transport`. |
| 42 | + If unspecified, :class:`.BackgroundThreadTransport` will be used. |
58 | 43 | """ |
59 | 44 |
|
60 | | - DEFAULT_LOGGER_NAME = 'app' |
61 | | - |
62 | 45 | def __init__(self, client, |
63 | 46 | transport=BackgroundThreadTransport): |
64 | | - super(AppEngineHandler, self).__init__(client, name=self.DEFAULT_LOGGER_NAME, |
65 | | - transport=transport, resource=self.gae_resource) |
| 47 | + super(AppEngineHandler, self).__init__( |
| 48 | + client, |
| 49 | + name=_DEFAULT_GAE_LOGGER_NAME, |
| 50 | + transport=transport, |
| 51 | + resource=self.get_gae_resource()) |
66 | 52 |
|
67 | | - @property |
68 | | - def gae_resource(self): |
| 53 | + def get_gae_resource(self): |
69 | 54 | gae_resource = Resource( |
70 | 55 | type='gae_app', |
71 | 56 | labels={ |
|
0 commit comments