Using Log4J for a "complexe" requirement. Need help!

E

etienno

HI,

I am trying to do this requirement with log4J. I have already post here
a comment about the fact that it seems quite difficult to extends the
DailyRollingFileAppender, this issu is related to my problem described
here:

For a Web Site, I need to be able to create logfiles where the file
name of the log is only known at runtime, and the number of log depends
of the number of user-roles in the website.

[User-role].MyLog.[Server IP Address or host name].[Current Day].log

Knowing there is 3 user role in my web site, Log4J should create 3
logs, one for each role. Each role will log in a different file... In
the future there might be more role, so I dont want to link this
feature to a log4j properties file (I mean the creation of an
properties-based Appender). The number of logFile should be dynamically
determined.

The [Server IP Address] will also be known only dynamically when
starting the server. It is the same thing for the [Current Day]. At
minight there must be a rolling file. This can be done like in the
DailyRollingFileAppender, overriding the naming convention (a date is
appended at the end of the logfile name (including the .log) only when
rolling the log file).

I have a small idea how to do it in theory:

- Create an custom appender based on DailyRollingFileAppender and
- Create a new LogFactory to overide the creation of the
"Custom"DailyRollingFileAppender to take in parameter the User-Role,
the IP Address and the Date.
- There must be somewhere a HashMap of Appenders.. each with there own
file name...

But in practice, I would like to have some hint about how to start the
code, is there some code I could based my work... or should I scrap
this crazy idea and make a "simple" Perl script to parse a single log4J
file and create the 3 files according this single file the log content?

Thanks for helping me

Etienne
Paris
 
D

ddimitrov

I don't think there is a way to habdle these requirements by using
properties/XML configuration only. Usually, when you need more than one
file, in Log4J you instantiate more than one appenders.

For your case, what I would do is to create a static unmodifiable map,
where the user roles would be mapped to separate loggers - each logger
holding a DailyRollingFileAppender (as your requirements call for
rolling based on the day an not on size.)

The daily appender has 'datepattern' property, which allows you to
customize the format of the suffix (you define the prefix when you
instantiate the appenders).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,991
Messages
2,570,217
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top