Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#34 How to use a custom logger

open-later
Bill Horsman
5
2007-03-19
2007-03-15
Wojtek
No

I just d/l 0.9.0RC3 and cannot get proxool to use my custom logger. The http://proxool.sourceforge.net/logging.html page says:

"However, there is no reason why you shouldn't write your own implementation of Log and log wherever you wish."

However the Log link is a 404.

I have tried setting the System property from System.setProperty("org.logicalcobwebs.logging.Log", "com.myapp.ProxoolLog") to System.setProperty("org.apache.commons.logging.Log", "com.myapp.ProxoolLog") but that does not work.

How do I get Proxool to use my logger as per version 0.8.3?

Discussion

  • Bill Horsman
    Bill Horsman
    2007-03-15

    • labels: --> 483555
    • assigned_to: nobody --> billhorsman
    • status: open --> open-later
     
  • Bill Horsman
    Bill Horsman
    2007-03-15

    Logged In: YES
    user_id=91747
    Originator: NO

    Sorry, it looks like that documentation is out of date. We have now unbundled Commons Logging and have it as a dependency. That means that to use a custom logger then you need to refer to the Commons Logging documentation. It's a while since I did what you're trying to do so I'd prefer to send you to their site to look for the answer:

    http://jakarta.apache.org/commons/logging/

    Thanks for pointing out our out of date docs. I'll fix that for the 0.9.0 release and leave this bug open in the meantime.

    -
    Bill

     
  • Wojtek
    Wojtek
    2007-03-19

    Logged In: YES
    user_id=1742490
    Originator: YES

    I have my class properly set up as per the Javadocs for the comons logger. However Proxool still only echos to the Apache log.

    The commons API states that you should put the log implementation call in the Apache startup command line. This means that my application log will gather log messages for Apache (and ALL other Apache applications). This is not desirable.

    I cannot get this to work. I have tried every reasonable class.method() call to try to get Proxool to use my log wrapper class. None of them worked.

    Could you put the 0.8.3 way of logging back? Or at least give me the option of using either?

     
  • Bill Horsman
    Bill Horsman
    2007-03-19

    Logged In: YES
    user_id=91747
    Originator: NO

    Have you tried configuring it in a file called commons-logging.properties and putting that in the same place as your proxool.jar? Something like:

    org.apache.commons.logging.Log=com.myapp.ProxoolLog

    You're right that that will change the log implementation for all applications loading that copy of proxool.jar. I wonder whether you could extend org.apache.commons.logging.impl.Log4JLogger and just call super.foo() if you don't want to handle it?

    I'm afraid that it is no trivial task to bundle Commons Logging back into Proxool and nor do we want to do so. Having two separate logging infrastructures caused more hassle than it was worth. We now log events in the same way as most other Java components, I believe.

    Finally, is your proxool.jar in your WEB-INF/lib directory? Do you share a Proxool pool across applications? Having it in your webapp should give you more control and at least allow you to restrict the use of com.myapp.ProxoolLog to your application.

    Let me know how you get on.

    -
    Bill

     
  • Wojtek
    Wojtek
    2007-03-19

    Logged In: YES
    user_id=1742490
    Originator: YES

    This is for an Intranet site which is not that busy. As such we share a number of Web apps on the same server in the same Apache runtime. Currently two apps use Proxool using different pool names. Each application has its own log directory and each has a Web page which displays the logs.

    If there is only one way to hook into the Proxool logging, and that is through the Apache logging mechanism, then that means that I can only tell Apache about one of the application's implementation of the Log interface. Then that application must gather all the Apache and Proxool logging messages and then decide where the actual message goes. Also, if one of the applications is not running (maintenance etc), then NO Proxool logging takes place if that is the one doing the logging.

    Each application uses a counter which is incremented in a synchronized method. The counter is written out to the one of four log files (info, error, trace, sql). This lets me see the exact order of log messages within the application. If a single application is trying to log for many applications, I will not be able to maintain this synchronization.

    In un-bundling logging from Proxool you have created a huge headache for me :-((

    Or else I forego logging Proxool events. Which means that I cannot provide the kind of detailed log which I gave you in my other bug thread....

     
  • Bill Horsman
    Bill Horsman
    2007-03-19

    Logged In: YES
    user_id=91747
    Originator: NO

    I'm guessing that you don't put proxool.jar in your WEB-INF/lib directory (you didn't answer that question). If you do put it there then I'm pretty sure you can configure each app to only collect its own log events by putting commons-logging.properties into WEB-INF/classes. Have you tried that?

    If all else fails then it's really easy for you to repackage Commons Logging yourself (using Jar Jar) and then to do a global replace in the Proxool source so that the Log classes use your new repackaged code. If you drop the original commons logging jar your IDE will quickly tell you what needs to be changed. You could even script that whole process in an Ant file. I'm sorry that our change has given you more work but we made that change because several people needed it and nobody objected it when we checked on the dev list before doing it). I believe the current method most closely follows best practice although I concede that it's not entirely black and white.

    I'm quite happy to help you solve this, but don't think that reverting to the 0.8 behaviour is the correct thing to do.

    -
    Bill

     
  • Bill Horsman
    Bill Horsman
    2007-03-19

    • labels: 483555 --> 483556
     
  • Wojtek
    Wojtek
    2007-03-19

    Logged In: YES
    user_id=1742490
    Originator: YES

    Sorry about the lib question.

    Yes, each app has its own copy of proxool.jar in the WEB-INF/lib directory, and I am not sharing pools.

    I have put the commons-logging.properties file with the suggested line in the WEB-INF/lib directory, however it is not being used. Proxool still writes to the Apache log.

    I also have the commons-logging.jar in the same directory, which I assume proxool is using?

    My ProxoolLog wrapper is not being used at all. I tried causing an error by removing the constructor which accepts a String parameter, but no error message was given.

    I deleted commons-logging.jar from the WEB-INF/lib and no error message was given.

    I placed the properties file in the Tomcat bin directory (where commons.logging-api.jar is). Again no messages or errors.

     
  • Bill Horsman
    Bill Horsman
    2007-03-19

    Logged In: YES
    user_id=91747
    Originator: NO

    I believe it should go in WEB-INF/classes not WEB-INF/lib. Also, you might find that Proxool loads the commons-logging JAR from the Tomcat shared libs directory. In which case, class loading rears its ugly head. The Tomcat shared lib can't see inside your webapp so won't detect the properties file. Lets' see what happens though.

     
  • Wojtek
    Wojtek
    2007-03-19

    Logged In: YES
    user_id=1742490
    Originator: YES

    Placing the properties file into WEB-INF/classes worked. It also appears to be segregated from other Proxool logs and the normal Tomcat log. Need to do more testing, but at first glance it works.

    Thanks!

     
  • Wojtek
    Wojtek
    2007-03-19

    Logged In: YES
    user_id=1742490
    Originator: YES

    One last thing. I placed a log statement into the constructor of my wrapper. I thought that I would get one log event from this. However:

    2007.03.19 11:59:51.359: Name is: org.logicalcobwebs.proxool.ProxoolDriver
    2007.03.19 11:59:51.375: Name is: org.logicalcobwebs.proxool.ProxoolFacade
    2007.03.19 11:59:51.375: Name is: org.logicalcobwebs.proxool.CompositeProxoolListener
    2007.03.19 11:59:51.390: Name is: org.logicalcobwebs.proxool.Version
    2007.03.19 11:59:51.390: Name is: org.logicalcobwebs.proxool.ConnectionPoolDefinition
    2007.03.19 11:59:51.390: Name is: org.logicalcobwebs.proxool.rcmp.SIIMS
    2007.03.19 11:59:51.406: Name is: org.logicalcobwebs.proxool.ConnectionPool
    2007.03.19 11:59:51.406: Name is: org.logicalcobwebs.proxool.CompositeConnectionListener
    2007.03.19 11:59:51.421: Name is: org.logicalcobwebs.proxool.CompositeStateListener
    2007.03.19 11:59:51.703: Name is: org.logicalcobwebs.proxool.ShutdownHook
    2007.03.19 11:59:51.718: Name is: org.logicalcobwebs.proxool.Prototyper
    2007.03.19 11:59:51.718: Name is: org.logicalcobwebs.proxool.HouseKeeperController
    2007.03.19 11:59:51.718: Name is: org.logicalcobwebs.proxool.HouseKeeper
    2007.03.19 11:59:51.718: Name is: org.logicalcobwebs.proxool.HouseKeeperThread
    2007.03.19 11:59:51.796: Name is: org.logicalcobwebs.proxool.PrototyperController
    2007.03.19 11:59:51.812: Name is: org.logicalcobwebs.proxool.PrototyperThread
    2007.03.19 11:59:51.828: Name is: org.logicalcobwebs.proxool.ProxyConnection
    2007.03.19 11:59:51.859: Name is: org.logicalcobwebs.proxool.ProxyFactory
    2007.03.19 11:59:51.921: Name is: org.logicalcobwebs.proxool.WrappedConnection
    2007.03.19 11:59:52.218: Name is: org.logicalcobwebs.proxool.ProxyDatabaseMetaData
    2007.03.19 11:59:52.484: Name is: org.logicalcobwebs.proxool.ProxyStatement
    2007.03.19 11:59:58.015: Name is: org.apache.catalina.core.ApplicationDispatcher
    2007.03.19 11:59:58.031: Name is: org.apache.jasper.servlet.JspServletWrapper
    2007.03.19 11:59:58.031: Name is: org.apache.jasper.compiler.Compiler
    2007.03.19 11:59:58.078: Name is: org.apache.jasper.runtime.PageContextImpl
    2007.03.19 11:59:58.125: Name is: org.apache.tomcat.util.buf.C2BConverter

    That is a LOT of instances.

     
  • Bill Horsman
    Bill Horsman
    2007-03-19

    Logged In: YES
    user_id=91747
    Originator: NO

    I suppose it is. But we're fetching logger instances according to the Jakarta documentation. For instance:

    Log LOG = LogFactory.getLog(ProxoolFacade.class);

    Either you should lobby Jakarta Commons to create fewer instances or make your instances more lightweight but there doesn't seem to by much we can, or should, be doing from Proxool.

    I'm glad you got it working though. Perhaps we can improve our documentation. On the one hand it's not really part of Proxool's remit to do document the logger - on the other hand, if it helps people out then we probably should.

    -
    Bill

     
  • Wojtek
    Wojtek
    2007-03-19

    Logged In: YES
    user_id=1742490
    Originator: YES

    All it is is a wrapper implementing the Log interface. No other methods or properties. I was not complaining, just surprised.

    It would be appreciated if you could note in your documentation that the common-logging.properties file (and its contents) must be added to the WEB-INF/classes directory. I tried to read the Google hits off common-logging.properties and it was not obvious that that was where it has to go.

    Since Proxool uses the Tomcat logging library, I also do not need to include common-logging.jar in my application's WEB-INF/lib directory.

    Thanks again!

     
  • Bill Horsman
    Bill Horsman
    2007-03-19

    • labels: 483556 --> Documentation
     
  • Bill Horsman
    Bill Horsman
    2007-03-19

    Logged In: YES
    user_id=91747
    Originator: NO

    I agree that it would be helpful to improve the documentation for the 0.9.0 release. Thanks for your feedback. It's always good to see someone persevere to find a solution. I'm glad we got something worked out. -Bill