This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.

Alex Yx Ng

Greenhorn
+ Follow
since Jun 06, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Alex Yx Ng

Hi guys,

I am building a standalone application and I'd like to use log4j 1.2 to append logs from different classes to a JTextarea, some of you might say this is not ideal because this would couple the UI and low level logging together, but this application is simply a practice, and I'd like to try all kinds of approach.

I have created some test class outside the application just to test log4j before I put it into the actual app, these are the codes what I have done,

UI class


Hello class


The custom appender



log4j.properties file which I have put under resources folder, same level as src folder



problems I have now and I dont know how to resolve as following,
  • If I run the UI class like these, I would get a NullPointException and only the first log would be logged both into the text area and eclipse console
  • The PropertyConfigurator doesnot configure layout properly if I changed the requiresLayout method in JTextArea to return true, it'd be null, I believe that'd be the reason I am getting NPE, but I am so confused about how I could resolve this
  • If I changed this line "log4j.rootLogger=INFO, stdout, textarea" in the property file to "log4j.rootLogger=textarea", all testing log can be appended to textarea but the console prompts the following error msg - log4j:WARN No appenders could be found for logger (testing.Hello).
    log4j:WARN Please initialize the log4j system properly.
  • If I add the Help logger to configuration file as changing the line to "log4j.rootLogger=INFO, stdout, textarea, Help" then add all layout and ConversionPattern lines for logger Help, it gives me NPE


  • What I want to achieve is, all logs in different classes should be able to be appended to textarea properly, using log4j.properties for configuration. I have been trying for days, since I work long hours during the day and only be able to work on my project at nights. Any help for these matters would be greatly appreciated.