• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

where to load log4j in a library

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

i am developing a library which logs stuff (with log4j). the library has no main entry point (static main(String[] args) and it is not deployed as web archive or similar so there is no possibility where it can be loaded with a kind of init-Servlet.

so i think of two possibilities:
1) loading configs somewhere in library (which seems to be ugly to me).
2) tell the library user to include log4jxxx.jar and load its settings up somewhere in his code and log4j.properties.

are there more possibilities?
 
Marshal
Posts: 28304
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to document the fact that you are using log4J. After all it's possible that the user of your library may be doing the same thing, and it would be bad behaviour for your library to replace the user's log4j configuration with your own configuration.

And it's also possible that the user of your library may want to have some say about where your library sends its logs to, so hard-coding any appenders into your library would also be bad behaviour.
[ August 15, 2006: Message edited by: Paul Clapham ]
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if this would work for you because of what you mention in your post, but I have a couple of deployment directories for all of my applications - C:\apps\lib, and C:\apps\conf.

In the C:\apps\lib I store all my supporting jars and the actual jars of the applications. In the manifests for my application's jar I include the jars that I reference like log4J. This would not work well if you manage multiple versions of jars for different apps, although you could keep the version named in the jar and reference that version for each application.

I use the C:\apps\conf directory to store a property file which over-rides the default property file in my jar. If an 'over-ride' property is set, I load in the property file and it has my log4J settings. This allows me to over-ride to turn off or add logging for different levels without having to change my code.

Hope this helps.

I'll include one of my samples below (from the property file) for the Log4J settings:



[ August 24, 2006: Message edited by: Greg Ostravich ]
[ August 24, 2006: Message edited by: Greg Ostravich ]
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic