Thursday, 10 October 2013

Create Log file for JAVA Server Applications.


Step:1
 
Save as log4j.properties in project folder
# Root logger option
log4j.rootLogger=INFO, file
 
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\blazeds-turnkey-4.0.0.14931\\tomcat\\log\\license.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

File=C:\\blazeds-turnkey-4.0.0.14931\\tomcat\\log\\license.log
In this path license log is created. 
 
Step 2:
Download log4j.jar

Step 3:
  Logger log = Logger.getLogger(getClass()); must be included in All Java Classes.
 getClass()=current class

        log.info("Username : "+uName);
        log.info("Password : "+pwd;
Username and Password are printed in log file.

Step4:
Levels of Log4j Properties:
  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL
  • ALL

    In step1:
    We have placed

    log4j.rootLogger=INFO, file
     
    info by which WARN,ERROR,FATAL,ALL will be covered above TRACE,DEBUG wont be covered.
    If we place Trace all properties will be covered.

No comments: