• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Reflection to dynamically load logging classes  RSS feed

 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the blog:
http://www.jroller.com/page/gstamp/20030812


What we eventually realised was that no one really cares about our
logging but us so what we did was not use logging at all by default
.
.
.
it is loaded by reflection so no external logging classes are
referenced unless the user explicitly enables them


Ok... what is my first clue on how to do this? (aside from asking in poi-developer, or just looking the source, since it's Open Source.

My library classes all use log4j, and so my libraries instantly require log4j. I'd love to be able to have them run with or without.

Has anyone attempted this sort of thing before?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know his exact situation, but I've done a number of things to reduce package dependencies in my own little projects. For example, what if all logging statements used an object that was defined only by an interface.

Now the code has no idea what the actual logger class is.
But that test for null is ugly and you have to do it every time you log. Easy to forget. How about a special NullLogger that does nothing?

This kind of thing is common in discussions of package dependencies. Here's a presentation I did for my team: http://www.surfscranton.com/architecture/DependencyInversion.htm. It has a picture of Robert Martin's book which is a treasure trove of good stuff like this.
Hope that answer matched your question. Look into the OO, UML etc. forum further down the ranch for lots more talk about such design principles.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!