title: Log4J not working properly?
body: <p>I am new to Log4J. i am trying to get this logger to work. i downloaded the .JAR file and I have built that into the Referenced Libraries and can open the folder and see it in there. So I think it is built into my project.</p>
  
  <p>I think that I am missing how to declare the logger so that i can use it below. Some of the code I got from stackoverflow. </p>
  
  <p><strong>Question: Which part of the Log4J declaration am I missing so that I can use it as a logger in my simple example?</strong></p>
  
  <p>Code:</p>
  
  <pre><code>import java.io.*;
  import java.util.logging.FileHandler;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import java.awt.*;
  import java.awt.event.*;
  
  import javax.swing.*;
  
  public class TestLogs {
      private static Logger logger = Logger.getLogger(FileChooserDemo.class.getName());
  
      FileHandler fh;   
  
      public TestLogs() {
          try {
              UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
              fh = new FileHandler("C:\\Users\\itpr13266\\Desktop\\MyNewLogFile.log");   
              logger.addHandler(fh);
              logger.info("Logging an INFO-level message");
              logger.warning("Your file cannot be written!!");
          } catch (Exception ex) {
              Logger.getLogger(FileChooserDemo.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  
      private void LogTester() {
           Logger.getRootLogger().getLoggerRepository().resetConfiguration();
           ConsoleAppender console = new ConsoleAppender(); //create appender
            //configure the appender
            String PATTERN = "%d [%p|%c|%C{1}] %m%n";
            console.setLayout(new PatternLayout(PATTERN)); 
            console.setThreshold(Level.FATAL);
            console.activateOptions();
            //add appender to any Logger (here is root)
            Logger.getRootLogger().addAppender(console);
  
            FileAppender fa = new FileAppender();
            fa.setName("FileLogger");
            fa.setFile("mylog.log");
            fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
            fa.setThreshold(Level.DEBUG);
            fa.setAppend(true);
            fa.activateOptions();
  
            //add appender to any Logger (here is root)
            Logger.getRootLogger().addAppender(fa)    
      }
  
      public static void main(String[] args) {
         TestLogs tls = new TestLogs();
         tls.LogTester();
       }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/hUUmt.jpg" alt="enter image description here"></p>
  
  <p>new image- I rebuilt the paths and it put them in a slightly different position in the file structure. But the error still persists.</p>
  
  <p><img src="https://i.stack.imgur.com/WAqR1.jpg" alt="enter image description here"></p>
  
  <p>Code that works --- But how do I log it to a text file on my computer.</p>
  
  <pre><code>package TestMenu;
  
  import org.apache.log4j.*;
  
  import javax.swing.*;
  
  public class TestLogs {
      private static Logger logger = Logger.getLogger(TestLogs.class.getName());
  
      public TestLogs() {
          try {
              UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
          } catch (Exception ex) {
          }
      }
  
      private void LogTester() {
           logger.info("It works");
           TestLogs tls = new TestLogs();
      }
  
      public static void main(String[] args) {
         TestLogs tls = new TestLogs();
         tls.LogTester();
       }
  }
  </code></pre>
  
  <p>At least the log4j is working but how to change the properties file around so that I can log all warnings, info and to a file not to the console?</p>
  
  <p>Log4j Properties:</p>
  
  <pre><code># Root logger option
  log4j.rootLogger=INFO, stdout
  
  # Direct log messages to stdout
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target=System.out
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
  </code></pre>
  
  <p>new image -- not working -- error shown on bottom</p>
  
  <p><img src="https://i.stack.imgur.com/7akJN.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/oAznj.jpg" alt="enter image description here"></p>
  
  <p>Errors:</p>
  
  <pre><code>log4j:WARN No appenders could be found for logger (TestMenu.TestLogs).
  log4j:WARN Please initialize the log4j system properly.
  log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/GkFGx.jpg" alt="enter image description here"></p>