Merge pull request #17064 from gnossen/fix-logging

Fix logging
pull/16773/head
Richard Belleville 6 years ago committed by GitHub
commit b741454fe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/python/.gitignore
  2. 2
      src/python/grpcio/grpc/_channel.py
  3. 2
      src/python/grpcio/grpc/_common.py
  4. 2
      src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi
  5. 2
      src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi
  6. 2
      src/python/grpcio/grpc/_plugin_wrapping.py
  7. 1
      src/python/grpcio/grpc/_server.py
  8. 2
      src/python/grpcio/grpc/framework/foundation/callable_util.py
  9. 2
      src/python/grpcio/grpc/framework/foundation/logging_pool.py
  10. 2
      src/python/grpcio/grpc/framework/foundation/stream_util.py
  11. 2
      src/python/grpcio_tests/tests/interop/server.py
  12. 1
      src/python/grpcio_tests/tests/tests.json
  13. 1
      src/python/grpcio_tests/tests/unit/BUILD.bazel
  14. 2
      src/python/grpcio_tests/tests/unit/_api_test.py
  15. 2
      src/python/grpcio_tests/tests/unit/_auth_context_test.py
  16. 2
      src/python/grpcio_tests/tests/unit/_auth_test.py
  17. 2
      src/python/grpcio_tests/tests/unit/_channel_args_test.py
  18. 2
      src/python/grpcio_tests/tests/unit/_channel_close_test.py
  19. 2
      src/python/grpcio_tests/tests/unit/_channel_connectivity_test.py
  20. 2
      src/python/grpcio_tests/tests/unit/_channel_ready_future_test.py
  21. 2
      src/python/grpcio_tests/tests/unit/_compression_test.py
  22. 2
      src/python/grpcio_tests/tests/unit/_credentials_test.py
  23. 2
      src/python/grpcio_tests/tests/unit/_empty_message_test.py
  24. 2
      src/python/grpcio_tests/tests/unit/_exit_scenarios.py
  25. 2
      src/python/grpcio_tests/tests/unit/_exit_test.py
  26. 2
      src/python/grpcio_tests/tests/unit/_interceptor_test.py
  27. 2
      src/python/grpcio_tests/tests/unit/_invalid_metadata_test.py
  28. 2
      src/python/grpcio_tests/tests/unit/_invocation_defects_test.py
  29. 73
      src/python/grpcio_tests/tests/unit/_logging_test.py
  30. 2
      src/python/grpcio_tests/tests/unit/_metadata_code_details_test.py
  31. 2
      src/python/grpcio_tests/tests/unit/_metadata_test.py
  32. 2
      src/python/grpcio_tests/tests/unit/_reconnect_test.py
  33. 2
      src/python/grpcio_tests/tests/unit/_resource_exhausted_test.py
  34. 2
      src/python/grpcio_tests/tests/unit/_rpc_test.py
  35. 2
      src/python/grpcio_tests/tests/unit/_server_ssl_cert_config_test.py
  36. 2
      src/python/grpcio_tests/tests/unit/_server_test.py
  37. 2
      src/python/grpcio_tests/tests/unit/_session_cache_test.py

@ -1,3 +1,4 @@
gens/
*_pb2.py
*_pb2_grpc.py
*.egg-info/

@ -24,8 +24,8 @@ from grpc import _grpcio_metadata
from grpc._cython import cygrpc
from grpc.framework.foundation import callable_util
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)
_LOGGER.addHandler(logging.NullHandler())
_USER_AGENT = 'grpc-python/{}'.format(_grpcio_metadata.__version__)

@ -20,8 +20,8 @@ import six
import grpc
from grpc._cython import cygrpc
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)
_LOGGER.addHandler(logging.NullHandler())
CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY = {
cygrpc.ConnectivityState.idle:

@ -14,8 +14,8 @@
import logging
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)
_LOGGER.addHandler(logging.NullHandler())
# This function will ascii encode unicode string inputs if neccesary.
# In Python3, unicode strings are the default str type.

@ -18,8 +18,8 @@ import logging
import time
import grpc
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)
_LOGGER.addHandler(logging.NullHandler())
cdef class Server:

@ -20,8 +20,8 @@ import grpc
from grpc import _common
from grpc._cython import cygrpc
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)
_LOGGER.addHandler(logging.NullHandler())
class _AuthMetadataContext(

@ -27,7 +27,6 @@ from grpc import _interceptor
from grpc._cython import cygrpc
from grpc.framework.foundation import callable_util
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)
_SHUTDOWN_TAG = 'shutdown'

@ -21,8 +21,8 @@ import logging
import six
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)
_LOGGER.addHandler(logging.NullHandler())
class Outcome(six.with_metaclass(abc.ABCMeta)):

@ -17,8 +17,8 @@ import logging
from concurrent import futures
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)
_LOGGER.addHandler(logging.NullHandler())
def _wrap(behavior):

@ -19,8 +19,8 @@ import threading
from grpc.framework.foundation import stream
_NO_VALUE = object()
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)
_LOGGER.addHandler(logging.NullHandler())
class TransformingConsumer(stream.Consumer):

@ -25,8 +25,8 @@ from tests.interop import methods
from tests.interop import resources
from tests.unit import test_common
logging.basicConfig()
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
logging.basicConfig()
_LOGGER = logging.getLogger(__name__)

@ -46,6 +46,7 @@
"unit._interceptor_test.InterceptorTest",
"unit._invalid_metadata_test.InvalidMetadataTest",
"unit._invocation_defects_test.InvocationDefectsTest",
"unit._logging_test.LoggingTest",
"unit._metadata_code_details_test.MetadataCodeDetailsTest",
"unit._metadata_test.MetadataTest",
"unit._reconnect_test.ReconnectTest",

@ -17,6 +17,7 @@ GRPCIO_TESTS_UNIT = [
"_interceptor_test.py",
"_invalid_metadata_test.py",
"_invocation_defects_test.py",
"_logging_test.py",
"_metadata_code_details_test.py",
"_metadata_test.py",
# TODO: Issue 16336

@ -14,6 +14,7 @@
"""Test of gRPC Python's application-layer API."""
import unittest
import logging
import six
@ -102,4 +103,5 @@ class ChannelTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -15,6 +15,7 @@
import pickle
import unittest
import logging
import grpc
from grpc import _channel
@ -187,4 +188,5 @@ class AuthContextTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -16,6 +16,7 @@
import collections
import threading
import unittest
import logging
from grpc import _auth
@ -77,4 +78,5 @@ class AccessTokenAuthMetadataPluginTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -15,6 +15,7 @@
from concurrent import futures
import unittest
import logging
import grpc
@ -62,4 +63,5 @@ class ChannelArgsTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -13,6 +13,7 @@
# limitations under the License.
"""Tests server and client side compression."""
import logging
import threading
import time
import unittest
@ -182,4 +183,5 @@ class ChannelCloseTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -13,6 +13,7 @@
# limitations under the License.
"""Tests of grpc._channel.Channel connectivity."""
import logging
import threading
import time
import unittest
@ -142,4 +143,5 @@ class ChannelConnectivityTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -15,6 +15,7 @@
import threading
import unittest
import logging
import grpc
from tests.unit.framework.common import test_constants
@ -85,4 +86,5 @@ class ChannelReadyFutureTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -15,6 +15,7 @@
import unittest
import logging
import grpc
from grpc import _grpcio_metadata
@ -117,4 +118,5 @@ class CompressionTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -14,6 +14,7 @@
"""Tests of credentials."""
import unittest
import logging
import grpc
@ -54,4 +55,5 @@ class CredentialsTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -13,6 +13,7 @@
# limitations under the License.
import unittest
import logging
import grpc
@ -118,4 +119,5 @@ class EmptyMessageTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -16,6 +16,7 @@
import argparse
import threading
import time
import logging
import grpc
@ -161,6 +162,7 @@ def infinite_request_iterator():
if __name__ == '__main__':
logging.basicConfig()
parser = argparse.ArgumentParser()
parser.add_argument('scenario', type=str)
parser.add_argument(

@ -26,6 +26,7 @@ import sys
import threading
import time
import unittest
import logging
from tests.unit import _exit_scenarios
@ -187,4 +188,5 @@ class ExitTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -17,6 +17,7 @@ import collections
import itertools
import threading
import unittest
import logging
from concurrent import futures
import grpc
@ -598,4 +599,5 @@ class InterceptorTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -14,6 +14,7 @@
"""Test of RPCs made against gRPC Python's application-layer API."""
import unittest
import logging
import grpc
@ -131,4 +132,5 @@ class InvalidMetadataTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -15,6 +15,7 @@
import itertools
import threading
import unittest
import logging
import grpc
@ -271,4 +272,5 @@ class InvocationDefectsTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -0,0 +1,73 @@
# Copyright 2018 gRPC authors.
#
# 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.
"""Test of gRPC Python's interaction with the python logging module"""
import unittest
import six
from six.moves import reload_module
import logging
import grpc
import functools
import sys
def patch_stderr(f):
@functools.wraps(f)
def _impl(*args, **kwargs):
old_stderr = sys.stderr
sys.stderr = six.StringIO()
try:
f(*args, **kwargs)
finally:
sys.stderr = old_stderr
return _impl
def isolated_logging(f):
@functools.wraps(f)
def _impl(*args, **kwargs):
reload_module(logging)
reload_module(grpc)
try:
f(*args, **kwargs)
finally:
reload_module(logging)
return _impl
class LoggingTest(unittest.TestCase):
@isolated_logging
def test_logger_not_occupied(self):
self.assertEqual(0, len(logging.getLogger().handlers))
@patch_stderr
@isolated_logging
def test_handler_found(self):
self.assertEqual(0, len(sys.stderr.getvalue()))
@isolated_logging
def test_can_configure_logger(self):
intended_stream = six.StringIO()
logging.basicConfig(stream=intended_stream)
self.assertEqual(1, len(logging.getLogger().handlers))
self.assertIs(logging.getLogger().handlers[0].stream, intended_stream)
if __name__ == '__main__':
unittest.main(verbosity=2)

@ -15,6 +15,7 @@
import threading
import unittest
import logging
import grpc
@ -656,4 +657,5 @@ class MetadataCodeDetailsTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -15,6 +15,7 @@
import unittest
import weakref
import logging
import grpc
from grpc import _channel
@ -237,4 +238,5 @@ class MetadataTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -15,6 +15,7 @@
import socket
import time
import logging
import unittest
import grpc
@ -100,4 +101,5 @@ class ReconnectTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -15,6 +15,7 @@
import threading
import unittest
import logging
import grpc
from grpc import _channel
@ -253,4 +254,5 @@ class ResourceExhaustedTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -16,6 +16,7 @@
import itertools
import threading
import unittest
import logging
from concurrent import futures
import grpc
@ -846,4 +847,5 @@ class RPCTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -35,6 +35,7 @@ import os
import six
import threading
import unittest
import logging
from concurrent import futures
@ -518,4 +519,5 @@ class ServerSSLCertReloadTestCertConfigReuse(_ServerSSLCertReloadTest):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -14,6 +14,7 @@
from concurrent import futures
import unittest
import logging
import grpc
@ -49,4 +50,5 @@ class ServerTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

@ -15,6 +15,7 @@
import pickle
import unittest
import logging
import grpc
from grpc import _channel
@ -142,4 +143,5 @@ class SSLSessionCacheTest(unittest.TestCase):
if __name__ == '__main__':
logging.basicConfig()
unittest.main(verbosity=2)

Loading…
Cancel
Save