logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacob L. Anawalt" <janaw...@geckosoftware.com>
Subject Re: How to config log4cxx to delete the log files periodically
Date Fri, 19 Sep 2008 21:31:57 GMT
On 2008-09-16 12:06, renny.koshy@rubixinfotech.com wrote:
> From what I've seen out there... small biz to large enterprises is that 
> for System Admins, they see deleting logfiles as part of a global task 

As I've started implementing some projects with log4cxx logging I had decided to 
use the sized based rolling policy since it was an in-my-face solution, but what 
I really wanted was for my programs to work into the logrotate system like most 
of the other daemons on my Debian systems.

I've looked into how to do this a couple of times, but only half heartedly. This 
discussion and some recent tweaking of a mail service's log rotation (via 
logrotate) on one server motivated me to figure out how to make this work.

Attached is a sample program that compiles on a Debian Etch (4.1) system with 
the liblog4cxx9-dev (0.9.7-6) package [1]. It is self-contained, no external 
conf file required. Just compile it and it should write to the terminal and to a 
file named log4cxx-hup.log. Rename the file to eg log4cxx-hup.1.log, like a 
rotation program would, and it continues to write to the file. Send it a SIGHUP 
and FileAppender::activateOptions() closes and re-opens the file, thus writing 
again to log4cxx-hup.log. You can even pre-create the file and set the 
permissions you want, as long as they allow the program to write, and it should 
work.

While I appreciate the portability issues the built-in rotation schemas try to 
provide, I prefer this solution if it will reliably work within my current 
logging framework.

Please glance over the attached code. I would like to have a reasonably polished 
example to put on the wiki that is simple without hiding too many details (eg no 
using namespace xxx), shows best practice ideas (eg NDC without push/pop) and 
easy to copy and paste as a boilerplate for doing the same in someone's 
application. I haven't checked this against 0.10.0, so I don't know if any 
methods are deprecated or if better options in that version.


[1] 0.9.7? Yes. I know. Unsupported by log4cxx project. Unfortunately this 
appears to be the version that will be in Lenny as well, so without a person 
willing to be responsible for the backport, or more time dropping into my lap, 
this is the version I will probably be dealing with for a few more years.

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt@geckosoftware.com
435-752-8026

Mime
View raw message