本文整理汇总了Python中logging.setLoggerClass方法的典型用法代码示例。如果您正苦于以下问题:Python logging.setLoggerClass方法的具体用法?Python logging.setLoggerClass怎么用?Python logging.setLoggerClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging.setLoggerClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_rp_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def setup_rp_logging(self):
"Setup reportportal logging"
try:
# Setting up a logging.
logging.setLoggerClass(RPLogger)
rp_logger = logging.getLogger(__name__)
rp_logger.setLevel(logging.INFO)
# Create handler for Report Portal.
rp_handler = RPLogHandler(pytest.config._config.py_test_service)
# Set INFO level for Report Portal handler.
rp_handler.setLevel(logging.INFO)
return rp_logger
except Exception as e:
self.write("Exception when trying to set rplogger")
self.write(str(e))
self.exceptions.append("Error when setting up the reportportal logger")
示例2: _static_init
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def _static_init():
if Log._initialized:
return
logging.setLoggerClass(_Logger)
# The root logger's type is unfortunately (and surprisingly) not affected by
# `setLoggerClass`. Monkey patch it instead. TODO(vimota): Remove this, see the TODO
# associated with _Logger.
logging.RootLogger.findCaller = _Logger.findCaller
log_to_file = _LOG_TO_FILE_ENV.lower() in ("yes", "true", "t", "1") if _LOG_TO_FILE_ENV is not None else True
if log_to_file:
handler = logging.FileHandler(filename='/tmp/kaggle.log', mode='w')
else:
handler = logging.StreamHandler()
# ".1s" is for the first letter: http://stackoverflow.com/a/27453084/1869.
format_string = "%(asctime)s %(levelname).1s %(process)d %(filename)s:%(lineno)d] %(message)s"
handler.setFormatter(_LogFormatter(format_string))
logging.basicConfig(level=logging.INFO, handlers=[handler])
Log._initialized = True
示例3: setup_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def setup_logger(loglevel=DEBUG):
"""Set up logger and add stdout handler"""
logging.setLoggerClass(IPDLogger)
logger = logging.getLogger("icloudpd")
logger.setLevel(loglevel)
has_stdout_handler = False
for handler in logger.handlers:
if handler.name == "stdoutLogger":
has_stdout_handler = True
if not has_stdout_handler:
formatter = logging.Formatter(
fmt="%(asctime)s %(levelname)-8s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S")
stdout_handler = logging.StreamHandler(stream=sys.stdout)
stdout_handler.setFormatter(formatter)
stdout_handler.name = "stdoutLogger"
logger.addHandler(stdout_handler)
return logger
示例4: test_logger_tqdm_fallback
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def test_logger_tqdm_fallback(self):
logging.setLoggerClass(IPDLogger)
logger = logging.getLogger("icloudpd-test")
logger.log = MagicMock()
logger.set_tqdm_description("foo")
logger.log.assert_called_once_with(logging.INFO, "foo")
logger.log = MagicMock()
logger.tqdm_write("bar")
logger.log.assert_called_once_with(logging.INFO, "bar")
logger.set_tqdm(MagicMock())
logger.tqdm.write = MagicMock()
logger.tqdm.set_description = MagicMock()
logger.log = MagicMock()
logger.set_tqdm_description("baz")
logger.tqdm.set_description.assert_called_once_with("baz")
logger.tqdm_write("qux")
logger.tqdm.write.assert_called_once_with("qux")
logger.log.assert_not_called
示例5: getLogger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def getLogger(name):
"""Returns a logger instance to use for the given name that implements the Scalyr agent's extra logging features.
This should be used in place of logging.getLogger when trying to retrieve a logging instance that implements
Scalyr agent's extra features.
Note, the logger instance will be configured to emit records at INFO level and above.
@param name: The name of the logger, such as the module name. If this is for a particular monitor instance, then
the monitor id should be appended at the end surrounded by brackets, such as "my_monitor[1]"
@return: A logger instance implementing the extra features.
"""
logging.setLoggerClass(AgentLogger)
result = logging.getLogger(name)
result.setLevel(logging.INFO)
return result
# The single AgentLogManager instance that tracks all of the process wide information necessary to implement
# our logging strategy. This variable is set to the real variable down below.
示例6: uninstall_filter
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def uninstall_filter():
"""Uninstall the rate filter installed by install_filter().
Do nothing if the filter was already uninstalled.
"""
if install_filter.log_filter is None:
# not installed (or already uninstalled)
return
# Restore the old logger class
logging.setLoggerClass(install_filter.logger_class)
# Remove the filter from all existing loggers
for logger in _iter_loggers():
logger.removeFilter(install_filter.log_filter)
install_filter.logger_class = None
install_filter.log_filter = None
示例7: get_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def get_logger(name="insteon_mqtt"):
"""Get a logger object to use.
This will return a logging object to use for messages.
Args:
name (str): The name of the logging objectd.
Returns:
The requested logging object.
"""
# Force the logging system to use our custom logger class, then restore
# whatever was set when we're done.
save = logging.getLoggerClass()
try:
logging.setLoggerClass(Logger)
return logging.getLogger(name)
finally:
logging.setLoggerClass(save)
#===========================================================================
示例8: _initialize
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def _initialize(log_config_path):
"""
Initialize the logging facility for Ignis
"""
logging.setLoggerClass(IgnisLogger)
log_config = IgnisLogging._load_config_file(log_config_path)
# Reading the config file content
IgnisLogging._file_logging_enabled = \
log_config.get('file_logging') == "true"
IgnisLogging._log_file = log_config.get('log_file') if \
log_config.get('log_file') is not None else "ignis.log"
max_size = log_config.get('max_size')
IgnisLogging._max_bytes = int(max_size) if \
max_size is not None and max_size.isdigit() else 0
max_rotations = log_config.get('max_rotations')
IgnisLogging._max_rotations = int(max_rotations) if \
max_rotations is not None and max_rotations.isdigit() else 0
示例9: _init_log
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def _init_log():
"""Initializes the Astropy log--in most circumstances this is called
automatically when importing astropy.
"""
global log
orig_logger_cls = logging.getLoggerClass()
logging.setLoggerClass(AstropyLogger)
try:
log = logging.getLogger('astropy')
log._set_defaults()
finally:
logging.setLoggerClass(orig_logger_cls)
return log
示例10: get_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def get_logger(name=None):
"""
Build a logger with the given name and returns the logger.
:param name: The name for the logger. This is usually the module
name, ``__name__``.
:return: logger object
"""
logging.setLoggerClass(CustomLogger)
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
logger.addHandler(_get_info_handler())
logger.addHandler(_get_out_handler())
logger.addHandler(_get_warn_handler())
logger.addHandler(_get_error_handler())
logger.addHandler(_get_critical_handler())
logger.addHandler(_get_success_handler())
logger.propagate = False
return logger
示例11: init_logging
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def init_logging():
# type: () -> None
"""
Initialize logging (set up forwarding to Go backend and sane defaults)
"""
# Forward to Go backend
logging.addLevelName(TRACE_LEVEL, 'TRACE')
logging.setLoggerClass(AgentLogger)
logging.captureWarnings(True) # Capture warnings as logs so it's easier for log parsers to handle them.
rootLogger = logging.getLogger()
rootLogger.addHandler(AgentLogHandler())
rootLogger.setLevel(_get_py_loglevel(datadog_agent.get_config('log_level')))
# `requests` (used in a lot of checks) imports `urllib3`, which logs a bunch of stuff at the info level
# Therefore, pre emptively increase the default level of that logger to `WARN`
urllib_logger = logging.getLogger("requests.packages.urllib3")
urllib_logger.setLevel(logging.WARN)
urllib_logger.propagate = True
示例12: set_logging_level
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def set_logging_level(cls, level):
if cls._qkc_logger:
Logger.warning("logging_level has already been set")
return
level_map = {
"DEBUG": logging.DEBUG,
"INFO": logging.INFO,
"WARNING": logging.WARNING,
"ERROR": logging.ERROR,
"CRITICAL": logging.CRITICAL,
}
level = level.upper()
if level not in level_map:
raise RuntimeError("invalid level {}".format(level))
original_logger_class = logging.getLoggerClass()
logging.setLoggerClass(QKCLogger)
cls._qkc_logger = logging.getLogger("qkc")
logging.setLoggerClass(original_logger_class)
logging.root.setLevel(level_map[level])
formatter = QKCLogFormatter()
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logging.root.addHandler(handler)
示例13: getLogger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def getLogger(self, name):
logging.setLoggerClass(SLogger)
return super(SManager, self).getLogger(name)
示例14: _logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def _logger(self):
"""Return the logger. The default_args property is not available in init."""
logging.setLoggerClass(TraceLogger)
logger = logging.getLogger(self.logger_name)
logger.setLevel(logging.TRACE)
return logger
示例15: getLogger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import setLoggerClass [as 别名]
def getLogger(name):
og_class = logging.getLoggerClass()
try:
logging.setLoggerClass(Logger)
return logging.getLogger(name)
finally:
logging.setLoggerClass(og_class)
# The main 'eyed3' logger