You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Kaneda K <ka...@dedaletechnology.com> on 2001/08/22 15:41:59 UTC
How to configure LOG4J
Hello,
As you can see I am new and I can not correctly configure Log4j in order
to publish different LEVEL out put so I'll ask few question :
1. just to be sure :
DEBUG < INFO < WARN < ERROR < FATAL
Which means that If I set my appender to DEBUG, I'll retrieve all the Log,
and I set to ERROR I'll only gonna retrieve ERROR and FATAL
?
2. This is where I have a problem I try to have 2 differentes output :
one for the log from com.foo.MyApp2 and another for the log from com.foo.Bar.
I obtain 2 file but they have the same value.
3. I Also try to have different Log level for those 2
this is my properties file : (the classes com.foo.MyApp2 and com.foo.Bar
are from the manual http://jakarta.apache.org/log4j/docs/manual.html)
# Log4 File
log4j.rootCategory=WARN, stdout, R1, R2
^ I set the default level here
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.stdout.category.com.foo=INFO
# getsion de R qui est pour les fichiers.
log4j.appender.R1=org.apache.log4j.RollingFileAppender
log4j.appender.R1.File=E:\\java\\jakarta-tomcat-3.3-b1\\webapps\\log4j\\WEB-INF\\log\\example1.log
log4j.appender.R1.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R1.MaxBackupIndex=1
log4j.appender.R1.layout=org.apache.log4j.PatternLayout
log4j.appender.R1.layout.ConversionPattern=[%p] %t (%c) - %m - %d{dd MMM
yyyy HH:mm:ss,SSS} %n
log4j.appender.R1.category.com.foo=INFO
^ this is where I set the level for file 1
log4j.appender.R2=org.apache.log4j.RollingFileAppender
log4j.appender.R2.File=E:\\java\\jakarta-tomcat-3.3-b1\\webapps\\log4j\\WEB-INF\\log\\example2.log
log4j.appender.R2.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R2.MaxBackupIndex=1
log4j.appender.R2.layout=org.apache.log4j.PatternLayout
log4j.appender.R2.layout.ConversionPattern=[%p] %t (%c) - %m - %d{dd MMM
yyyy HH:mm:ss,SSS} %n
log4j.appender.R2.category.com.foo.bar=ERROR
^ this is where I set the level for file 2
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
RE: Log4j and servlets - Reflection Error UPDATE
Posted by Craig Newlander <cn...@eqtc.com>.
update:
If using plain vanilla servlets then putting the .jar file in the
WEB-INF/lib directory and doing nothing to the classpath log4j works just
fine.
It seems that if you use reflection to instantiate a class that is using
log4j then the appropriate loj4j .jar file needs to be in the classpath
otherwise the relected class will not be instantiated.
Craig
-----Original Message-----
From: Ceki Gülcü [mailto:cgu@qos.ch]
Sent: Wednesday, August 22, 2001 2:37 PM
To: LOG4J Users Mailing List
Subject: Re: Log4j and servlets - Reflection Error
Craig,
No idea at all. Sorry I can't help. Ceki
At 09:55 22.08.2001 -0500, Craig Newlander wrote:
>Strange error here.
>In my Servlet class (foo) I defined a static field member as
>
>private static Category log;
>
>and in its Constructor is
>log = Category.getRoot();
>I can now log until the cows come home.
>
>Now then, I have another class (foobar) which is instantiated via
reflection
>by foo from foo's service() method
>
>foobar has a static field member as
>private static Category log;
>and in its Constructor is
>log = Category.getInstance( this.getClass().getName() );
>
>and when foo tries to reflect foobar I recevied a
>java.lang.reflect.InvocationTargetException:
java.lang.NoClassDefFoundError:
>org/apache/log4j/Category
>foobar never gets instantiated foo keeps chugging along and logs without a
>hitch?
>
>if I remove the log = from foobars construtor foobar can be reflected just
>fine.
>
>Any ideas?
--
Ceki Gülcü - http://qos.ch
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: Log4j and servlets - Reflection Error
Posted by Ceki Gülcü <cg...@qos.ch>.
Craig,
No idea at all. Sorry I can't help. Ceki
At 09:55 22.08.2001 -0500, Craig Newlander wrote:
>Strange error here.
>In my Servlet class (foo) I defined a static field member as
>
>private static Category log;
>
>and in its Constructor is
>log = Category.getRoot();
>I can now log until the cows come home.
>
>Now then, I have another class (foobar) which is instantiated via reflection
>by foo from foo's service() method
>
>foobar has a static field member as
>private static Category log;
>and in its Constructor is
>log = Category.getInstance( this.getClass().getName() );
>
>and when foo tries to reflect foobar I recevied a
>java.lang.reflect.InvocationTargetException: java.lang.NoClassDefFoundError:
>org/apache/log4j/Category
>foobar never gets instantiated foo keeps chugging along and logs without a
>hitch?
>
>if I remove the log = from foobars construtor foobar can be reflected just
>fine.
>
>Any ideas?
--
Ceki Gülcü - http://qos.ch
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: log4j wrapper
Posted by kk...@softalia.com.
hi!
> I'd like to absract log4j from my appilication so I don't have to do a
> import org.apache.log4j.* throughout my source files and be dependant on the
> Category class. What is a good method to employ here?
jdk1.4 has such APIs like this:
Class caller = sun.reflect.Reflection.getCallerClass(3);
which returns the Class of current methods caller^3;
whose name is then used in deciding which categories to pick.
(for now, I'm just parsing output of stack trace from a
locally created java.lang.Throwable object to get the
caller's name+method; there'd be a better way than this?)...
regards,
kenji
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: log4j wrapper
Posted by Don Taylor <do...@yahoo.com>.
--- Craig Newlander <cn...@eqtc.com> wrote:
> Hello,
>
> I'd like to absract log4j from my appilication so I don't have to
> do a
> import org.apache.log4j.* throughout my source files and be dependant
> on the
> Category class. What is a good method to employ here?
>
> Craig
>
I created a wrapper class around Category. You're going to create your
debug(), error(), fatal(), info(), and warn() methods in here. You'll
also need a fully-qualified-classname of the wrapper class. So here's
an example:
class Logger {
private static final String FQCN = Logger.class.getName();
public static void debug(Class c, Object message) {
Category.getInstance(c).log(FQCN, Priority.DEBUG, message, null);
}
public static void debug(Class c, Object message, Throwable t) {
Category.getInstance(c).log(FQCN, Priority.DEBUG, message, t);
}
/* Continue wrapping all the others... */
};
-- Don
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Re: log4j wrapper
Posted by Jin Zhao <JZ...@Qcorps.com>.
We also have a solution similar with Don's.
Usually a logger will wrapp all the categories we defined.
You pass the category name to the logging method to do the logging
for that category.
Jin
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
log4j wrapper
Posted by Craig Newlander <cn...@eqtc.com>.
Hello,
I'd like to absract log4j from my appilication so I don't have to do a
import org.apache.log4j.* throughout my source files and be dependant on the
Category class. What is a good method to employ here?
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
RE: Log4j and servlets - Reflection Error
Posted by Craig Newlander <cn...@eqtc.com>.
Putting the log4j.jar file in the lib directory of WEB-INF/ works fine
for servlets (but the not the classes w/ lo4j referencesthat the servlet
refelcts
After putting the .jar file in the classpath everything works fine.
I guess that makes sense.
-----Original Message-----
From: Thomas Tuft Muller [mailto:ttm@online.no]
Sent: Thursday, August 23, 2001 1:39 AM
To: LOG4J Users Mailing List
Subject: RE: Log4j and servlets - Reflection Error
There's a few unintentional discrepencies in the various VMs with respect to
reflection. I've e.g. seen the InvocationTargetTxception if I reflect with
an anonymous class as opposed to an explicitly defined inner class.
BTW, unless Foo is a Singleton, the static log field will be assigned for
each invocation of the constructor. A side-effect (unless Foo is final) is
that you reassign it when a sub-class of foo is created as well (that is if
the constructor assigning 'log' is called by this sub-class constructor).
This is probably NOT your intention.
I use a similar technique, but I let the category reference be an instance
variable. More memory consumption, but less side-effect prone.
--
Thomas
| -----Original Message-----
| From: Craig Newlander [mailto:cnewlander@eqtc.com]
| Sent: 22 August 2001 15:55
| To: LOG4J Users Mailing List
| Subject: Log4j and servlets - Reflection Error
|
|
| Strange error here.
| In my Servlet class (foo) I defined a static field member as
|
| private static Category log;
|
| and in its Constructor is
| log = Category.getRoot();
| I can now log until the cows come home.
|
| Now then, I have another class (foobar) which is instantiated via
| reflection
| by foo from foo's service() method
|
| foobar has a static field member as
| private static Category log;
| and in its Constructor is
| log = Category.getInstance( this.getClass().getName() );
|
| and when foo tries to reflect foobar I recevied a
| java.lang.reflect.InvocationTargetException:
| java.lang.NoClassDefFoundError:
| org/apache/log4j/Category
| foobar never gets instantiated foo keeps chugging along and logs without a
| hitch?
|
| if I remove the log = from foobars construtor foobar can be reflected just
| fine.
|
| Any ideas?
|
|
|
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
| For additional commands, e-mail: log4j-user-help@jakarta.apache.org
|
|
*************************************************************************
Copyright ERA Technology Ltd. 2001. (www.era.co.uk). All rights reserved.
Confidential. No liability whatsoever is accepted for any loss or damage
suffered as a result of accessing this message or any attachments.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
RE: Log4j and servlets - Reflection Error
Posted by Thomas Tuft Muller <tt...@online.no>.
There's a few unintentional discrepencies in the various VMs with respect to
reflection. I've e.g. seen the InvocationTargetTxception if I reflect with
an anonymous class as opposed to an explicitly defined inner class.
BTW, unless Foo is a Singleton, the static log field will be assigned for
each invocation of the constructor. A side-effect (unless Foo is final) is
that you reassign it when a sub-class of foo is created as well (that is if
the constructor assigning 'log' is called by this sub-class constructor).
This is probably NOT your intention.
I use a similar technique, but I let the category reference be an instance
variable. More memory consumption, but less side-effect prone.
--
Thomas
| -----Original Message-----
| From: Craig Newlander [mailto:cnewlander@eqtc.com]
| Sent: 22 August 2001 15:55
| To: LOG4J Users Mailing List
| Subject: Log4j and servlets - Reflection Error
|
|
| Strange error here.
| In my Servlet class (foo) I defined a static field member as
|
| private static Category log;
|
| and in its Constructor is
| log = Category.getRoot();
| I can now log until the cows come home.
|
| Now then, I have another class (foobar) which is instantiated via
| reflection
| by foo from foo's service() method
|
| foobar has a static field member as
| private static Category log;
| and in its Constructor is
| log = Category.getInstance( this.getClass().getName() );
|
| and when foo tries to reflect foobar I recevied a
| java.lang.reflect.InvocationTargetException:
| java.lang.NoClassDefFoundError:
| org/apache/log4j/Category
| foobar never gets instantiated foo keeps chugging along and logs without a
| hitch?
|
| if I remove the log = from foobars construtor foobar can be reflected just
| fine.
|
| Any ideas?
|
|
|
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
| For additional commands, e-mail: log4j-user-help@jakarta.apache.org
|
|
*************************************************************************
Copyright ERA Technology Ltd. 2001. (www.era.co.uk). All rights reserved.
Confidential. No liability whatsoever is accepted for any loss or damage
suffered as a result of accessing this message or any attachments.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org
Log4j and servlets - Reflection Error
Posted by Craig Newlander <cn...@eqtc.com>.
Strange error here.
In my Servlet class (foo) I defined a static field member as
private static Category log;
and in its Constructor is
log = Category.getRoot();
I can now log until the cows come home.
Now then, I have another class (foobar) which is instantiated via reflection
by foo from foo's service() method
foobar has a static field member as
private static Category log;
and in its Constructor is
log = Category.getInstance( this.getClass().getName() );
and when foo tries to reflect foobar I recevied a
java.lang.reflect.InvocationTargetException: java.lang.NoClassDefFoundError:
org/apache/log4j/Category
foobar never gets instantiated foo keeps chugging along and logs without a
hitch?
if I remove the log = from foobars construtor foobar can be reflected just
fine.
Any ideas?
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org