本文整理汇总了Python中neubot.log.LOG.listify方法的典型用法代码示例。如果您正苦于以下问题:Python LOG.listify方法的具体用法?Python LOG.listify怎么用?Python LOG.listify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.log.LOG
的用法示例。
在下文中一共展示了LOG.listify方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: log_api
# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import listify [as 别名]
def log_api(stream, request, query):
''' Implements /api/log '''
# Get logs and options
logs = LOG.listify()
options = cgi.parse_qs(query)
# Reverse logs on request
if utils.intify(options.get('reversed', ['0'])[0]):
logs = reversed(logs)
# Filter according to verbosity
if utils.intify(options.get('verbosity', ['1'])[0]) < 2:
logs = [ log for log in logs if log['severity'] != 'DEBUG' ]
if utils.intify(options.get('verbosity', ['1'])[0]) < 1:
logs = [ log for log in logs if log['severity'] != 'INFO' ]
# Human-readable output?
if utils.intify(options.get('debug', ['0'])[0]):
logs = [ '%(timestamp)d [%(severity)s]\t%(message)s\r\n' % log
for log in logs ]
body = ''.join(logs).encode('utf-8')
mimetype = 'text/plain; encoding=utf-8'
else:
body = json.dumps(logs)
mimetype = 'application/json'
# Compose and send response
response = Message()
response.compose(code='200', reason='Ok', body=body, mimetype=mimetype)
stream.send_response(request, response)
示例2: _api_log
# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import listify [as 别名]
def _api_log(self, stream, request, query):
response = Message()
dictionary = cgi.parse_qs(query)
if "debug" in dictionary and utils.intify(dictionary["debug"][0]):
stringio = StringIO.StringIO()
for row in LOG.listify():
ln = "%d [%s]\t%s" % (row["timestamp"], row["severity"],
row["message"])
stringio.write(ln.encode("utf-8"))
stringio.write("\r\n")
stringio.seek(0)
mimetype = "text/plain"
else:
s = json.dumps(LOG.listify())
stringio = StringIO.StringIO(s)
mimetype = "application/json"
response.compose(code="200", reason="Ok", body=stringio,
mimetype=mimetype)
stream.send_response(request, response)
示例3: log_api
# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import listify [as 别名]
def log_api(stream, request, query):
''' Implements /api/log '''
#
# CAVEAT Currently Neubot do not update logs "in real
# time" using AJAX. If it did we would run in trouble
# because each request for /api/log would generate a
# new access log record. In turn, a new access log
# record will cause a new "logwritten" event, leading
# to a log-caused Comet storm.
#
# Get logs and options
logs = LOG.listify()
options = cgi.parse_qs(query)
# Reverse logs on request
if utils.intify(options.get('reversed', ['0'])[0]):
logs = reversed(logs)
# Filter according to verbosity
if utils.intify(options.get('verbosity', ['1'])[0]) < 2:
logs = [ log for log in logs if log['severity'] != 'DEBUG' ]
if utils.intify(options.get('verbosity', ['1'])[0]) < 1:
logs = [ log for log in logs if log['severity'] != 'INFO' ]
# Human-readable output?
if utils.intify(options.get('debug', ['0'])[0]):
logs = [ '%(timestamp)d [%(severity)s]\t%(message)s\r\n' % log
for log in logs ]
body = ''.join(logs).encode('utf-8')
mimetype = 'text/plain; encoding=utf-8'
else:
body = json.dumps(logs)
mimetype = 'application/json'
# Compose and send response
response = Message()
response.compose(code='200', reason='Ok', body=body, mimetype=mimetype)
stream.send_response(request, response)
示例4: Exception
# 需要导入模块: from neubot.log import LOG [as 别名]
# 或者: from neubot.log.LOG import listify [as 别名]
import sys
if __name__ == "__main__":
sys.path.insert(0, ".")
from neubot.log import LOG, oops
from neubot import compat
if __name__ == "__main__":
logging.info("INFO w/ logging.info")
logging.debug("DEBUG w/ logging.debug")
logging.warning("WARNING w/ logging.warning")
logging.error("ERROR w/ logging.error")
print compat.json.dumps(LOG.listify())
access_logger = logging.getLogger('access')
access_logger.info('Test access logger')
try:
raise Exception("Testing exc_info")
except (KeyboardInterrupt, SystemExit):
raise
except:
logging.error('EXCEPTION', exc_info=1)
oops("Testing the new oops feature")
# Testing variadic args
logging.warning("WARNING %s", "variadic warning")