本文整理汇总了Python中tornado.log.access_log.warning方法的典型用法代码示例。如果您正苦于以下问题:Python access_log.warning方法的具体用法?Python access_log.warning怎么用?Python access_log.warning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.log.access_log
的用法示例。
在下文中一共展示了access_log.warning方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: log_exception
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def log_exception(self, typ, value, tb):
"""复写来自定义未捕获异常的日志.
默认情况下 `HTTPError` 的日志实例作为警告(warning)没有堆栈追踪(在
``tornado.general`` logger), 其他作为错误(error)的异常带有堆栈
追踪(在 ``tornado.application`` logger).
.. versionadded:: 3.1
"""
if isinstance(value, HTTPError):
if value.log_message:
format = "%d %s: " + value.log_message
args = ([value.status_code, self._request_summary()] +
list(value.args))
gen_log.warning(format, *args)
else:
app_log.error("Uncaught exception %s\n%r", self._request_summary(),
self.request, exc_info=(typ, value, tb))
示例2: log_request
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def log_request(self, handler):
"""写一个完成的HTTP 请求到日志中.
默认情况下会写到python 根(root)logger. 要改变这种行为
无论是子类应用和复写这个方法, 或者传递一个函数到应用的
设置字典中作为 ``log_function``.
"""
if "log_function" in self.settings:
self.settings["log_function"](handler)
return
if handler.get_status() < 400:
log_method = access_log.info
elif handler.get_status() < 500:
log_method = access_log.warning
else:
log_method = access_log.error
request_time = 1000.0 * handler.request.request_time()
log_method("%d %s %.2fms", handler.get_status(),
handler._request_summary(), request_time)
示例3: log_request
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def log_request(self, handler: RequestHandler) -> None:
"""Writes a completed HTTP request to the logs.
By default writes to the python root logger. To change
this behavior either subclass Application and override this method,
or pass a function in the application settings dictionary as
``log_function``.
"""
if "log_function" in self.settings:
self.settings["log_function"](handler)
return
if handler.get_status() < 400:
log_method = access_log.info
elif handler.get_status() < 500:
log_method = access_log.warning
else:
log_method = access_log.error
request_time = 1000.0 * handler.request.request_time()
log_method(
"%d %s %.2fms",
handler.get_status(),
handler._request_summary(),
request_time,
)
示例4: log_exception
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def log_exception(self, typ, value, tb):
"""Override to customize logging of uncaught exceptions.
By default logs instances of `HTTPError` as warnings without
stack traces (on the ``tornado.general`` logger), and all
other exceptions as errors with stack traces (on the
``tornado.application`` logger).
.. versionadded:: 3.1
"""
if isinstance(value, HTTPError):
if value.log_message:
format = "%d %s: " + value.log_message
args = ([value.status_code, self._request_summary()] +
list(value.args))
gen_log.warning(format, *args)
else:
app_log.error("Uncaught exception %s\n%r", self._request_summary(),
self.request, exc_info=(typ, value, tb))
示例5: log_request
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def log_request(self, handler):
"""Writes a completed HTTP request to the logs.
By default writes to the python root logger. To change
this behavior either subclass Application and override this method,
or pass a function in the application settings dictionary as
``log_function``.
"""
if "log_function" in self.settings:
self.settings["log_function"](handler)
return
if handler.get_status() < 400:
log_method = access_log.info
elif handler.get_status() < 500:
log_method = access_log.warning
else:
log_method = access_log.error
request_time = 1000.0 * handler.request.request_time()
log_method("%d %s %.2fms", handler.get_status(),
handler._request_summary(), request_time)
示例6: add_handlers
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def add_handlers(self, host_pattern, host_handlers):
"""添加给定的handler到我们的handler表.
Host 模式将按照它们的添加顺序进行处理.
所有匹配模式将被考虑.
"""
if not host_pattern.endswith("$"):
host_pattern += "$"
handlers = []
# The handlers with the wildcard host_pattern are a special
# case - they're added in the constructor but should have lower
# precedence than the more-precise handlers added later.
# If a wildcard handler group exists, it should always be last
# in the list, so insert new groups just before it.
if self.handlers and self.handlers[-1][0].pattern == '.*$':
self.handlers.insert(-1, (re.compile(host_pattern), handlers))
else:
self.handlers.append((re.compile(host_pattern), handlers))
for spec in host_handlers:
if isinstance(spec, (tuple, list)):
assert len(spec) in (2, 3, 4)
spec = URLSpec(*spec)
handlers.append(spec)
if spec.name:
if spec.name in self.named_handlers:
app_log.warning(
"Multiple handlers named %s; replacing previous value",
spec.name)
self.named_handlers[spec.name] = spec
示例7: _decode_signed_value_v1
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def _decode_signed_value_v1(secret, name, value, max_age_days, clock):
parts = utf8(value).split(b"|")
if len(parts) != 3:
return None
signature = _create_signature_v1(secret, name, parts[0], parts[1])
if not _time_independent_equals(parts[2], signature):
gen_log.warning("Invalid cookie signature %r", value)
return None
timestamp = int(parts[1])
if timestamp < clock() - max_age_days * 86400:
gen_log.warning("Expired cookie %r", value)
return None
if timestamp > clock() + 31 * 86400:
# _cookie_signature does not hash a delimiter between the
# parts of the cookie, so an attacker could transfer trailing
# digits from the payload to the timestamp without altering the
# signature. For backwards compatibility, sanity-check timestamp
# here instead of modifying _cookie_signature.
gen_log.warning("Cookie timestamp in future; possible tampering %r",
value)
return None
if parts[1].startswith(b"0"):
gen_log.warning("Tampered cookie %r", value)
return None
try:
return base64.b64decode(parts[0])
except Exception:
return None
示例8: _log
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def _log(self, status_code, request):
if status_code < 400:
log_method = access_log.info
elif status_code < 500:
log_method = access_log.warning
else:
log_method = access_log.error
request_time = 1000.0 * request.request_time()
summary = request.method + " " + request.uri + " (" + \
request.remote_ip + ")"
log_method("%d %s %.2fms", status_code, summary, request_time)
示例9: log_exception
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def log_exception(
self,
typ: "Optional[Type[BaseException]]",
value: Optional[BaseException],
tb: Optional[TracebackType],
) -> None:
"""Override to customize logging of uncaught exceptions.
By default logs instances of `HTTPError` as warnings without
stack traces (on the ``tornado.general`` logger), and all
other exceptions as errors with stack traces (on the
``tornado.application`` logger).
.. versionadded:: 3.1
"""
if isinstance(value, HTTPError):
if value.log_message:
format = "%d %s: " + value.log_message
args = [value.status_code, self._request_summary()] + list(value.args)
gen_log.warning(format, *args)
else:
app_log.error( # type: ignore
"Uncaught exception %s\n%r",
self._request_summary(),
self.request,
exc_info=(typ, value, tb),
)
示例10: _decode_signed_value_v1
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def _decode_signed_value_v1(
secret: Union[str, bytes],
name: str,
value: bytes,
max_age_days: int,
clock: Callable[[], float],
) -> Optional[bytes]:
parts = utf8(value).split(b"|")
if len(parts) != 3:
return None
signature = _create_signature_v1(secret, name, parts[0], parts[1])
if not hmac.compare_digest(parts[2], signature):
gen_log.warning("Invalid cookie signature %r", value)
return None
timestamp = int(parts[1])
if timestamp < clock() - max_age_days * 86400:
gen_log.warning("Expired cookie %r", value)
return None
if timestamp > clock() + 31 * 86400:
# _cookie_signature does not hash a delimiter between the
# parts of the cookie, so an attacker could transfer trailing
# digits from the payload to the timestamp without altering the
# signature. For backwards compatibility, sanity-check timestamp
# here instead of modifying _cookie_signature.
gen_log.warning("Cookie timestamp in future; possible tampering %r", value)
return None
if parts[1].startswith(b"0"):
gen_log.warning("Tampered cookie %r", value)
return None
try:
return base64.b64decode(parts[0])
except Exception:
return None
示例11: _log
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def _log(self, status_code: int, request: httputil.HTTPServerRequest) -> None:
if status_code < 400:
log_method = access_log.info
elif status_code < 500:
log_method = access_log.warning
else:
log_method = access_log.error
request_time = 1000.0 * request.request_time()
assert request.method is not None
assert request.uri is not None
summary = request.method + " " + request.uri + " (" + request.remote_ip + ")"
log_method("%d %s %.2fms", status_code, summary, request_time)
示例12: decode_signed_value
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def decode_signed_value(secret, name, value, max_age_days=31):
if not value:
return None
parts = utf8(value).split(b"|")
if len(parts) != 3:
return None
signature = _create_signature(secret, name, parts[0], parts[1])
if not _time_independent_equals(parts[2], signature):
gen_log.warning("Invalid cookie signature %r", value)
return None
timestamp = int(parts[1])
if timestamp < time.time() - max_age_days * 86400:
gen_log.warning("Expired cookie %r", value)
return None
if timestamp > time.time() + 31 * 86400:
# _cookie_signature does not hash a delimiter between the
# parts of the cookie, so an attacker could transfer trailing
# digits from the payload to the timestamp without altering the
# signature. For backwards compatibility, sanity-check timestamp
# here instead of modifying _cookie_signature.
gen_log.warning("Cookie timestamp in future; possible tampering %r", value)
return None
if parts[1].startswith(b"0"):
gen_log.warning("Tampered cookie %r", value)
return None
try:
return base64.b64decode(parts[0])
except Exception:
return None
示例13: log_request
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def log_request(handler):
try:
request = handler.request
location_info = referer_info = user_agent_info = ''
status_code = handler.get_status()
if status_code < 400:
log_method = access_log.info
if status_code in (301, 302, 307):
location = handler._headers.get('Location')
if location:
location_info = '\n\tLocation: ' + location
elif status_code < 500:
log_method = access_log.warning
headers = request.headers
referer = headers.get('Referer')
if referer:
referer = referer.replace('"', '')
referer_info = '\n\tReferer url: ' + referer
user_agent = headers.get('User-Agent')
if user_agent:
user_agent = user_agent.replace('"', '')
user_agent_info = '\n\tUser agent: ' + user_agent
else:
log_method = access_log.error
request_time = request.request_time()
log_method("%d %s %.2fms%s%s%s", status_code,
handler._request_summary(), request_time * 1000.0,
location_info, referer_info, user_agent_info)
except Exception:
logging.exception('failed to log request')
示例14: _log
# 需要导入模块: from tornado.log import access_log [as 别名]
# 或者: from tornado.log.access_log import warning [as 别名]
def _log(self, status_code, request):
if status_code < 400:
log_method = access_log.info
elif status_code < 500:
log_method = access_log.warning
else:
log_method = access_log.error
timestamp = ut.timestamp()
request_time = 1000.0 * request.request_time()
log_method(
"WALL=%s STATUS=%s METHOD=%s URL=%s IP=%s TIME=%.2fms",
timestamp,
status_code, request.method,
request.uri, request.remote_ip, request_time)