本文整理汇总了Python中logging.getLoggerClass方法的典型用法代码示例。如果您正苦于以下问题:Python logging.getLoggerClass方法的具体用法?Python logging.getLoggerClass怎么用?Python logging.getLoggerClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging
的用法示例。
在下文中一共展示了logging.getLoggerClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: json_console_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def json_console_logger(init_context):
level = init_context.logger_config['log_level']
name = init_context.logger_config['name']
klass = logging.getLoggerClass()
logger_ = klass(name, level=level)
handler = logging.StreamHandler()
class JsonFormatter(logging.Formatter):
def format(self, record):
return json.dumps(record.__dict__)
handler.setFormatter(JsonFormatter())
logger_.addHandler(handler)
return logger_
示例2: json_console_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def json_console_logger(init_context):
level = coerce_valid_log_level(init_context.logger_config['log_level'])
name = init_context.logger_config['name']
klass = logging.getLoggerClass()
logger_ = klass(name, level=level)
handler = coloredlogs.StandardErrorHandler()
class JsonFormatter(logging.Formatter):
def format(self, record):
return seven.json.dumps(record.__dict__)
handler.setFormatter(JsonFormatter())
logger_.addHandler(handler)
return logger_
示例3: get_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [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)
#===========================================================================
示例4: set_up_notify_log_level
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def set_up_notify_log_level():
"""Add up a global notify severity to the python logging package.
NOTIFY severity is logging level between INFO and WARNING.
By default it outputs only echo step and step name
with description.
"""
# could (should?) be checking hasattr like so:
# hasattr(logging, levelName):
# hasattr(logging, methodName):
# hasattr(logging.getLoggerClass(), methodName):
# but this extra check is arguably *more* overhead than just assigning it?
logging.addLevelName(NOTIFY, "NOTIFY")
logging.NOTIFY = NOTIFY
logging.getLoggerClass().notify = notify
示例5: _init_log
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [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
示例6: set_logging_level
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [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)
示例7: getLogger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [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
示例8: add_logging_level
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def add_logging_level(levelName, levelNum, methodName = None):
""" Adds a new logging level to the `logging` module and the currently configured logging class.
`levelName` becomes an attribute of the `logging` module with the value `levelNum`.
`methodName` becomes a convenience method for both `logging` itself and the class returned by `logging.getLoggerClass()`
(usually just `logging.Logger`). If `methodName` is not specified, `levelName.lower()` is used.
To avoid accidental clobberings of existing attributes, this method will raise an `AttributeError` if the level name
is already an attribute of the `logging` module or if the method name is already present .
Example
-------
>>> add_logging_level('TRACE', logging.DEBUG - 5)
>>> logging.getLogger(__name__).setLevel("TRACE")
>>> logging.getLogger(__name__).trace('that worked')
>>> logging.trace('so did this')
>>> logging.TRACE
5
"""
if not methodName:
methodName = levelName.lower()
if hasattr(logging, levelName) or hasattr(logging, methodName) or hasattr(logging.getLoggerClass(), methodName):
return
def logForLevel(self, message, *args, **kwargs):
if self.isEnabledFor(levelNum):
self._log(levelNum, message, args, **kwargs)
def logToRoot(message, *args, **kwargs):
logging.log(levelNum, message, *args, **kwargs)
logging.addLevelName(levelNum, levelName)
setattr(logging, levelName, levelNum)
setattr(logging.getLoggerClass(), methodName, logForLevel)
setattr(logging, methodName, logToRoot)
示例9: test_set_logger_class
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def test_set_logger_class(self):
self.assertRaises(TypeError, logging.setLoggerClass, object)
class MyLogger(logging.Logger):
pass
logging.setLoggerClass(MyLogger)
self.assertEqual(logging.getLoggerClass(), MyLogger)
logging.setLoggerClass(logging.Logger)
self.assertEqual(logging.getLoggerClass(), logging.Logger)
示例10: viewLogs
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def viewLogs() -> None:
QDesktopServices.openUrl(QUrl.fromLocalFile(logging.getLoggerClass().root.handlers[0].baseFilename))
示例11: test_file_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def test_file_logger(init_context):
klass = logging.getLoggerClass()
logger_ = klass(
init_context.logger_config['name'], level=init_context.logger_config['log_level']
)
handler = LogTestFileHandler(init_context.logger_config['file_path'])
logger_.addHandler(handler)
handler.setLevel(init_context.logger_config['log_level'])
return logger_
示例12: construct_single_handler_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def construct_single_handler_logger(name, level, handler):
check.str_param(name, 'name')
check.inst_param(handler, 'handler', logging.Handler)
level = coerce_valid_log_level(level)
@logger
def single_handler_logger(_init_context):
klass = logging.getLoggerClass()
logger_ = klass(name, level=level)
logger_.addHandler(handler)
handler.setLevel(level)
return logger_
return single_handler_logger
示例13: create_logger
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def create_logger(app):
"""Creates a logger for the given application. This logger works
similar to a regular Python logger but changes the effective logging
level based on the application's debug flag. Furthermore this
function also removes all attached handlers in case there was a
logger with the log name before.
"""
Logger = getLoggerClass()
class DebugLogger(Logger):
def getEffectiveLevel(x):
if x.level == 0 and app.debug:
return DEBUG
return Logger.getEffectiveLevel(x)
class DebugHandler(StreamHandler):
def emit(x, record):
StreamHandler.emit(x, record) if app.debug else None
handler = DebugHandler()
handler.setLevel(DEBUG)
handler.setFormatter(Formatter(app.debug_log_format))
logger = getLogger(app.logger_name)
# just in case that was not a new logger, get rid of all the handlers
# already attached to it.
del logger.handlers[:]
logger.__class__ = DebugLogger
logger.addHandler(handler)
return logger
示例14: install_filter
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def install_filter(burst, interval, except_level='CRITICAL'):
"""Install a rate limit filter on existing and future loggers.
Limit logs to *burst* messages every *interval* seconds, except of levels
>= *except_level*. *except_level* is a log level name like 'CRITICAL'. If
*except_level* is an empty string, all levels are filtered.
The filter uses a monotonic clock, the timestamp of log records is not
used.
Raise an exception if a rate limit filter is already installed.
"""
if install_filter.log_filter is not None:
raise RuntimeError("rate limit filter already installed")
try:
except_levelno = _LOG_LEVELS[except_level]
except KeyError:
raise ValueError("invalid log level name: %r" % except_level)
log_filter = _LogRateLimit(burst, interval, except_levelno)
install_filter.log_filter = log_filter
install_filter.logger_class = logging.getLoggerClass()
class RateLimitLogger(install_filter.logger_class):
def __init__(self, *args, **kw):
logging.Logger.__init__(self, *args, **kw)
self.addFilter(log_filter)
# Setup our own logger class to automatically add the filter
# to new loggers.
logging.setLoggerClass(RateLimitLogger)
# Add the filter to all existing loggers
for logger in _iter_loggers():
logger.addFilter(log_filter)
示例15: _use_logger_class
# 需要导入模块: import logging [as 别名]
# 或者: from logging import getLoggerClass [as 别名]
def _use_logger_class(logger_class: Type[logging.Logger]) -> Iterator[None]:
original_logger_class = logging.getLoggerClass()
logging.setLoggerClass(logger_class)
try:
yield
finally:
logging.setLoggerClass(original_logger_class)