use log4j - can see the output from the console but not found the log file.

As advised from object, I used log4j. yes. this is cool.

It displays the INFO message to console, but i can't find the physical file i specified in the program.

See my code below:


public class Scheduler extends MailUtilities implements EvtConfig {

  static Logger schedulerLogger = Logger.getLogger("scheduler.log");
  Appender      schedulerAppender;
  SimpleLayout  schedulerLayout;
 
  public static void main(String[] args) {
     try {
       int dbConnOk = Utilities.SQLJdbConnection(userName, pwd, dbName );
       if ( dbConnOk == 0 ) {
           new Scheduler();
       }
       else {
         System.exit(1);
       }
     }  
     catch (Exception e) {
       System.out.println("Scheduler.main() : Errro occured due to " + e);
       e.printStackTrace();
       System.exit(1);            
     }
  } // main

  private Scheduler() throws Exception  {
    /* Log layout handler */
    schedulerLogger.setLevel(Level.INFO);
    schedulerLayout   = new SimpleLayout();
    schedulerAppender = new ConsoleAppender(schedulerLayout);
    schedulerLogger.addAppender(schedulerAppender);
    //
    schedulerLogger.info("UTeventScheduler: START");  

<=== I can see the above message in the console, but CAN'T FIND the scheduler.log file


 }


==========================
Please advise if I have missed out something.
Thanks
LeanMoreTryMoreAsked:
Who is Participating?
 
objectsCommented:
It shouldn't, exactly what problem were you having?
0
 
objectsCommented:
>   static Logger schedulerLogger = Logger.getLogger("scheduler.log");

Thats just the name of the logger.
To send the log to a file you need to add a file appender.
0
 
objectsCommented:
you can also handle the config via properties file instead of in your code

a good read: http://logging.apache.org/log4j/docs/manual.html
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
LeanMoreTryMoreAuthor Commented:
Please tell me how to i add a file to a file appender.
giving me a very simple codes is greatly appricated
0
 
objectsCommented:
 schedulerLogger.addAppender(new FileAppender(shedulerlayout, "sheduler.log"));
0
 
LeanMoreTryMoreAuthor Commented:
Very thanks for that.
Do i have to close the log if this process is aborted?
0
 
objectsCommented:
No log4j should look after that for you.
0
 
LeanMoreTryMoreAuthor Commented:
Just one last question.

Does log4j cause any buffer problem as I previouly experienced using System.out.println?
0
 
LeanMoreTryMoreAuthor Commented:
Thanks for your quick response.
If not because of you providing such a quick response, i would cancel my subscription long time ago.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.