-1

我正在使用log4japi 来维护我的应用程序的日志。我在初始化时使用了以下private Logger logger;

logger = Logger.getLogger("Application Started ");

但它显示Application Started在每个动作中,如下所示:

[ INFO] [2013-08-19 11:50:41,140] AWT-EventQueue-0 Application Started at Mon Aug 19 11:50:33 NPT 2013 (SMSCMainFrame.java:248)- SMSC Setup Panel opened.
[ INFO] [2013-08-19 12:00:15,423] AWT-EventQueue-0 Application Started at Mon Aug 19   12:00:08 NPT 2013 (SMSCMainFrame.java:247)- 
SMSC Setup Panel opened.
[ INFO] [2013-08-19 12:00:17,576] AWT-EventQueue-0 Application Started at Mon Aug 19 12:00:08 NPT 2013 (SMSCMainFrame.java:264)- 
Key messaage setup panel opened.
[ INFO] [2013-08-19 12:00:19,713] AWT-EventQueue-0 Application Started at Mon Aug 19 12:00:08 NPT 2013 (SMSCMainFrame.java:282)- 
Binding details panel opened
[ INFO] [2013-08-19 12:00:21,850] AWT-EventQueue-0 Application Started at Mon Aug 19 12:00:08 NPT 2013 (SMSCMainFrame.java:353)- 
Key Message Details Panel opened
[ INFO] [2013-08-19 12:00:23,093] AWT-EventQueue-0 Application Started at Mon Aug 19 12:00:08 NPT 2013 (SMSCMainFrame.java:371)- 
Blocked Smsc Details panel opened.
[ INFO] [2013-08-19 12:00:24,575] AWT-EventQueue-0 Application Started at Mon Aug 19 12:00:08 NPT 2013 (SMSCMainFrame.java:335)- 
Request response report panel opened.

我只想Application started在我的应用程序启动时显示一次消息。

像 :

[ INFO] [2013-08-19 11:50:41,140] AWT-EventQueue-0 Application Started...

那么只有其他日志应该显示在我的日志文件中。

请帮我。谢谢

4

2 回答 2

1

您需要提供更多代码片段,显示如何logger调用,例如:

logger.info("SMSC Setup Panel opened.");

基本上,每次调用 alogger.info("")时,如果日志级别设置为 ,日志文件中都会有一个日志项INFO

仅显示一项,例如:

[信息] [2013-08-19 11:50:41,140] AWT-EventQueue-0 应用程序已启动...

您可以将日志级别设置为INFO,并通过以下方式调用 logger:

logger.info("application started");
....
if (logger.isDebugEnabled()) logger.debug("xxxxxx");
于 2013-08-19T08:21:37.127 回答
0

to 的参数getLogger是记录器的名称;你告诉它调用 logger Application Started。相反,通常最好使用您的类名(例如,Logger.getLogger(ThisClass.class))。您要做的只是编写一条带有“应用程序已启动”内容的日志消息,因此请在代码的开头执行此操作。

于 2013-08-19T08:10:54.770 回答