DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Log4j.properties: Eclipse Log4j HOWTO In 10 Minutes

Log4j.properties: Eclipse Log4j HOWTO In 10 Minutes

Snippets Manager user avatar by
Snippets Manager
·
Jan. 05, 07 · Java Zone · Code Snippet
Like (0)
Save
Tweet
38.66K Views

Join the DZone community and get the full member experience.

Join For Free
// How to use log4j within eclipse in 10 minutes


# HOW TO USE LOG4J WITHIN ECLIPSE IN 10 MINUTES
# by Daniel Gonzalez Gasull  gasull[at]gmail[dot]com
#
# 1) Download log4j http://logging.apache.org/site/binindex.cgi
# 2) Unpack the .zip file in your Java folder (In Windows it is usually 
# C:\Program Files\Java\)
# 3) In Eclipse: Window - Preferences... - Java - Build Path - User Libraries - 
# New - write "log4j" - OK - Add JARs... - navigate to find your log4j .jar you just
# unpacked in the Java Folder - OK 
# 4) right click on your project in the Package Explorer - New - Folder - 
# in "Folder name" write "log4j" - click Advanced - select "Link to a folder in the
# file system" - create a new folder "log4j" in your project folder in the file system
# 5) Place this file you are reading right now in in the folder you just created.  Name
# the file as log4j.properties
# 6) In Eclipse: Run - Run... - In the navigation bar on the left select either the 
# server, or the runnable class, or the JUnit test you want to log with log4j -
# select the Classpath tab - User Entries - Advanced... - Add folders - OK - select 
# the "log4j" folder you created in your project - OK   
# 7) Repeat step 6 for other servers, runnable classes or JUnit tests you want to log
# 8) Change in the following line the "org.example.foo.bar" with whatever you want.
log4j.category.org.example.foo.bar=DEBUG
# 9) Add the following import to the Java Class you want to log:
#import org.apache.log4j.Logger;
# 10) Add this lines to the Java Class you want to log:
#/**
# * Log4j logger
# */
#static Logger log4j = Logger.getLogger("org.example.foo.bar");
# 11) Substitute in the code above "org.example.foo.bar" with whatever your wrote in
# in the step 8.
# 12) Add something like the following code in your Class whenever you want to log:
#log4j.debug("WTF?");
# 13) Repeat steps 9, 10, 11 and 12 for every Java Class you want to log
# 14) Enjoy!


log4j.rootCategory=DEBUG, R, O

# Stdout
log4j.appender.O=org.apache.log4j.ConsoleAppender

# File
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=log4j.log

# Control the maximum log file size
log4j.appender.R.MaxFileSize=100KB

# Archive log files (one backup file here)
log4j.appender.R.MaxBackupIndex=1

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.O.layout=org.apache.log4j.PatternLayout

log4j.appender.R.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n
log4j.appender.O.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x - %C.%M(%F:%L) - %m%n


Eclipse Log4j

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Kafka Fail-Over Using Quarkus Reactive Messaging
  • Fintech and AI: Ways Artificial Intelligence Is Used in Finance
  • How To Integrate Event Streaming Into Your Applications
  • Top Soft Skills to Identify a Great Software Engineer

Comments

Java Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo