Inherit logging properties in ja custom jar library?

Discussion in 'Java' started by John Smith, Apr 26, 2011.

  1. John Smith

    John Smith Guest

    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.
    John Smith, Apr 26, 2011
    #1
    1. Advertising

  2. John Smith

    Lew Guest

    On 04/26/2011 06:53 AM, John Smith wrote:
    > 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?

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, Apr 26, 2011
    #2
    1. Advertising

  3. John Smith

    John Smith Guest

    On 26.4.2011. 15:52, Lew wrote:
    > On 04/26/2011 06:53 AM, John Smith wrote:
    >> 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?
    >


    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)
    John Smith, Apr 26, 2011
    #3
  4. John Smith

    Lew Guest

    John Smith wrote:
    > Lew wrote:
    >> 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.

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, Apr 26, 2011
    #4
  5. John Smith

    John Smith Guest

    On 26.4.2011. 17:38, Lew wrote:
    > John Smith wrote:
    >> Lew wrote:
    >>> 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.
    John Smith, Apr 27, 2011
    #5
  6. John Smith

    John Smith Guest

    On 26.4.2011. 17:38, Lew wrote:
    > John Smith wrote:
    >> Lew wrote:
    >>> 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.
    John Smith, Apr 27, 2011
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    0
    Views:
    567
    Arnold Peters
    Jan 5, 2005
  2. muttley
    Replies:
    0
    Views:
    2,717
    muttley
    Oct 20, 2005
  3. cyberco
    Replies:
    4
    Views:
    3,752
    Roedy Green
    Feb 14, 2006
  4. Arnold Peters
    Replies:
    0
    Views:
    657
    Arnold Peters
    Jan 5, 2005
  5. Andrew

    Custom Control - inherit child properties?

    Andrew, Jul 16, 2003, in forum: ASP .Net Building Controls
    Replies:
    6
    Views:
    187
    Andrew
    Jul 17, 2003
Loading...

Share This Page