I have a application that write a log file to .log. But now i make a html jar file to implement to the application (1 log per request). The problem is when 2 or more thread running at the same time, the html log is mixed up.
我有一个将日志文件写入.log的应用程序。但现在我创建一个html jar文件来实现应用程序(每个请求1个日志)。问题是当2个或更多线程同时运行时,html日志会混淆。
Example: aaa.log and bbb.log
示例:aaa.log和bbb.log
aaa.log content contain bbb.log content vice versa
aaa.log内容包含bbb.log内容,反之亦然
how to make it separate log file with own content.
如何使用自己的内容使其成为单独的日志文件。
ctx.htmllogger = new HTMLLogger(
ctx.control.getCodeValue(),
ctx.AvailRequest.getTrip().getSegmentProductType()
.getCodeValue(), ctx.OPT_TYPE);
String htmllogdir = System.getProperty("user.dir");
htmllogdir = htmllogs + "\" + ctx.htmllogger.getCurrentTS( "ddMMyyyy" ) + "\" + ctx.OPT_TYPE.toLowerCase();
ctx.htmllogger.MakeDirectories( htmllogdir );
try {
ctx.htmllogger.initLogger(DlgKuoni.class.getCanonicalName(), htmllogdir);
} catch (IOException e) {
ctx.htmllogger = null;
e.printStackTrace();
}
ctx.htmllogger.startHTMLLog();
Appreciated who help me.
感谢谁帮助我。
2 个解决方案
#1
2
You should take a look at log4j (and maybe self4j). There is really no need th handle these things on your own. That can all be configured with log4j, including html-formatter etc.
你应该看看log4j(也许是self4j)。真的没有必要自己处理这些事情。这些都可以用log4j配置,包括html-formatter等。
#2
0
This is happening because you have a bug in your program. Most likely you have a global/shared variable used by both threads to access the log.
发生这种情况是因为您的程序中存在错误。很可能您有两个线程用来访问日志的全局/共享变量。
I suggest you have a resource for your log which is visible to only one thread at a time. This avoids the chance for confusion.
我建议你有一个日志资源,一次只能看到一个线程。这避免了混淆的可能性。
#1
2
You should take a look at log4j (and maybe self4j). There is really no need th handle these things on your own. That can all be configured with log4j, including html-formatter etc.
你应该看看log4j(也许是self4j)。真的没有必要自己处理这些事情。这些都可以用log4j配置,包括html-formatter等。
#2
0
This is happening because you have a bug in your program. Most likely you have a global/shared variable used by both threads to access the log.
发生这种情况是因为您的程序中存在错误。很可能您有两个线程用来访问日志的全局/共享变量。
I suggest you have a resource for your log which is visible to only one thread at a time. This avoids the chance for confusion.
我建议你有一个日志资源,一次只能看到一个线程。这避免了混淆的可能性。