def log_message(self, log_obj):
"""
Attached to the `go:log` WebSocket action; logs the given *log_obj* via
:meth:`ApplicationWebSocket.client_log`. The *log_obj* should be a
dict (JSON object, really) in the following format::
{
"level": "info", # Optional
"message": "Actual log message here"
}
If a "level" is not given the "info" level will be used.
*Supported Levels:* "info", "error", "warning", "debug", "fatal",
"critical".
.. note::
The "critical" and "fatal" log levels both use the
`logging.Logger.critical` method.
"""
if not self.current_user:
return # Don't let unauthenticated users log messages.
# NOTE: We're not using the authenticated() check here so we don't
# end up logging a zillion error messages when an unauthenticated
# user's client has debug logging enabled.
if "message" not in log_obj:
return # Nothing to do
log_obj["level"] = log_obj.get("level", "info") # Default to "info"
loggers = {
"info": self.client_log.info,
"warning": self.client_log.warning,
"error": self.client_log.error,
"debug": self.client_log.debug,
"fatal": self.client_log.critical, # Python doesn't use "fatal"
"critical": self.client_log.critical,
}
if isinstance(log_obj["message"], bytes):
log_msg = log_obj["message"]
else:
log_msg = log_obj["message"].encode('utf-8')
loggers[log_obj["level"].lower()](
"Client Logging: {0}".format(log_msg))
评论列表
文章目录