[英]How can i get URL,IP Address & java Class details from error log
I am working on a big project in struts. 我正在struts中进行一个大项目。 In that for logging purpose we have used log4j1.2.12 出于记录目的,我们使用了log4j1.2.12
I want that when any exception occur from code,i want following details from/of the exceptions : URL(from which exception occurs) with parameters,IP Address(from which IP my request is placed),Time Stamp,Java Class Name,Java Method Name, as well as Struts Action Name. 我希望当代码中发生任何异常时,我想从异常中了解异常的详细信息:URL(发生异常的原因)和参数,IP地址(我的请求所来自的IP),时间戳,Java类名,Java方法名称,以及Struts操作名称。
In my whole code, in every java file, i have used try-catch-finally. 在我的整个代码中,在每个java文件中,我都使用了try-catch-finally。
public static final Logger log = Logger.getLogger(xyz.class);
try{
//My Code
} catch(Exception e) {
log.error("Exception Message :", e);
}
which only writes the exception details but not my required details then How can i achieve my goal? 仅写异常详细信息,而不写我的必需详细信息,然后我该如何实现我的目标?
Note: Our project has over 2000 java files in which try-catch-finally comes... So, i cant manually change/edit/modify my code in every java file. 注意:我们的项目有2000多个Java文件,其中try-catch-finally最终会出现...因此,我无法在每个Java文件中手动更改/编辑/修改我的代码。
I will appreciate your all suggestions. 我将感谢您的所有建议。
Thanks in advance. 提前致谢。
Have a look at the PatternLayout and how to set up a Configrataion-File . 看一下PatternLayout以及如何设置Configrataion-File 。 Add conversion Characters to get the value you want. 添加转换字符以获得所需的值。 For Example: 例如:
%d{yyy-MM-dd_HH:mm:ss,SSS} for a full date %d {yyy-MM-dd_HH:mm:ss,SSS}(完整日期)
%l for the full qualified calling method name. %l为完整的合格调用方法名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.