Results 1 to 4 of 4
  1. #1
    kaswanharish is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Smile log4j and struts

    Hi,
    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
    <appender name="debugfile"
    class="org.apache.log4j.RollingFileAppender">
    <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 !!

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    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
    Java Code:
    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.
    appender.setMaxFileSize(maxFileSize);
    
    // and make this appender be used 
    Logger logger = Logger.getRootLogger();
    logger.removeAllAppenders();
    logger.addAppender(appender);
    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.

  3. #3
    kaswanharish is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Default

    Travishein thanks for Reply !!

    :confused::confused:
    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

  4. #4
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    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.

Similar Threads

  1. log4j
    By swapna_d in forum New To Java
    Replies: 7
    Last Post: 08-04-2010, 01:23 AM
  2. decorator.jsp problem building Struts Menu in JSP when Struts action is used
    By dkirvan in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-29-2010, 06:33 AM
  3. Regarding Log4j
    By sidiq in forum New To Java
    Replies: 0
    Last Post: 04-07-2008, 08:35 PM
  4. log4j not working in struts
    By Manu in forum Web Frameworks
    Replies: 0
    Last Post: 03-19-2008, 03:54 PM
  5. Log4j
    By chakri in forum New To Java
    Replies: 1
    Last Post: 02-08-2008, 11:15 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •