我正在尝试报告 Bug4J 库的错误。根据他们的网站,您应该在 log4j.xml 文件中插入以下指令:
<appender name="bug4j" class="org.bug4j.client.Bug4jAppender">
<param name="serverUrl" value="http://<bug4j.host.name>:8063/"/>
<param name="applicationName" value="My Application"/>
<param name="applicationVersion" value="1.3"/>
</appender>
我正在尝试在没有属性文件的情况下设置相同的参数,但是在 localhost:8063 上的 Web 控制台中没有报告错误,到目前为止,我尝试了以下操作:
public TestClass
{
static Logger log = Logger.getLogger(TestClass.class);
TestClass()
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.INFO);
Bug4jAppender bug4jAppender = new Bug4jAppender();
bug4jAppender.setName("BUG4J");
bug4jAppender.setServerUrl("http://localhost:8063/");
bug4jAppender.setApplicationName("testapp");
bug4jAppender.setApplicationVersion("1.9");
Logger.getRootLogger().addAppender(bug4jAppender);
log.addAppender(bug4jAppender);
Bug4jAgent.report("Failed to do something", null);
log.info("Failed to do something");
}
}
请问有什么想法吗?
编辑:可能与为什么实际上没有报告任何内容有关,如果我添加:
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.INFO);
Bug4jAppender bug4jAppender = new Bug4jAppender();
bug4jAppender.setName("BUG4J");
bug4jAppender.setServerUrl("http://127.0.0.1:8063/");
bug4jAppender.setApplicationName("testapp");
bug4jAppender.setApplicationVersion("1.9");
bug4jAppender.activateOptions();
Logger.getRootLogger().addAppender(bug4jAppender);
//Bug4jAgent.report("Failed to do something", null);
log.warn("Failed to do something");
Bug4jAgent.shutdown();
我明白了
Exception in thread "main" java.lang.NullPointerException
at org.bug4j.client.Bug4jAppender.append(Bug4jAppender.java:48)
at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
at org.apache.log4j.Category.callAppenders(Category.java:206)
at org.apache.log4j.Category.forcedLog(Category.java:391)
at org.apache.log4j.Category.warn(Category.java:1043)
at testapp.Main.<init>(Main.java:118)
at testapp.Main.main(Main.java:837)