?
Solved

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

Posted on 2005-05-12
9
Medium Priority
?
218 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:LeanMoreTryMore
  • 5
  • 4
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13992614
>   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
 
LVL 92

Expert Comment

by:objects
ID: 13992629
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
 

Author Comment

by:LeanMoreTryMore
ID: 13992632
Please tell me how to i add a file to a file appender.
giving me a very simple codes is greatly appricated
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 92

Expert Comment

by:objects
ID: 13992635
 schedulerLogger.addAppender(new FileAppender(shedulerlayout, "sheduler.log"));
0
 

Author Comment

by:LeanMoreTryMore
ID: 13992661
Very thanks for that.
Do i have to close the log if this process is aborted?
0
 
LVL 92

Expert Comment

by:objects
ID: 13992681
No log4j should look after that for you.
0
 

Author Comment

by:LeanMoreTryMore
ID: 13992707
Just one last question.

Does log4j cause any buffer problem as I previouly experienced using System.out.println?
0
 
LVL 92

Accepted Solution

by:
objects earned 1600 total points
ID: 13992815
It shouldn't, exactly what problem were you having?
0
 

Author Comment

by:LeanMoreTryMore
ID: 13993126
Thanks for your quick response.
If not because of you providing such a quick response, i would cancel my subscription long time ago.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question