本文整理汇总了Python中logging.handlers.WatchedFileHandler.addFilter方法的典型用法代码示例。如果您正苦于以下问题:Python WatchedFileHandler.addFilter方法的具体用法?Python WatchedFileHandler.addFilter怎么用?Python WatchedFileHandler.addFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging.handlers.WatchedFileHandler
的用法示例。
在下文中一共展示了WatchedFileHandler.addFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import addFilter [as 别名]
def setup():
cfg = parse_config()
logging.getLogger().setLevel(getattr(logging, cfg.get('log', 'loglevel').upper()))
logfile = cfg.get('log', 'logfile')
if logfile != '':
handler = WatchedFileHandler(logfile)
handler.addFilter(RequestIdFilter())
formatter = logging.Formatter(
'%(asctime)s [%(process)d] %(levelname)-5s '
'%(request_id)s %(name)s %(message)s'
)
handler.setFormatter(formatter)
logging.getLogger().addHandler(handler)
else:
logging.basicConfig()
ctx = SygnalContext()
ctx.database = sygnal.db.Db(cfg.get('db', 'dbfile'))
for key,val in cfg.items('apps'):
parts = key.rsplit('.', 1)
if len(parts) < 2:
continue
if parts[1] == 'type':
try:
pushkins[parts[0]] = make_pushkin(val, parts[0])
except:
logger.exception("Failed to load module for kind %s", val)
raise
if len(pushkins) == 0:
logger.error("No app IDs are configured. Edit sygnal.conf to define some.")
sys.exit(1)
for p in pushkins:
pushkins[p].cfg = cfg
pushkins[p].setup(ctx)
logger.info("Configured with app IDs: %r", pushkins.keys())
logger.error("Setup completed")
示例2: __init__
# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import addFilter [as 别名]
def __init__(
self,
level=logging.DEBUG,
name=None,
logdir="./",
stdout=True,
multiFile=False,
post=False,
ws="www-qa.coraid.com",
):
self.logdir = logdir
self.ws = ws
self.instance = os.environ.get("instance") or ""
self.level = level
logging.addLevelName(COMMENT, "COMMENT")
# Root Logger
self.logger = logging.getLogger("otto" + self.instance)
self.logger.addHandler(logging.NullHandler())
"""
Root Logger Threshold is WARNING by default.
We will set the threshold as low as possible
"""
self.logger.setLevel(DEBUG)
"""
The STDOUT handler will use the logger default threshold for printing.
If the level is set to INFO the STDOUT should only display INFO messages and greater
"""
if stdout:
StdOutHandler = logging.StreamHandler(sys.stdout)
StdOutHandler._name = "STDOUT"
StdOutHandler.setLevel(level)
StdOutHandler.setFormatter(Dispatcher())
self.logger.addHandler(StdOutHandler)
if name is None:
frame = inspect.stack()[1]
name = inspect.getfile(frame[0]).split("/")[-1].split(".py")[0]
logFileBase = self.logdir + name + "-" + time.strftime("%Y%m%d_%H%M")
"""
The Full log will contain every level of output and will be created
in any configuration for use when posting the log to the web server.
"""
fullLogFile = logFileBase + "_FULL.log"
self.fullLogFile = fullLogFile
FullLogFileHandler = WatchedFileHandler(fullLogFile)
FullLogFileHandler.setLevel(level)
FullLogFileHandler._name = "LogFile-FULL"
FullLogFileHandler.setFormatter(Dispatcher())
self.logger.addHandler(FullLogFileHandler)
"""
In the case of multiFile = True:
Create a FileHandler for each level and attatch the appropriate level name to the file suffix
Then set a filter on each handler to return only the appropriate level per file
"""
if multiFile:
# Set up filename variables
debugLogFile = logFileBase + "_DEBUG.log"
commentLogFile = logFileBase + "_COMMENT.log"
infoLogFile = logFileBase + "_INFO.log"
warningLogFile = logFileBase + "_WARNING.log"
errorLogFile = logFileBase + "_ERROR.log"
# Create FileHandler objects
DebugFileHandler = WatchedFileHandler(debugLogFile)
DebugFileHandler._name = "LogFile-DEBUG"
CommentFileHandler = WatchedFileHandler(commentLogFile)
CommentFileHandler._name = "LogFile-COMMENT"
InfoFileHandler = WatchedFileHandler(infoLogFile)
InfoFileHandler._name = "LogFile-INFO"
WarningFileHandler = WatchedFileHandler(warningLogFile)
WarningFileHandler._name = "LogFile-WARNING"
ErrorFileHandler = WatchedFileHandler(errorLogFile)
ErrorFileHandler._name = "LogFile-ERROR"
# Add filters at corresponding levels
DebugFileHandler.addFilter(LogFilter(DEBUG))
CommentFileHandler.addFilter(LogFilter(COMMENT))
InfoFileHandler.addFilter(LogFilter(INFO))
WarningFileHandler.addFilter(LogFilter(WARNING))
ErrorFileHandler.addFilter(LogFilter(ERROR))
# Add format Dispatcher
DebugFileHandler.setFormatter(Dispatcher())
CommentFileHandler.setFormatter(Dispatcher())
InfoFileHandler.setFormatter(Dispatcher())
WarningFileHandler.setFormatter(Dispatcher())
ErrorFileHandler.setFormatter(Dispatcher())
# Add handlers to root logger
self.logger.addHandler(DebugFileHandler)
self.logger.addHandler(CommentFileHandler)
self.logger.addHandler(InfoFileHandler)
self.logger.addHandler(WarningFileHandler)
self.logger.addHandler(ErrorFileHandler)
示例3: FilterErr
# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import addFilter [as 别名]
log.addHandler(handler_out)
class FilterErr(logging.Filter):
def filter(self, rec):
return is_error(rec.levelno)
handler_err = logging.StreamHandler(sys.stderr)
handler_err.setFormatter(formatter)
if LOG_LEVEL:
handler_err.setLevel(LOG_LEVEL)
handler_err.addFilter(FilterErr())
log.addHandler(handler_err)
if LOG_LEVEL and LOG_DIR:
try:
os.makedirs(LOG_DIR)
except OSError:
if not os.path.isdir(LOG_DIR):
raise
filename = os.path.basename(sys.argv[0])
if filename.endswith('.py'):
filename = filename[:-3]
filename += '.log'
logfile = os.path.join(LOG_DIR, filename)
file_handler_err = WatchedFileHandler(logfile)
file_handler_err.setFormatter(json_formatter)
file_handler_err.setLevel(LOG_LEVEL)
file_handler_err.addFilter(FilterErr())
log.addHandler(file_handler_err)