• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

log4j use best way

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I use log4j in the best way in my program?

I configure all logging properties in the properties file.

/*******************************************


#For File Append of the logs
log4j.rootCategory=DEBUG, rfware
log4j.appender.rfware=org.apache.log4j.RollingFileAppender
log4j.appender.rfware.File=c:/temp/aiicommunicator.log
log4j.appender.rfware.Threshold=DEBUG
log4j.appender.rfware.Append=false
log4j.appender.rfware.MaxFileSize=1000KB
log4j.appender.rfware.MaxBackupIndex=2
log4j.appender.rfware.layout=org.apache.log4j.PatternLayout
log4j.appender.rfware.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

/*********************************************************************

But I want to load this properties during the start up of my application for logging in my java all java classes.

can you provide some code guide line how can I achieve it ?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you put that into a file named log4j.properties and make sure that the properties file is in a directory that's in the classpath when you run your application, then Log4J will automatically find it and you don't have to do anything special to initialise Log4J in your application.
 
shankha bhattacharya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I am not use the name log4j.properties then how can I use it to my application?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Promoting to the intermediate forum.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't this belong in "Other opensource"?

Anyway, take a look at the PropertyConfigurator. If you call configure(file) or configureAndWatch(file) before the first log statement, it will use the configuration in the given file.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how about use: PropertyConfigurator.configure(".\\src\\log4j.properties") first init the log4j?
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"west west", please check your private messages. You can see them by clicking My Profile.
 
reply
    Bookmark Topic Watch Topic
  • New Topic