LeanMoreTryMore
asked on
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("schedule r.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("Schedu ler.main() : Errro occured due to " + e);
e.printStackTrace();
System.exit(1);
}
} // main
private Scheduler() throws Exception {
/* Log layout handler */
schedulerLogger.setLevel(L evel.INFO) ;
schedulerLayout = new SimpleLayout();
schedulerAppender = new ConsoleAppender(schedulerL ayout);
schedulerLogger.addAppende r(schedule rAppender) ;
//
schedulerLogger.info("UTev entSchedul er: 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
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("schedule
Appender schedulerAppender;
SimpleLayout schedulerLayout;
public static void main(String[] args) {
try {
int dbConnOk = Utilities.SQLJdbConnection
if ( dbConnOk == 0 ) {
new Scheduler();
}
else {
System.exit(1);
}
}
catch (Exception e) {
System.out.println("Schedu
e.printStackTrace();
System.exit(1);
}
} // main
private Scheduler() throws Exception {
/* Log layout handler */
schedulerLogger.setLevel(L
schedulerLayout = new SimpleLayout();
schedulerAppender = new ConsoleAppender(schedulerL
schedulerLogger.addAppende
//
schedulerLogger.info("UTev
<=== 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
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
a good read: http://logging.apache.org/log4j/docs/manual.html
ASKER
Please tell me how to i add a file to a file appender.
giving me a very simple codes is greatly appricated
giving me a very simple codes is greatly appricated
schedulerLogger.addAppende r(new FileAppender(shedulerlayou t, "sheduler.log"));
ASKER
Very thanks for that.
Do i have to close the log if this process is aborted?
Do i have to close the log if this process is aborted?
No log4j should look after that for you.
ASKER
Just one last question.
Does log4j cause any buffer problem as I previouly experienced using System.out.println?
Does log4j cause any buffer problem as I previouly experienced using System.out.println?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your quick response.
If not because of you providing such a quick response, i would cancel my subscription long time ago.
If not because of you providing such a quick response, i would cancel my subscription long time ago.
Thats just the name of the logger.
To send the log to a file you need to add a file appender.