Your explanation is a lot better than those I found on web. Thx.
I still have some questions, see below:

----- Original Message ----- From: <[EMAIL PROTECTED]>
To: "Log4J Users List" <log4j-user@logging.apache.org>
Sent: Wednesday, August 17, 2005 8:43 AM
Subject: Re: Log4j Configuration



"William Mok" <[EMAIL PROTECTED]> wrote on 08/16/2005 03:59:25 PM:
Thanks. Your explanation make everything much clearer.

I modified the log4j.properties file and run the servlet again, I can
only
see empty file axis.log being created but there is no logging inside.

The issue with that is most likely one of two things:

* The logging level is set so that debug or info messages are not being
sent, so you won't see any messages unless something bad happens (warn,
error, fatal). Try knocking down the logging level to debug and see if you
get anything.

* From your previous code, it looks like you had the axis.log appender
attached to classes in the org.apache.axis.enterprise package and below.
That's Axis code, not your own. So when you do the Logger.getLogger() call
on your own class (EchoService?), it's actually retrieving a logger for
com.mycompany.mypackage.echo.EchoService, or whatever the package is that
contains that class. If there are no loggers defined for any level of that
hierarchy (i.e. com, com.mycompany, com.mycompany.mypackage, etc.), then
you'll get the root category logger.  Try redefining that logger to
something like:

# Set the my logger to DEBUG and add the my appender.
log4j.logger.com.mycompany.mypackage.echo=DEBUG, CONSOLE, ECHO

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
...

# ECHO is set to be a File appender using a PatternLayout.
log4j.appender.ECHO=org.apache.log4j.FileAppender
...

Look at the call to Logger.getLogger(EchoService.class): what it does is
retrieves the fully qualified name of that class, e.g.
com.mycompany.mypackage.echo.EchoService.  It then looks for a logger
defined for com.mycompany.mypackage.echo.EchoService.  If it doesn't find
that, it'll look for the next step up the hierarchy, i.e.
com.mycompany.mypackage.echo, then com.mycompany.mypackage, and so on.
Once you've defined this logger for com.mycompany.mypackage.echo, that's
what it'll find.  It will then write whatever messages you send to that
logger to the defined appenders, as long as those messages have the
effective level of the logger or above.

I am a bit confused about the rootlogger and childlogger concepts, what's the reason behind having different logging hierarchy? What does the rootLogger actually do? , i.e. when do I use the rootLogger?


Also the check for ClassLoader seems to fail, i.e. cl = NULL as I cannot
find the "Search and destroy" in any logs.

That's probably because the stdout is being diverted somewhere.  If you're
running your servlet container (e.g. Tomcat) from a shell script, then that
message will be displayed on the actual console.  If you're running from a
service on Windows or some other script on *nix, then stdout is usually
diverted to something like localhost_log.<date>.txt or something like that.
Another option is to replace the System.out.println() call by opening a
file in a known location and writing out to that.  It's completely
impossible that you're not getting a class loader, otherwise... well, none
of your classes would load :^)

That's correct, if I run it using Eclipse, I can see the "search and destroy" on the Eclipse console but not appearing in any of the logs.


However, I believe the log4j.properties has been picked up otherwise the
axis.log file will not be created.

Definitely. That right there proves that your instance of log4j.properties
is being loaded.



---------------------------------------------------------------------
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