0

I am trying to report an error with the Bug4J library. According to their website you should insert inside your log4j.xml file the following directives:

    <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>

I am trying to set the same parameters without a property file however no error is reported in the web console on localhost:8063, so far I tried the following:

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");
 }
}

Any ideas please?

EDIT: Might be related to why nothing is actually reported, if I add:

    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();

I get

 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)
dendini
  • 3,842
  • 9
  • 37
  • 74
  • It's very sad no one can give support for this good product which seems the only one out there capable of reporting remote errors and presenting the developer with a well done web interface and with a simple enough library to make it quickly deployable in a Java application – dendini Apr 15 '13 at 15:31
  • It's a long time, but did you try calling bug4JAgent directly as a test? For us we had issues because we added authentication to the tomcat server hosting bug4j - mistake! – MJB Mar 19 '15 at 23:49
  • I was using Glassfish without any authentication. Guess the product is dead since no one replies on this forum :( – dendini Mar 20 '15 at 08:19
  • Right, but did you run Bug4JAgent itself. Using bug4j.properties. Proabbly a lot easy to test with – MJB Mar 20 '15 at 17:23

1 Answers1

0
  1. you have to "activate the options" on a Log4j appender.

    bug4jAppender.activateOptions();
    
  2. The bug4j agent wants to be non-intrusive so it enqueues the reports and they are processed by a background thread. If your application dies right after it reports an issue you should wait for the background thread to report all the errors that are still in the queue.
    Add the following line at the end of main().

    Bug4jAgent.shutdown();
    
  3. Bug4j can be used with or without log4j. If you use it with log4j then you can setup the agent programatically but you then can forget about it and just report errors using log4j.
    Instead of

    Bug4jAgent.report("Failed to do something", null);
    log.info("Failed to do something");
    

    Just call

    log.error("Failed to do something");
    

In the end you should have something like this:

    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");
    bug4jAppender.activateOptions();

    Logger.getRootLogger().addAppender(bug4jAppender);

    log.error("Failed to do something");
    Bug4jAgent.shutdown();
Cedric
  • 195
  • 4
  • 10
  • I followed your hints but still nothing is sent to the bug4j server. I tried using localhost, 127.0.0.1, or my ip but nothing, I have set the application name equal to the one inside the bug4j server administration section, the package equal to my source file package, the appender name equal to BUG4J. I see no other points of possible mistake – dendini Feb 18 '13 at 11:08