• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using Reflection to dynamically load logging classes

 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic