本文整理汇总了Python中tornado.log.LogFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python log.LogFormatter方法的具体用法?Python log.LogFormatter怎么用?Python log.LogFormatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.log
的用法示例。
在下文中一共展示了log.LogFormatter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import LogFormatter [as 别名]
def setUp(self):
self.formatter = LogFormatter(color=False)
# Fake color support. We can't guarantee anything about the $TERM
# variable when the tests are run, so just patch in some values
# for testing. (testing with color off fails to expose some potential
# encoding issues from the control characters)
self.formatter._colors = {
logging.ERROR: u("\u0001"),
}
self.formatter._normal = u("\u0002")
# construct a Logger directly to bypass getLogger's caching
self.logger = logging.Logger('LogFormatterTest')
self.logger.propagate = False
self.tempdir = tempfile.mkdtemp()
self.filename = os.path.join(self.tempdir, 'log.out')
self.handler = self.make_handler(self.filename)
self.handler.setFormatter(self.formatter)
self.logger.addHandler(self.handler)
示例2: setUp
# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import LogFormatter [as 别名]
def setUp(self):
self.formatter = LogFormatter(color=False)
# Fake color support. We can't guarantee anything about the $TERM
# variable when the tests are run, so just patch in some values
# for testing. (testing with color off fails to expose some potential
# encoding issues from the control characters)
self.formatter._colors = {logging.ERROR: u"\u0001"}
self.formatter._normal = u"\u0002"
# construct a Logger directly to bypass getLogger's caching
self.logger = logging.Logger("LogFormatterTest")
self.logger.propagate = False
self.tempdir = tempfile.mkdtemp()
self.filename = os.path.join(self.tempdir, "log.out")
self.handler = self.make_handler(self.filename)
self.handler.setFormatter(self.formatter)
self.logger.addHandler(self.handler)
示例3: setUp
# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import LogFormatter [as 别名]
def setUp(self):
self.formatter = LogFormatter(color=False)
# Fake color support. We can't guarantee anything about the $TERM
# variable when the tests are run, so just patch in some values
# for testing. (testing with color off fails to expose some potential
# encoding issues from the control characters)
self.formatter._colors = {
logging.ERROR: u("\u0001"),
}
self.formatter._normal = u("\u0002")
self.formatter._color = True
# construct a Logger directly to bypass getLogger's caching
self.logger = logging.Logger('LogFormatterTest')
self.logger.propagate = False
self.tempdir = tempfile.mkdtemp()
self.filename = os.path.join(self.tempdir, 'log.out')
self.handler = self.make_handler(self.filename)
self.handler.setFormatter(self.formatter)
self.logger.addHandler(self.handler)
示例4: setUp
# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import LogFormatter [as 别名]
def setUp(self):
self.formatter = LogFormatter(color=False)
# Fake color support. We can't guarantee anything about the $TERM
# variable when the tests are run, so just patch in some values
# for testing. (testing with color off fails to expose some potential
# encoding issues from the control characters)
self.formatter._colors = {
logging.ERROR: u"\u0001",
}
self.formatter._normal = u"\u0002"
# construct a Logger directly to bypass getLogger's caching
self.logger = logging.Logger('LogFormatterTest')
self.logger.propagate = False
self.tempdir = tempfile.mkdtemp()
self.filename = os.path.join(self.tempdir, 'log.out')
self.handler = self.make_handler(self.filename)
self.handler.setFormatter(self.formatter)
self.logger.addHandler(self.handler)
示例5: enable_pretty_logging
# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import LogFormatter [as 别名]
def enable_pretty_logging(options=None, logger=None):
if options is None:
from tornado.options import options
if options.logging is None or options.logging.lower() == 'none':
return
if logger is None:
logger = logging.getLogger()
logger.setLevel(getattr(logging, options.logging.upper()))
if options.log_file_prefix:
rotate_mode = options.log_rotate_mode
if rotate_mode == 'size':
channel = logging.handlers.RotatingFileHandler(
filename=options.log_file_prefix,
maxBytes=options.log_file_max_size,
backupCount=options.log_file_num_backups)
elif rotate_mode == 'time':
channel = logging.handlers.TimedRotatingFileHandler(
filename=options.log_file_prefix,
when=options.log_rotate_when,
interval=options.log_rotate_interval,
backupCount=options.log_file_num_backups)
else:
error_message = 'The value of log_rotate_mode option should be ' + \
'"size" or "time", not "%s".' % rotate_mode
raise ValueError(error_message)
channel.setFormatter(LogFormatter(color=False))
logger.addHandler(channel)
if (options.log_to_stderr or
(options.log_to_stderr is None and not logger.handlers)):
# Set up color if we are in a tty and curses is installed
channel = logging.StreamHandler()
channel.setFormatter(LogFormatter())
logger.addHandler(channel)
示例6: _setup_logging
# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import LogFormatter [as 别名]
def _setup_logging(self):
logger.setLevel(logging.INFO)
channel = logging.StreamHandler()
channel.setFormatter(LogFormatter())
logger.addHandler(channel)
# need a tornado logging handler to prevent IOLoop._setup_logging
logging.getLogger('tornado').addHandler(channel)
示例7: initLogger
# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import LogFormatter [as 别名]
def initLogger(log_level='debug', log_path=None, logfile_name=None):
""" 初始化日志输出
@param log_level 日志级别 debug info
@param log_path 日志输出路径
@param logfile_name 日志文件名
"""
if log_level == 'info':
options.logging = 'info'
else:
options.logging = 'debug'
logger = logging.getLogger()
if logfile_name:
if not os.path.isdir(log_path):
os.makedirs(log_path)
logfile = os.path.join(log_path, logfile_name)
print('init logger ...:', logfile)
handler = logging.handlers.TimedRotatingFileHandler(
logfile, 'midnight')
else:
handler = logging.StreamHandler()
fmt_str = '%(levelname)1.1s [%(asctime)s] %(message)s'
fmt = log.LogFormatter(fmt=fmt_str, datefmt=None)
handler.setFormatter(fmt)
logger.addHandler(handler)
示例8: capture_log
# 需要导入模块: from tornado import log [as 别名]
# 或者: from tornado.log import LogFormatter [as 别名]
def capture_log(app, fmt="[%(levelname)s] %(message)s"):
"""Adds an extra handler to the given application the logs to a string
buffer, calls ``app.start()``, and returns the log output. The extra
handler is removed from the application before returning.
Arguments
---------
app: LoggingConfigurable
An application, withh the `.start()` method implemented
fmt: string
A format string for formatting log messages
Returns
-------
A dictionary with the following keys (error and log may or may not be present):
- success (bool): whether or not the operation completed successfully
- error (string): formatted traceback
- log (string): captured log output
"""
log_buff = io.StringIO()
handler = logging.StreamHandler(log_buff)
formatter = LogFormatter(fmt="[%(levelname)s] %(message)s")
handler.setFormatter(formatter)
app.log.addHandler(handler)
try:
app.start()
except:
log_buff.flush()
val = log_buff.getvalue()
result = {"success": False}
result["error"] = traceback.format_exc()
if val:
result["log"] = val
else:
log_buff.flush()
val = log_buff.getvalue()
result = {"success": True}
if val:
result["log"] = val
finally:
log_buff.close()
app.log.removeHandler(handler)
return result