log4j and struts
I am using log4j with struts, all configuration is working fine but now I have a requirement to read log4j xml param values using database here is example what i want
<param name="maxFileSize" value="**this i want from database
<param name="maxBackupIndex" value=" **this i want from database
<param name="File" value="**this i want from database
please help me out
Thanks in advance !!
I imagine to do this,
- have the log4j.xml file generated, such as having a java process run before your application, to connect to the database, populate the value, perhaps by replacing a token in a template and writing out the log4j,xml file, then starting your application up, which would conveniently now find this generated log4j.xml in its classpath.
- use the programmatic API to configure the log4j. See the log4j java API documentation, where you might do something like
I think this hybrid reconfiguration would allow the logger settings and levels defined in the log4j.xml to still work. Maybe you would not need to remove all existing appenders first.
String filename = "thefilename";
Layout layout = new PatternLayout(...);
RollingFileAppender appender = new RollingFileAppender(layout, filename);
int maxFileSize = // this is where you invoke your database query to get the value to use.
// and make this appender be used
Logger logger = Logger.getRootLogger();
Travishein thanks for Reply !!
I want to chang log4j.xml based on user login !!
suppose if type A user login then I want different log4j configuration and if type B user login then I want different log4j configuration .....
is it possible for me ?? :rolleyes::rolleyes:
Thanks again for reply
im not sure if this is possible directly with log4j. you would need to write a custom appender that is somehow aware of who the user who invoked it is. It might be possible with something more modern like logback project, but i have not really looked into this.