java - 如何在 tomcat 访问日志中记录线程上下文值

标签 java tomcat logging

我已使用 %X 模式成功在应用程序日志中记录线程上下文值。现在,我想在 tomcat 访问日志 tomcat 中记录相同的值。有什么模式可以记录吗?

最佳答案

恐怕您无法在访问日志中记录线程上下文。

以下是可用选项:

%a - Remote IP address
%A - Local IP address
%b - Bytes sent, excluding HTTP headers, or '-' if zero
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if enableLookups for the connector is false)
%H - Request protocol
%l - Remote logical username from identd (always returns '-')
%m - Request method (GET, POST, etc.)
%p - Local port on which this request was received. See also %{xxx}p below.
%q - Query string (prepended with a '?' if it exists)
%r - First line of the request (method and request URI)
%s - HTTP status code of the response
%S - User session ID
%t - Date and time, in Common Log Format
%u - Remote user that was authenticated (if any), else '-'
%U - Requested URL path
%v - Local server name
%D - Time taken to process the request, in millis
%T - Time taken to process the request, in seconds
%F - Time taken to commit the response, in millis
%I - Current request thread name (can compare later with stacktraces)

据我所知,您唯一能做的就是记录当前线程名称(%I),然后在应用程序日志中查找它以获取其上下文信息。

关于java - 如何在 tomcat 访问日志中记录线程上下文值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32863538/

相关文章:

logging - Elasticsearch:无法导入记录器(答案适用于其他导入)

java - 如何提供跨平台、异步的服务接口(interface)

java - 用于定义值的 JSF 复合属性

java - 在 Hibernate 5、Tomcat 8 中配置数据源

java - MySQL 语句取消计时器未能停止

windows - 确定哪个用户重新启动了 Windows 服务器

java - 一个类可以在java中实例化为静态吗?

java - kie workbench 6.2.0.CR2安装程序无法启动: Unsatisfied dependencies

python - 通过 HTTP 调用 python 脚本

python - Spyder IDE 中的重复日志条目和锁定的日志文件