Link to home
Start Free TrialLog in
Avatar of snaef
snaef

asked on

Adding a appender to log4j at runtime

Hello,

I am new to the log4j package and have a need to add log files at runtime.   From looking through the documentation I see that all the logs are configured via a config file.   The app will have many users and I would like to create a log file for each user at runtime.  I won’t know in advance who the users are.

I thought that I could create a basic rotating file logger and then add appenders to it, but I don’t see a way via the javadocs to create an appender at runtime, just ways to get references to preconfigured appenders.

Is there a way to do this?   I guess I could create unique loggers from scratch via code each time a user logs on, but I liked being able to configure the root logger in the config file.  The way I understand the docs, a appender will inherit the attributes of the root logger.

Many thanks,
-Scott
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snaef
snaef

ASKER

Ok, just one quick question.   If I add a new rolling file logger and the filename already exists (i.e its still the same date and the use has returned to the site) will the logger append text to the existing file or overwrite the old file.

Append to the existing i think
Avatar of snaef

ASKER

Thanks for the help, slit points as both were basically the same answer, but  the latter was more detailed.   Thanks again!
:-)