0

I have a problem with log4j loggin and I hope you can help me on this.

This is the scenario: I have 3 different applications (in other words 3 .jar) A, B and C. A is always running and from time to time calls B and C to execute them. Each of them have its own log4j.properties (with the path duly included in the MANIFEST) but Log4j only takes the properties of the main app A into consideration, ignoring the rest. I need to know if I can force Log4j to use for each app its own properties. I have seen something related using DOMConfigurator, but if I'm not wrong this only works with xml files and I'm using properties.

Thanks in advance

Fran
  • 61
  • 1
  • 3

2 Answers2

0

There are several Configurators, one of which is the PropertyConfigurator.

Paul Grime
  • 14,970
  • 4
  • 36
  • 58
0

I need to know if I can force Log4j to use for each app its own properties.

Yes, you can. When you launch the applications B and C, define this system variable at their command line:

-Dlog4j.configuration=B.properties

where B.properties is the file name of log4j properties file in B's classpath. Likewise for application C.

Edit: found this: Change location of log4j.properties

Community
  • 1
  • 1
MaDa
  • 10,511
  • 9
  • 46
  • 84
  • Magda, A instantiates the main class of B and calls the method execute (B.execute()), it does not execute the main method directly, so I am not sure about the useful of the command line proposed, should I execute the main method directly? Is only neccesary to pass this parámeter or I need to do something with it later? Thanks – Fran Sep 20 '11 at 07:53
  • @Fran Then we've found the cause: you are not executing application B, you just instantiate a class and call its method. You're still within A. If you were to start a separate application, you'd use one of `java.lang.Runtime.exec()` methods. The way you do it now, you'll never get a separate log4j configuration for B or C. – MaDa Sep 20 '11 at 08:31
  • Ok, then I cannot separate the logs because I cannot now to change the way of executing the app. Anyway thanks for your help – Fran Sep 20 '11 at 12:16
  • @Fran Well, you learnt something. It would be polite to show your appreciation by clicking the appropriate buttons. It is no-charge, just as anyone's answers in Stackoverflow. – MaDa Sep 20 '11 at 12:43
  • @Fran Hmmm, I still can't see any accept or an upvote, to put it directly. What a gyp. – MaDa Sep 20 '11 at 14:59