log4J – Manage multiple log files in a single application


In order to effectively manage a web server, it is necessary to get feedback about the activity and performance of the server as well as any problems that may be occurring. The Apache HTTP Server provides very comprehensive and flexible logging capabilities. This document describes how to configure its logging capabilities, and how to understand what the logs contain.

Please see the bellow mentioned sample log4j.properties

log4j.rootCategory=debug, rolling
# log4j.rootCategory=warn, stdout, rolling, socketLogger, lf5, xml, lf5Rolling

# Example of adding a specific package/class at a different
# logging level…
# –log everything in the com.johnmunsch package at debug level
#   ..even better, send it to a different appender.  Note, however, that
#   this doesn’t mean that any loggers from a lower level won’t be used:
#   everything still inherits, so this new logger is used _in_addition_to_
#   the loggers it would have otherwise already used.
log4j.category.com.johnmunsch=debug, socketLogger

# –on the other hand, everything in the
#   com.johnmunsch.stuff class _shouldn’t_ log
#   unless the log message is at ‘warn’ level or worse.
#   (It just so happens that stuff generates a _lot_ of
#   logging when it’s used)
log4j.category.com.johnmunsch.stuff=warn

# –also, it just so happens that we have a different
#   appender that we’re using that we want to have
#   log information from a specific location, and we
#   don’t want to send that information anywhere else.
log4j.category.com.johnmunsch.otherstuff=warn, xml
log4j.additivity.com.johnmunsch.otherstuff=false

# BEGIN APPENDER: CONSOLE APPENDER (stdout)
#  first:  type of appender (fully qualified class name)
log4j.appender.stdout=org.apache.log4j.ConsoleAppender

#  second: Any configuration information needed for that appender.
#    Many appenders require a layout.
log4j.appender.stdout.layout=org.apache.log4j.TTCCLayout
# log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout

# Possible information overload?
# log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#  additionally, some layouts can take additional information —
#    like the ConversionPattern for the PatternLayout.
# log4j.appender.stdout.layout.ConversionPattern=%d %-5p %-17c{2} (%30F:%L) %3x
– %m%n
# END APPENDER: CONSOLE APPENDER (stdout)

# BEGIN APPENDER: ROLLING FILE APPENDER (rolling)
#  first:  type of appender (fully qualified class name)
log4j.appender.rolling=org.apache.log4j.RollingFileAppender

#  second: Any configuration information needed for that appender.
#    Many appenders require a layout.
log4j.appender.rolling.File=example.log

log4j.appender.rolling.MaxFileSize=100KB
#  Keep one backup file
log4j.appender.rolling.MaxBackupIndex=1

log4j.appender.rolling.layout=org.apache.log4j.PatternLayout
log4j.appender.rolling.layout.ConversionPattern=%p %t %c – %m%n

# Possible information overload?
# log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#  additionally, some layouts can take additional information —
#    like the ConversionPattern for the PatternLayout.
# log4j.appender.stdout.layout.ConversionPattern=%d %-5p %-17c{2} (%30F:%L) %3x
– %m%n
# END APPENDER: ROLLING FILE APPENDER (rolling)

# BEGIN APPENDER: SOCKET APPENDER (socketLogger)
# Note: if you don’t have anything configured to accept the events
# from the socketLogger appender, you’ll see an exception on program
# startup (to console), and occasional status messages (to console)
# on if the log4j system has managed to connect to the specified
# socket..
log4j.appender.socketLogger=org.apache.log4j.net.SocketAppender
log4j.appender.socketLogger.RemoteHost=localhost
log4j.appender.socketLogger.Port=4445
log4j.appender.socketLogger.LocationInfo=false
# END APPENDER: SOCKET APPENDER (socketLogger)

# BEGIN APPENDER: LogFactor5 APPENDER (lf5)
# LogFactor5 is a Swing window that directly receives logging messages and
# displays them. It offers filtering, searching etc. similar to Chainsaw or
# Lumbermill but you don’t have to use a socket appender so it should be faster
# when the logging display is on the same machine as the program issuing
# messages.
log4j.appender.lf5=org.apache.log4j.lf5.LF5Appender
log4j.appender.lf5.MaxNumberOfRecords=1000
# END APPENDER: LogFactor5 APPENDER (lf5)

# BEGIN APPENDER: XML APPENDER (xml)
# A standard file appender where we have put an XML layout onto the output
# event records. A file put out using this technique can be loaded after
# the fact into Chainsaw for viewing, filtering, searching, etc.
log4j.appender.xml=org.apache.log4j.FileAppender
log4j.appender.xml.file=example_xml.log
log4j.appender.xml.append=false
log4j.appender.xml.layout=org.apache.log4j.xml.XMLLayout
# END APPENDER: XML APPENDER (xml)

# BEGIN APPENDER: LogFactor5 Rolling APPENDER (lf5Rolling)
# Like the XML appender above, this is a specialized format designed to be read
# from a tool. In this case LogFactor5 can load up files in this format for
# after the fact review.
log4j.appender.lf5Rolling=org.apache.log4j.RollingFileAppender
log4j.appender.lf5Rolling.File=example_lf5.log
log4j.appender.lf5Rolling.layout=org.apache.log4j.PatternLayout

log4j.appender.lf5Rolling.layout.ConversionPattern=[slf5s.start]%d{DATE}[slf5s.DATE]%n
%p[slf5s.PRIORITY]%n%x[slf5s.NDC]%n%t[slf5s.THREAD]%n%c[slf5s.CATEGORY]%n
%l[slf5s.LOCATION]%n%m[slf5s.MESSAGE]%n%n
# END APPENDER: LogFactor5 Rolling APPENDER (lf5Rolling)

Advertisements

About Praveen Orathel

I am a java web application developer.
This entry was posted in Uncategorized. Bookmark the permalink.

13 Responses to log4J – Manage multiple log files in a single application

  1. Hello, I just came by to check out this site. It is really great and
    I enjoyed viewing it, thank you for the great writing!

  2. We stumbled over here by a different web address and thought I may as well check things out.
    I like what I see so now i am following you. Look forward to looking over your
    web page yet again.

  3. Have you ever considered about including a little bit more than just your articles?
    I mean, what you say is fundamental and all. Nevertheless just
    imagine if you added some great visuals or videos to give
    your posts more, “pop”! Your content is excellent but
    with pics and videos, this site could definitely be one of the greatest in its
    niche. Fantastic blog!

  4. 2web.ma says:

    This info is priceless. How can I find out more?

  5. turmeric says:

    Making sure that supplement provides herbal ingredients extends those benefits.

    By drinking a cup of boiled milk mixed with a tea spoon of turmeric powder for couple of days before going to bed will definitely cure the mouth
    ulcers. It’s a condition that results in pain or mild discomfort of the pelvic region and the bladder.

  6. What i do not realize is in reality how you are now not really much more well-liked
    than you may be right now. You’re so intelligent. You already know thus considerably in the case of this topic, made me individually consider it from a lot of various angles. Its like men and women aren’t interested until it is one
    thing to accomplish with Woman gaga! Your own stuffs great.
    All the time maintain it up!

  7. Elden says:

    Thank you for the auspicious writeup. It in fact was a amusement account it.
    Look advanced to more added agreeable from you!

    However, how can we communicate?

  8. Stephany says:

    And here’s a good tip: if your bag’s cleaning instructions call for air drying in
    a tumble dryer, try throwing a few tennis balls in with the sleeping bag.
    Many times if you use our suggestion you will find that the quality backpacks are
    the same price as the cheaply made backpacks. Tent camping is great for families with
    younger children because it’s fun, inexpensive, and the right combination of being outdoors without being too far from those modern conveniences.

  9. deuil says:

    I found your blog on http://pjava.wordpress.
    com/2011/01/05/log4j-manage-multiple-log-files-in-a-single-application/ and I’m so happy I did. It’s as if you read my
    mind. You come across as knowing a lot about this, like you wrote the book on it or
    something. While I think some extra media like some pics or
    a couple of videos, this will be a fantastic resource.
    I will certainly return.

  10. Hello there, just became alert to your blog through Google, and
    found that it’s truly informative. I am gonna watch out for brussels. I will be grateful if you continue this in future. Many people will be benefited from your writing. Cheers!

  11. An impressive share! I have just forwarded this onto a friend who had
    been doing a little research on this. And he actually
    bought me lunch because I stumbled upon it for him…

    lol. So allow me to reword this…. Thanks for
    the meal!! But yeah, thanx for spending time to discuss this issue here on your website.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s