Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is log4j.properties , why we need this. how to create this in java project using eclipse IDE

 
sulthan mathina
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is log4j.properties , why we need this. how to create this in java project using eclipse IDE. Please help with proper example. i'm newbie for java
 
Anand Bhatt
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
log4j.properties is just a file with type.properties.This file being used for configuration related to logging in your application. Contain a key-value pair.Key--> Some properties and value-->the value /setting for properties.
From your IDE just select project and follow : New-->File--> Specify file name as (xyz.properties)
Below is sample log4j.properties for your reference:


# The following properties set the logging levels and log appender. The
# log4j.rootCategory variable defines the default log level and one or more
# appenders. For the console, use 'S'. For the daily rolling file, use 'R'.
# For an HTML formatted log, use 'H'.

log4j.rootCategory=DEBUG, S,R
log4j.logger.com.bgs.entity=INFO
# The following properties configure the console (stdout) appender.
log4j.appender.S = org.apache.log4j.ConsoleAppender
log4j.appender.S.layout = org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss},[%p],%c{1}, %M(), %m%n
# The following properties configure the Daily Rolling File appender.
log4j.appender.R = org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File = E:/logs/application.log
log4j.appender.R.Append = true
log4j.appender.R.DatePattern = '.'yyy-MM-dd
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss},[%p],%c{1},%M,%m%n
# The following properties configure the Rolling File appender in HTML.
log4j.appender.H = org.apache.log4j.RollingFileAppender
log4j.appender.H.File = E:/logs/application.html
log4j.appender.H.MaxFileSize = 500KB
log4j.appender.H.Append = false
log4j.appender.H.layout = org.apache.log4j.HTMLLayout

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
log4j.properties is a configuration file for the Log4J logging framework.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17625
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:log4j.properties is a configuration file for the Log4J logging framework.


... And it has nothing to do with Eclipse itself.

You use log4j.properties in Java projects (notice I didn't say Eclipse Java projects) if you wish to use the log4j logger. It defines the logging mechanism(s) that will be used, how they will be used, and what topics they will log under.

log4.jproperties must be located in the root level of the classpath of the application when the application is being run. For applets and Applications, that's simply the root of the classpath directory or jar. For webapps, it's WEB-INF/classes. You can also specify a log4j.xml file, which allows a few more options and is in XML format. If you do, it will override log4j.properties.

Care must be taken when using log4j.properties if you're depending on an IDE. If you just put it into the compiler output classes directory, you may find that the IDE build process erases it as part of the cleanup process. Not that I recommend placing permanent objects in a project's output directories, whether using an IDE or not!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic