Finally it worked!!!
Thank you very much for your help.

Best Regards!

Carlos Yaconi Hitschfeld


-----Mensaje original-----
De: Jacob Kjome [mailto:[EMAIL PROTECTED] 
Enviado el: Jueves, 12 de Junio de 2003 13:51
Para: Log4J Users List
Asunto: RE: Problem configuring log4j with common classes



Depends where the properties file exists.  For example (in examples below 
MyClass.class is used so you can access this behavior in static contexts as 
well as instance contexts.  If you have a current instance, you can use 
this.getClass())...

//loads my.properties in the same relative package location as MyClass.class 
InputStream is = MyClass.class.getResourceAsStream("my.properties"):

//loads my.properties in the default (root) package
InputStream is = MyClass.class.getResourceAsStream("/my.properties"):

//loads my.properties from the my/package package anywhere in the current 
class loader
InputStream is = 
MyClass.class.getClassLoader().getResourceAsStream("my/package/my.properties"):

//loads my.properties from the my/package package relative to the default 
(root) package in the current class loader
InputStream is = 
MyClass.class.getClassLoader().getResourceAsStream("/my/package/my.properties"):

You can also replicate the latter two cases using the thread context class 
loader in order to load classes across any class loader in the JVM using... 
Thread.currentThread().getContextClassLoader().getResourceAsStream("my/package/my.properties");
and 
Thread.currentThread().getContextClassLoader().getResourceAsStream("/my/package/my.properties");


And then if you are in a servlet environment, you can do... 
getServletContext().getResourceAsStream("/WEB-INF/props/my.properties");

Hope that was specific enough for you.

Jake


At 12:51 PM 6/12/2003 -0400, you wrote:
>Thanks... But, can you give some example please??
>I'm newbie with log4j and I don't know how to do it.
>
>Thank you!
>
>Atte,
>Carlos Yaconi Hitschfeld
>Anexo: 8-4619
>Tel�fono: 388-4619
>
>
>-----Mensaje original-----
>De: Jacob Kjome [mailto:[EMAIL PROTECTED]
>Enviado el: Jueves, 12 de Junio de 2003 12:45
>Para: Log4J Users List
>Asunto: RE: Problem configuring log4j with common classes
>
>
>
>If you load the properties file with a file name, it will look for the 
>file in the location where the java process was started unless you 
>provide an absolute path to the file.  The better way to do this is 
>load it off the classloader and then provide it as an inputstream or 
>URL to the configure method.
>
>Jake
>
>At 12:37 PM 6/12/2003 -0400, you wrote:
> >Thanks Alison!!
> >Now I'm almost ready with my configuration, but the last (I hope) 
> >problem is where to put the log4j.properties for the common classes. 
> >I've tried putting the file inside the jar, on the root folder, and 
> >initializing it with the next sentence on a static block, in a class 
> >located inside of this jar:
> >
> >static{
> >         PropertyConfigurator.configure("log4j.properties");
> >}
> >
> >When log4j tried to read this file, it throws me a 
> >FileNotFoundException.
> >
> >What am I doing wrong????
> >
> >Thank you very much!!
> >
> >Atte,
> >Carlos Yaconi Hitschfeld
> >Anexo: 8-4619
> >Tel�fono: 388-4619
> >
> >
> >-----Mensaje original-----
> >De: Alison Ortega [mailto:[EMAIL PROTECTED]
> >Enviado el: Mi�rcoles, 11 de Junio de 2003 14:24
> >Para: [EMAIL PROTECTED]
> >Asunto: RE: Problem configuring log4j with common classes
> >
> >
> >What you have looks right, just do a static initializer block in your 
> >common classes like this: ... code to get the init file name and 
> >prefix ... static { PropertyConfigurator.configure(prefix+file);
> >}
> >
> >It goes in the class/instance data declarations section of your 
> >common class.  I suppose you could use an init servlet here, but then 
> >you would have to deploy your common classes as an app, which I 
> >didn't want to do. Btw, if you want to not have all the app logs 
> >duplicated in the common class logs, change the common class 
> >properties file to use log4j.rootCategory = info, appender list 
> >instead of log4j.logger...=info, appender list
> >and that will make the appender in the common class properties file the
> >root one, and you can prevent the other loggers (categories) from logging
> >to the parent (root) more easily.
> >
> >Let me know if you have any other questions.
> >
> >Alison Ortega
> >North Carolina State University
> >ACS
> >Systems Programmer II
> >919-513-1417
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to