One way to solve your problem is to use automatic configuration (i.e rename to log4j.properties and add to your classpath).
On 9/3/05, Jason <[EMAIL PROTECTED]> wrote: > Hello, > > I'm in the process of adding log4j to a project I'm > working on and I have a question about a configuration > strategy. I'd like to initialize the configuration of > loggers in our system based on a common property file > named mysystemlog4j.properties. To this end, I've > added something like the following static block to the > class I happen to be working on: > > //Begin Code > static > { > URL url = > someclass1.class.getResource("/mysystemlog4j.properties"); > PropertyConfigurator.configure( url ); > } > //End Code > > This works fine as far as this class is concerned but > ideally I'l like this code to execute only once system > wide but I'm not sure how to accomplish this. The > system is such that there is no single class which I > can always count on to have been loaded before any > logging calls are made from elsewhere in the > application so there doesn't seem to be any natural > place to stick the static block. I'm considering > creating a class com.mycompany.utility.LogInit which > contains nothing but the static block and then > requiring each class which contains log statement to > create a new LogInit( ) in it's ctor. Obviously the > LogInit static block will only be executed once so > this will work but it seems there should be a better > solution. One last note: I'd rather stay away from > depending on any properties having been passed to the > vm as various components of the product might > ultimately end up in different scenarios where we > don't control startup of the vm. Any thoughts would > be greatly appreciated. > > -jason > > > > ____________________________________________________ > Start your day with Yahoo! - make it your home page > http://www.yahoo.com/r/hs > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- James Stauffer Are you good? Take the test at http://www.livingwaters.com/good/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]