2 Replies Latest reply on Jan 25, 2007 9:18 AM by Marcus Klein

    Logging question (repository selector with local and global

    Marcus Klein Newbie


      I have a question regarding logging with log4j. I used the example repositoryselector.zip (http://wiki.jboss.org/wiki/Wiki.jsp?page=Logging) from the Wiki Knowledge Base to enable logging on a per-webapp basis, i.e. now I can use a log4j.xml file for each deployment I have. This works fine so far. The problem I have now is that all logging messages are written to the appenders I specified in those 'local' log4j.xml file. How would I be able to specify that only some logging messages are written to the 'local' logging-file while others are still written, say, to the server.log? Is there a way to access the 'global' specified appender "FILE" from the JBoss\conf\log4j.xml file?

      To make it a bit more precise, say, I have two classes A and B deployed as mydeployment application. Within the log4j.xml file below mydeployment I would like to specify that logging msgs from class A are written to a 'local' log-file (say classA.log), while logging messages from class B are written to the server.log (the server.log that is specified in JBoss\conf\log4j.xml). The example in repositoryselector.zip shows me only how to log either all msgs to server.log or to the 'local' specified log-file. Please note that the logging messages should appear only once, i.e. either in the server.log file xor in the 'local' log-file. Is there a way to do this by configuration, or will I need to change the repository selector implementation? Anyway a detailed answer would be appreciated.

      Thank you very much for your time and help.

        • 1. Re: Logging question (repository selector with local and glo
          Elias Ross Master

          I doubt there is an out-of-the-box solution.

          One (convoluted) way to make this work would be to have this deployed on the main server:


          And then configure your per-application appender as a SocketAppender. I assume you know how to create MBeans.

          • 2. Re: Logging question (repository selector with local and glo
            Marcus Klein Newbie

            Thank you for the answer genman.

            In the meanwhile I found another approach. During the initializtaion of the 'local' log4j configuration I check for appender references that doesn't exist within the 'local' log4j file (i.e. which aren't specified by an appender tag). For each such (non existing) appender I check the existing appenders I get by LogManager.getLoggerRepository().getRootLogger() and LogManager.getLoggerRepository().getCurrentLoggers() (one needs to iterate over all possible appenders for each Logger object) in case an appender of the same name can be found it is added to the Logger ('local') that references a non existing appender. Note that the appenders you get from LogManager.getLoggerRepository().XXX() are the ones specified by the 'global' log4j configuration file that is stored in folder JBoss\conf.
            So I am able to reference within my 'local' log4j configuration an appender that is specified within the 'global' log4j configuration file. The disadvantage of this approach is that the appender in the 'global' configuration file must be used (refernced) by at least one logger, since otherwise the appender can't be found.

            In case anyone has some suggestions on this approach, they are welcome.

            I wonder why it isn't possible, without any additional implementation work, to reference appenders from a 'local' configuration file that are specified within another ('global') configuration file.

            The drawbacks I see in the approach that genman suggested are:
            - you will need to open another port
            - you don't know to which appender the log messages are written, since the default LoggerRepository (LogManager.getLoggerRepository()) is used; or you will need to extend the implementation, so that one can specify which logger/appender from the default LoggerRepository should be used.