首页 > 解决方案 > 如何为 AsyncNCSARequestLog 设置日志区域设置和延迟

问题描述

虽然AsyncNCSARequestLog已弃用,但我应该将其替换为CustomRequestLog.

代码是:

AsyncNCSARequestLog log = new AsyncNCSARequestLog(filename);
log.setAppend(true);
log.setLogLatency(true);
log.setRetainDays(retainDays);
log.setLogLocale(Locale.ENGLISH);

应该是:

AsyncRequestLogWriter writer = new AsyncRequestLogWriter(filename, new BlockingArrayQueue<>(size));
writer.setAppend(true);
writer.setRetainDays(retainDays);
CustomRequestLog log = new CustomRequestLog(writer, CustomRequestLog.EXTENDED_NCSA_FORMAT);

但是没有为CustomRequestLogor设置日志区域设置和延迟的选项AsyncRequestLogWriter。我该如何设置它们?

更新:

以下设置消失了:

AsyncNCSARequestLog log = new AsyncNCSARequestLog(filename, new BlockingArrayQueue<>());
log.setLogDateFormat(format);
log.setExtended(true);
log.setLogLocale(Locale.ENGLISH);
log.setLogCookies(true);
log.setLogLatency(true);
log.setLogServer(true);

标签: javaloggingjetty

解决方案


这些都记录在CustomRequestLog 的 apidocs 中

语言环境仅用于“时间”表示。

这是在格式参数中指定的。

看:%{format|timeZone|locale}t

延迟也是一个格式参数。

看:

  • %D以微秒为单位的延迟
  • %T以秒为单位的延迟
  • %{UNIT}T对于您自己想要的单位的延迟
    • %msT是毫秒
    • %usT是微秒
    • %sT是秒

您将希望使用自定义格式参数,而不是预定义的标准格式CustomRequestLog.EXTENDED_NCSA_FORMAT(它永远不会有延迟,并且总是使用Locale.getDefault()它的时间表示)


推荐阅读