*
The moose likes IDEs, Version Control and other tools and the fly likes what is log4j.properties , why we need this. how to create this in java project using  eclipse IDE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "what is log4j.properties , why we need this. how to create this in java project using  eclipse IDE" Watch "what is log4j.properties , why we need this. how to create this in java project using  eclipse IDE" New topic
Author

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

sulthan mathina
Greenhorn

Joined: Jan 31, 2011
Posts: 6
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

Joined: May 30, 2007
Posts: 189
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

Joined: Aug 16, 2005
Posts: 14117
    
  16

log4j.properties is a configuration file for the Log4J logging framework.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

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!


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is log4j.properties , why we need this. how to create this in java project using eclipse IDE