Skip to content

Commit

Permalink
fix: Add submodule imports for handlers to logging alias (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Dec 8, 2020
1 parent e704f28 commit 6843a3a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 1 deletion.
27 changes: 27 additions & 0 deletions google/cloud/logging/handlers/__init__.py
@@ -0,0 +1,27 @@
# Copyright 2016 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Python :mod:`logging` handlers for Google Cloud Logging."""

from google.cloud.logging_v2.handlers.app_engine import AppEngineHandler
from google.cloud.logging_v2.handlers.container_engine import ContainerEngineHandler
from google.cloud.logging_v2.handlers.handlers import CloudLoggingHandler
from google.cloud.logging_v2.handlers.handlers import setup_logging

__all__ = [
"AppEngineHandler",
"CloudLoggingHandler",
"ContainerEngineHandler",
"setup_logging",
]
17 changes: 17 additions & 0 deletions google/cloud/logging/handlers/middleware/__init__.py
@@ -0,0 +1,17 @@
# Copyright 2017 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from google.cloud.logging_v2.handlers.middleware.request import RequestMiddleware

__all__ = ["RequestMiddleware"]
28 changes: 28 additions & 0 deletions google/cloud/logging/handlers/transports/__init__.py
@@ -0,0 +1,28 @@
# Copyright 2016 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Transport classes for Python logging integration.
Currently two options are provided, a synchronous transport that makes
an API call for each log statement, and an asynchronous handler that
sends the API using a :class:`~google.cloud.logging.logger.Batch` object in
the background.
"""

from google.cloud.logging_v2.handlers.transports.base import Transport
from google.cloud.logging_v2.handlers.transports.sync import SyncTransport
from google.cloud.logging_v2.handlers.transports.background_thread import (
BackgroundThreadTransport,
)

__all__ = ["BackgroundThreadTransport", "SyncTransport", "Transport"]
41 changes: 40 additions & 1 deletion tests/unit/test_logging_shim.py
Expand Up @@ -17,7 +17,7 @@


class TestLoggingShim(unittest.TestCase):
def test_shim_matches_logging_v2(self):
def test_root_shim_matches_logging_v2(self):
from google.cloud import logging
from google.cloud import logging_v2

Expand All @@ -26,4 +26,43 @@ def test_shim_matches_logging_v2(self):
for name in logging.__all__:
found = getattr(logging, name)
expected = getattr(logging_v2, name)
if name == "handlers":
# handler has separate shim
self.assertTrue(found)
self.assertIs(type(found), type(expected))
else:
# other attributes should be identical
self.assertIs(found, expected)

def test_handler_shim_matches_logging_v2(self):
from google.cloud.logging import handlers
from google.cloud.logging_v2 import handlers as handlers_2

self.assertEqual(handlers.__all__, handlers_2.__all__)

for name in handlers.__all__:
found = getattr(handlers, name)
expected = getattr(handlers_2, name)
self.assertIs(found, expected)

def test_middleware_shim_matches_logging_v2(self):
from google.cloud.logging.handlers import middleware
from google.cloud.logging_v2.handlers import middleware as middleware_2

self.assertEqual(middleware.__all__, middleware_2.__all__)

for name in middleware.__all__:
found = getattr(middleware, name)
expected = getattr(middleware_2, name)
self.assertIs(found, expected)

def test_transports_shim_matches_logging_v2(self):
from google.cloud.logging.handlers import transports
from google.cloud.logging_v2.handlers import transports as transports_2

self.assertEqual(transports.__all__, transports_2.__all__)

for name in transports.__all__:
found = getattr(transports, name)
expected = getattr(transports_2, name)
self.assertIs(found, expected)

0 comments on commit 6843a3a

Please sign in to comment.