Results 1 to 2 of 2

Thread: Different log4j configurations within the same application context

  1. #1

    Question Different log4j configurations within the same application context

    Hi,

    We have a Spring application using log4j which is configured on startup within Tomcat:

    Code:
    -Dlog4j.configuration=file:%CATALINA_BASE%/conf/log4j.xml
    Currently the application logs to one log file, e.g. system.log.

    We have now developed a new component that runs in the same context but is logging to a different log file from the rest of the application e.g. subsystem.log. This is fine for the new code we have developed as we have configured a new logger/appender for subsystem.log in the log4j.xml and reference this in the logging code of the new component.

    However the problem is with our common libraries which will always log to the default system.log through:

    Code:
    Logger.getLogger(this.getClass());
    This means we currently have our new component's logging going to 2 separate logs which is not ideal. Ideally where we utilize these common libraries within our new component we would like logging to subsystem.log and where used elsewhere in the system logging would be to system.log. This makes me think we need two log4j configurations, one being specifically for the new component. I'm not sure if it is possible to configure this in Spring. The main problem is that I don't want to override the default logging config anywhere else but in the new component. May be I'm being a tad too optimistic thinking I can do it all in config

    If anyone has any ideas please let me know! It'd be much appreciated
    Last edited by cpedros; Feb 19th, 2008 at 09:54 AM. Reason: Providing more detail

  2. #2

    Default

    Hi cpedros,
    Log4j is a modular and scalable API and hence its immense popularity among developer community.

    Quote Originally Posted by cpedros View Post
    However the problem is with our common libraries which will always log to the default system.log through:

    Code:
    Logger.getLogger(this.getClass());
    This means we currently have our new component's logging going to 2 separate logs which is not ideal. Ideally where we utilize these common libraries within our new component we would like logging to subsystem.log and where used elsewhere in the system logging would be to system.log. This makes me think we need two log4j configurations, one being specifically for the new component. I'm not sure if it is possible to configure this in Spring. The main problem is that I don't want to override the default logging config anywhere else but in the new component. May be I'm being a tad too optimistic thinking I can do it all in config

    If anyone has any ideas please let me know! It'd be much appreciated
    You may not require multiple configuration files for logging in main and at component level.

    You only need to configure distinct loggers for main and specific component/component group in the Log4j configuration and in the relevant component instantiate appropriate logger for use. Thats all that is needed to be done!

    You may choose to take a look at this discussion thread for better understanding [Setting Log4j Properties]

    Happy coding!!
    PS: You may pay it forward!!

Posting Permissions

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