本文整理汇总了Python中google.cloud.logging.getLogger方法的典型用法代码示例。如果您正苦于以下问题:Python logging.getLogger方法的具体用法?Python logging.getLogger怎么用?Python logging.getLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.cloud.logging
的用法示例。
在下文中一共展示了logging.getLogger方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_python_logging
# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import getLogger [as 别名]
def setup_python_logging(self):
"""Configures Python logging system
Python logs are sent to STDOUT and STDERR by default. In GCF, these
logs are associated on execution_id.
"""
if os.getenv('DEBUG'):
level = logging.DEBUG
else:
level = logging.INFO
# Make googleapiclient less noisy.
# See https://github.com/googleapis/google-api-python-client/issues/299
api_logger = logging.getLogger('googleapiclient')
api_logger.setLevel(logging.ERROR)
# Set level of our logger.
log = logging.getLogger(self.LOGNAME)
log.setLevel(level)
return log
示例2: suppress_unwanted_warnings
# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import getLogger [as 别名]
def suppress_unwanted_warnings():
"""Suppress unwanted warnings."""
# See https://github.com/googleapis/google-api-python-client/issues/299
logging.getLogger('googleapiclient.discovery_cache').setLevel(logging.ERROR)
示例3: configure_appengine
# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import getLogger [as 别名]
def configure_appengine():
"""Configure logging for App Engine."""
logging.getLogger().setLevel(logging.INFO)
if os.getenv('LOCAL_DEVELOPMENT') or os.getenv('PY_UNITTESTS'):
return
import google.cloud.logging
client = google.cloud.logging.Client()
handler = client.get_default_handler()
logging.getLogger().addHandler(handler)
示例4: configure
# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import getLogger [as 别名]
def configure(name, extras=None):
"""Set logger. See the list of loggers in bot/config/logging.yaml.
Also configures the process to log any uncaught exceptions as an error.
|extras| will be included by emit() in log messages."""
suppress_unwanted_warnings()
if _is_running_on_app_engine():
configure_appengine()
return
if _console_logging_enabled():
logging.basicConfig()
else:
config.dictConfig(get_logging_config_dict(name))
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
set_logger(logger)
# Set _default_extras so they can be used later.
if extras is None:
extras = {}
global _default_extras
_default_extras = extras
# Install an exception handler that will log an error when there is an
# uncaught exception.
sys.excepthook = uncaught_exception_handler
示例5: get_logger
# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import getLogger [as 别名]
def get_logger():
"""Return logger. We need this method because we need to mock logger."""
if _logger:
return _logger
if _is_running_on_app_engine():
# Running on App Engine.
set_logger(logging.getLogger())
elif _console_logging_enabled():
# Force a logger when console logging is enabled.
configure('root')
return _logger
示例6: _configure_logging
# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import getLogger [as 别名]
def _configure_logging(verbose=True, stackdriver_logging=False):
"""Basic logging configuration.
Args:
verbose: enable verbose logging
stackdriver_logging: enable Stackdriver logging
"""
logging.basicConfig(level=logging.ERROR)
level = logging.DEBUG if verbose else logging.INFO
logging.getLogger(_LOGGER.name).setLevel(level)
warnings.filterwarnings('ignore', r'.*end user credentials.*', UserWarning)
if stackdriver_logging:
import google.cloud.logging
client = google.cloud.logging.Client()
client.setup_logging(log_level=level)
示例7: __init__
# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import getLogger [as 别名]
def __init__(self, handler=None, transport=sync.SyncTransport):
self.logger = logging.getLogger()
if handler is None:
handler = logging.StreamHandler()
self.handler = handler
self.logger.addHandler(handler)
self.logger.setLevel(logging.INFO)
self.transport = transport(self)
示例8: setup_logging
# 需要导入模块: from google.cloud import logging [as 别名]
# 或者: from google.cloud.logging import getLogger [as 别名]
def setup_logging(app):
log_formatter = logger.Formatter(
'%(asctime)s %(levelname)8s [%(filename)s:%(lineno)d] '
'%(client)s %(message)s')
# log to files unless on AppEngine
if not on_appengine():
# Main logger
if not (app.debug or app.config.get('TESTING')):
handler = logging.FileHandler(
app.config.get('LOGFILE', '/tmp/scoreboard.wsgi.log'))
handler.setLevel(logging.INFO)
handler.setFormatter(log_formatter)
app.logger.addHandler(handler)
else:
app.logger.handlers[0].setFormatter(log_formatter)
# Challenge logger
handler = logging.FileHandler(
app.config.get('CHALLENGELOG', '/tmp/scoreboard.challenge.log'))
handler.setLevel(logging.INFO)
handler.setFormatter(logger.Formatter(
'%(asctime)s %(client)s %(message)s'))
local_logger = logging.getLogger('scoreboard')
local_logger.addHandler(handler)
app.challenge_log = local_logger
else:
app.challenge_log = app.logger
try:
import google.cloud.logging
from google.cloud.logging import handlers
client = google.cloud.logging.Client()
client.setup_logging()
handler = handlers.CloudLoggingHandler(client)
app.logger.addHandler(handler)
handler.setLevel(logging.INFO)
return app
except ImportError as ex:
logging.error('Failed setting up logging: %s', ex)
if not app.logger.handlers:
app.logger.addHandler(flask_logging.default_handler)
app.logger.handlers[0].setFormatter(log_formatter)
logging.getLogger().handlers[0].setFormatter(log_formatter)
return app