From 2e113ca6b2cc31aa8a9687d40ee1bd759381654f Mon Sep 17 00:00:00 2001 From: Naresh Date: Thu, 1 Mar 2018 13:24:45 +0530 Subject: Update logging in Python to use module-level logger All logging in Python so far was done with the root logger, resulting in logs like: `ERROR:Exception calling application:`. With module-level loggers, the logs will instead include the module in which the exception is raised: `ERROR:grpc._server:Exception calling application:` --- src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi | 3 ++- src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/python/grpcio/grpc/_cython') diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi index 53e06a1596..00a1b23a67 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc_string.pyx.pxi @@ -14,6 +14,7 @@ import logging +_LOGGER = logging.getLogger(__name__) # This function will ascii encode unicode string inputs if neccesary. # In Python3, unicode strings are the default str type. @@ -49,5 +50,5 @@ cdef str _decode(bytes bytestring): try: return bytestring.decode('utf8') except UnicodeDecodeError: - logging.exception('Invalid encoding on %s', bytestring) + _LOGGER.exception('Invalid encoding on %s', bytestring) return bytestring.decode('latin1') diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi index 707ec742dd..da3dd21244 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi @@ -18,6 +18,8 @@ import logging import time import grpc +_LOGGER = logging.getLogger(__name__) + cdef grpc_ssl_certificate_config_reload_status _server_cert_config_fetcher_wrapper( void* user_data, grpc_ssl_server_certificate_config **config) with gil: # This is a credentials.ServerCertificateConfig @@ -34,13 +36,13 @@ cdef grpc_ssl_certificate_config_reload_status _server_cert_config_fetcher_wrapp try: cert_config_wrapper = user_cb() except Exception: - logging.exception('Error fetching certificate config') + _LOGGER.exception('Error fetching certificate config') return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_FAIL if cert_config_wrapper is None: return GRPC_SSL_CERTIFICATE_CONFIG_RELOAD_UNCHANGED elif not isinstance( cert_config_wrapper, grpc.ServerCertificateConfiguration): - logging.error( + _LOGGER.error( 'Error fetching certificate configuration: certificate ' 'configuration must be of type grpc.ServerCertificateConfiguration, ' 'not %s' % type(cert_config_wrapper).__name__) -- cgit v1.2.3