Discussions

General J2EE: Setting Log4j Properties

  1. Setting Log4j Properties (5 messages)

    Hi,

    I am revamping a java application. We are planning to user Log4j but I am new to Log4j. My requirement is, I need to use the same log4j property file for 8 different module. I need to know how to configure different file names for different modules in the same log4j file. Thanks for your time

    Threaded Messages (5)

  2. Re: Setting Log4j Properties[ Go to top ]

    You can split your loggers into different files. With the following example, all logging done to loggers in package "com.myco.a" and any subpackage thereof will be logged to module-a.log (likewise for module b). Now, as long as you separate your modules into packages like this, you're ok.

    log4j.logger.com.myco.a=DEBUG, A
    log4j.logger.com.myco.b=DEBUG, B

    log4j.appender.A=org.apache.log4j.FileAppender
    log4j.appender.A.File=a.log
    log4j.appender.A.layout=org.apache.log4j.PatternLayout
    log4j.appender.A.layout.ConversionPattern=%d{MM-dd@HH:mm:ss} %-5p (%13F:%L) %3x - %m%n

    log4j.appender.B=org.apache.log4j.FileAppender
    log4j.appender.B.File=b.log
    log4j.appender.B.layout=org.apache.log4j.PatternLayout
    log4j.appender.B.layout.ConversionPattern=%d{MM-dd@HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
  3. Re: Setting Log4j Properties[ Go to top ]

    I do understand that, but what if I have to use two different loggers in lets say the same class. How do I get the specified logger a, or b?
    Thank you very much for your help!
    Regards,
    Matt
  4. 2 Logger instances[ Go to top ]

    You just need to create 2 Logger instances using different names.
  5. Re: 2 Logger instances[ Go to top ]

    I have declared fileappender the same way, but some how file is not being generated. what may be the reason? jsptube.com
  6. specify the appender[ Go to top ]

    When declare the "logger" variable, use this to specify de appender: private static Logger logger = Logger.getLogger("com.myco.b");