在web应用中使用 logback, log4j 打印request中的相关信息
2016-05-29 17:17
465 查看
** 这里使用的一个技巧是修改thread的名字,然后通过日志格式配置输出线程的名字
在web应用中使用 logback, log4j 打印request中的相关信息
在日志配置文件中打印出thread的信息,这个是关键
在web应用中使用 logback, log4j 打印request中的相关信息
String method = request.getMethod(); String path = request.getRequestURI(); String queryString = request.getQueryString(); if (queryString != null) { path = path + '?' + queryString; } Thread thread = Thread.currentThread(); String threadName = thread.getName(); String newThreadName = threadName + " - " + remoteAddr + " - " + method + " - " + path + " - " + sessionId; thread.setName(newThreadName); //这句是关键
在日志配置文件中打印出thread的信息,这个是关键
[%thread]
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender>
相关文章推荐
- Duilib学习总结
- UIKit框架之——UILabel
- 2.5 UI组件-AdapterView及子类(疯狂android学习笔记)
- QuickHit游戏
- 05章项目: QuickHit快速击键
- 算法思想系列--分治策略(Divide-Conquer-Combine)(待补充)
- SAPUI5 学习笔记(1)
- 1976 Queen数列
- android与arduino手机控制项目开源
- 浅谈arduino与android通信
- arduino 大小端数据问题
- Introduction of Algorithm - Divide and Conquer(分治法)
- SGU-181 X-Sequence
- iOS AutoLayout: 关联 Xib 和 UIViewController
- X-Sequence
- 【Android UI】图片 + 文字展示by SpannableStringBuilder
- iOS开发中的UDID和UUID详解
- hadoop key和value 分隔符号设置
- windows GUI开发00 - 前言
- Repeated DNA Sequences