1# Copyright 2016 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Module containing base class for logging transport."""
16
17from google.cloud.logging_v2.logger import _GLOBAL_RESOURCE
18
19
20class Transport(object):
21 """Base class for Google Cloud Logging handler transports.
22
23 Subclasses of :class:`Transport` must have constructors that accept a
24 client and name object, and must override :meth:`send`.
25 """
26
27 def __init__(self, client, name, resource=_GLOBAL_RESOURCE, **kwargs):
28 """
29 Args:
30 client (~logging_v2.client.Client):
31 The Logging client.
32 name (str): The name of the lgoger.
33 resource (Optional[Resource|dict]): The default monitored resource to associate
34 with logs when not specified
35 """
36 super().__init__()
37
38 def send(self, record, message, **kwargs):
39 """Transport send to be implemented by subclasses.
40
41 Args:
42 record (logging.LogRecord): Python log record that the handler was called with.
43 message (str or dict): The message from the ``LogRecord`` after being
44 formatted by the associated log formatters.
45 kwargs: Additional optional arguments for the logger
46 """
47 raise NotImplementedError
48
49 def flush(self):
50 """Submit any pending log records.
51
52 For blocking/sync transports, this is a no-op.
53 """
54 pass
55
56 def close(self):
57 """Closes the transport and cleans up resources used by it.
58
59 This call should be followed up by disowning the transport.
60 """
61 pass