Click here to Skip to main content
12,892,015 members (53,919 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 17 Jun 2004

Daily Folder Appender

, 17 Jun 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
A Log4j appender class to create daily folders


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.


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 file in your project's file and start using this appender. The file is rolled-over at midnight.

## direct messages to a file date-wise ###
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


  • 18th June, 2004 - Initial release


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.

You may also be interested in...

Comments and Discussions

QuestionDailyFileAppender Issue Pin
Member 1123859812-Feb-15 4:58
memberMember 1123859812-Feb-15 4:58 
AnswerRe: DailyFileAppender Issue Pin
Prasad Khandekar19-Mar-15 17:37
professionalPrasad Khandekar19-Mar-15 17:37 
GeneralMy vote of 5 Pin
Abhijit Thakre7-Apr-13 0:26
memberAbhijit Thakre7-Apr-13 0:26 

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

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

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