Click here to Skip to main content
Click here to Skip to main content

Daily Folder Appender

By , 17 Jun 2004
Rate this:
Please Sign up or sign in to vote.

Introduction

I'd like to thank The Code Project members for allowing us to share our code on this site. This article is created to give online help about an appender class for the popular Log4j package, how to use it, its source code, and comments.

Background

Log4j is a very popular package for logging various kinds of messages from within a Java application. It's a feature rich logging utility and comes with various built-in appenders which allows one to redirect the logging output to various destinations like files, message queues, database, etc.

While working for one of the clients, I came across the requirement which demanded that the log files be prepared on a daily basis and be kept in a day-wise folder structure. Although the first requirement is easy to accommodate with the built-in DailyRollingFileAppender class, the implementation for the second part was not readily available. So I decided to write my own appender to satisfy this need.

Using the Code

The download file contains the code and the sample log4j configuration file. Simply copy the DailyFolderAppender.class found under bin to your project's class folder. Keep in mind that the com.freeware.log4j directory structure is preserved. Copy the following lines from log4j.properties file in your project's log4j.properties file and start using this appender. The file is rolled-over at midnight.

## direct messages to a file date-wise ###
log4j.appender.Daily=com.freeware.log4j.DailyFolderAppender
log4j.appender.Daily.RootFolder=logs
log4j.appender.Daily.FileName=MyApp.log
log4j.appender.Daily.DatePattern=yyyy-MM-dd
log4j.appender.Daily.layout=org.apache.log4j.PatternLayout
log4j.appender.Daily.layout.ConversionPattern=%d{ABSOLUTE} %5p  - %m%n

To use this configured appender, refer to the following snippet:

### set log levels - for more verbose logging change 'info' to 'debug' ##
### possible levels ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF
log4j.rootLogger=INFO, stdout, Daily

History

  • 18th June, 2004 - Initial release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Prasad Khandekar
Software Developer (Senior) Freelancer
India India
I am a software professional with over 20 years of commercial business applications design and development experience.
 
My programming experience includes Java, Spring, .NET, Classic VB & ASP, Scripting, Power Builder, PHP, Magic & far far ago FoxPro, C, Assembly and COBOL.
 
From last 11 years I am mostly working with Java Technology. I am currently available to take up new assignments.

Comments and Discussions

 
GeneralMy vote of 5 PinmemberAbhijit Thakre7-Apr-13 0:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 18 Jun 2004
Article Copyright 2004 by Prasad Khandekar
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid