• 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

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
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
log4j.properties is a configuration file for the Log4J logging framework.
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic