3 Replies Latest reply on Nov 20, 2012 11:21 AM by mazz

    writing own standalone module that needs legacy log4j support

    mazz Master

      This is yet another log4j thread - however, I think its different than most that have been posted - at least I can't find the answer to my specific use case - so don't roll your eyes just yet

       

      I am not writing an EAR, WAR, whatever. I am writing a standalone module (it has a Main-Class in it - its just like what the org.jboss.as.cli module does) and I am deploying it as just a module. I start the server via something like "java -jar jboss-modules.jar -mp <module paths> org.my.module" (this is similar to how the jboss CLI script starts the CLI)

       

      However, my module code is using some legacy libraries that use both commons-logging with log4j underneath (there is a log4j.xml that I want to be used to configure the logging).

       

      I do NOT get any ClassNotFound or similar errors, the code runs "ok" - only, I do not see any of log messages coming out in the console or the file (I have both appenders defined in log4j.xml).

       

      In my modules.xml, I do have a dependency on modules org.apache.commons.logging, org.apache.log4j, org.jboss.logmanager and org.jboss.logging. My module does NOT have any of those jars inside of it (that is, my module does not contain the log4j.jar or the commons-logging.jar - since I have a dependency declared for them, I did not put them in my module).

       

      Does this make sense? Any ideas on how I get this to work?  Oh, and where exactly is log4j getting is configuration if not from my module's own logj4.xml?

        • 1. Re: writing own standalone module that needs legacy log4j support
          jaikiran pai Master

          My guess is that the log4j.xml isn't being picked up. Where exactly is that located?

           

           

          John Mazzitelli wrote:

           

          Oh, and where exactly is log4j getting is configuration if not from my module's own logj4.xml?

          Adding -Dlog4j.debug=true system property while starting the server might help in understanding that (you'll see the system.out messages from log4j, telling you what it's upto).

          • 2. Re: writing own standalone module that needs legacy log4j support
            David Lloyd Master

            You'll need to do a Couple Things to make it work.  Our log4j is modified for the purpose of forwarding through the LogManager.  So step one is, you'll have to make sure your module has a dependency on "org.jboss.logmanager" with 'services="import"' set.

             

            Next, I believe you'll have to configure a LogManager-style logging.properties in your module as our log4j won't be configuring itself.  Once you do these things you *should* get some output.

            • 3. Re: writing own standalone module that needs legacy log4j support
              mazz Master

              Thanks folks. So, I got it to work by adding the org.jboss.logmanager with services=import in modules.xml and I put a logging.properties file in the root directory of my module's main jar file. I did do both of those before, but not at the same time which is why it wasn't working for me :-) So, making sure I do both of those fixed the problem. Note that having a log4j.xml doesn't matter - I don't have a log4j.xml and things still worked.