Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log4j log output written both in a file AND in a frame.

Status
Not open for further replies.

celia05es

Programmer
Jan 10, 2002
81
US
Hello,
I am quite new with swing and log4j so please bear with me.
I have an swing application within a jar file.
I have two questions:
1. How can I have the log4j log output written in a frame (separated from the main frame).
I also would like to have the log4j log output written in a file which has to be located on the user PC because the jar file will be executed from the user PC.
2. I am having problem dynamically changing the logging level (it simply does not work).... I am using the configure() method but it might not be the best one since I would like to use the log4j.properties file... though reading the tutorial, I found a lot of things but I only want to be able to read from a property file in a standalone swing application... and I haven't found how.

Could you help me please?

The main.java is :
Code:
....
import org.apache.log4j.*;

....
public class Main extends JFrame
{ 
    ...
   static Logger logger = Logger.getLogger(Main.class.getName());
   ...
  public static void main(String[] args)
  {
    BasicConfigurator.configure();

    logger.debug("Entering in main...");
    Main application = new Main();
    application.show();
  }

  public Main()
  {
    super();
    logger.debug("Entering in Main ...");
    initialize();
  }

  private void initialize()
  {
    logger.debug("Entering Main.initialize...");
    this.setSize(800,600);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setContentPane(getJContentPane());
    this.setTitle("APPLICATION TITLE");

    .....

     System.out.println("current logging level="+logger.getLevel());  ==> NULL!!

if (logger.getLevel() == null)
       logger.setLevel(Level.FATAL);


     logger.debug("DEBUG TEST"); <== WRITTEN THOUGH FATAL!!
     logger.info("INFO TEST");
....
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top