• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Need help for Log4j 1.2 used in a standalone application

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    Alex Yx Ng
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I'm stuck.
    Nobody could give me some help?
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hello!

    You don't modify your log4j.properties!
    If you must change your pattern layout, you modify
     
    He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic