本文整理匯總了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