Inherit logging properties in ja custom jar library?

J

John Smith

Ja have a custom jar library which is used by a web service application.
Can I inherit the log4j properties from the enveloping application in
the jar? I want them both to write to the same file defined in
log4j.properties of the web service.

Thanks in advance for any help.
 
L

Lew

Ja have a custom jar library which is used by a web service application.
Can I inherit the log4j properties from the enveloping application in the jar?
I want them both to write to the same file defined in log4j.properties of the
web service.

Unless logging properties are set up specifically for the classes in the JAR,
log4j uses the parent logger, which will be the one you set up, AIUI.

Have you tried this? Why not? What happened when you did?
 
J

John Smith

Unless logging properties are set up specifically for the classes in the
JAR, log4j uses the parent logger, which will be the one you set up, AIUI.

Have you tried this? Why not? What happened when you did?

If I specifically put log4j.properties inside the jar file than both the
WS application and the jar log to the defined file.

But if I only specify logging properties for the WS application, only
the application writes logs to the file and jar logs are not written.

Maybe the problem is that my jar file is in [tomcat]shared/lib
directory? (It is purposely put there, not in WE-INF/lib)
 
L

Lew

John said:
Lew said:
Have you tried this? Why not? What happened when you did?

If I specifically put log4j.properties inside the jar file than both the WS
application and the jar log to the defined file.

But if I only specify logging properties for the WS application, only the
application writes logs to the file and jar logs are not written.

Maybe the problem is that my jar file is in [tomcat]shared/lib directory? (It
is purposely put there, not in WE-INF/lib)

Yes, that would have it loaded via a different class loader, so the JAR
classes are not in the inheritance hierarchy for the application classes.
 
J

John Smith

John said:
Lew said:
Have you tried this? Why not? What happened when you did?

If I specifically put log4j.properties inside the jar file than both
the WS
application and the jar log to the defined file.

But if I only specify logging properties for the WS application, only the
application writes logs to the file and jar logs are not written.

Maybe the problem is that my jar file is in [tomcat]shared/lib
directory? (It
is purposely put there, not in WE-INF/lib)

Yes, that would have it loaded via a different class loader, so the JAR
classes are not in the inheritance hierarchy for the application classes.

Thank you for your help.
I'll try to put the jar into the application library.
If not I'll leave the logging of ERROR level to system out.
 
J

John Smith

John said:
Lew said:
Have you tried this? Why not? What happened when you did?

If I specifically put log4j.properties inside the jar file than both
the WS
application and the jar log to the defined file.

But if I only specify logging properties for the WS application, only the
application writes logs to the file and jar logs are not written.

Maybe the problem is that my jar file is in [tomcat]shared/lib
directory? (It
is purposely put there, not in WE-INF/lib)

Yes, that would have it loaded via a different class loader, so the JAR
classes are not in the inheritance hierarchy for the application classes.

Now I have managed to move the jar to the WEB-INF/lib of the Web
Service, but there are no logs from the jar in the WS log file.

If I put the log4j.properties in the jar with ERROR level, on for
example stdout than all logs (from WS, and from the jar) are being
logged, but with the LEVEL specified in the WS log4j configuration.

It seems that the level is being overriden, but not the appender.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top