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 Ri...@ahm.honda.com on 2005/08/16 21:16:33 UTC

Re: Log4j Configuration

William,

Two things you can try:

First, add an explicit path to the log file name.  So set it to
/var/log/axis/axis.log or /home/you/logs/axis.log or c:/tmp/logs/axis.log
or whatever is appropriate depending on platform, perms, etc.  You can also
do something like ${catalina.home}/logs/axis.log or something like that
too.  What's valid is very dependent on your environment, so play around
with that.  The default directory for log output is the current directory,
which in the case of a servlet container will usually be the container's
home directory.  So, for example, for Tomcat this means your
/usr/local/tomcat or c:\Tomcat or wherever you've got it installed.  I'm
not sure where these might go for other containers.

Second, check which log4j.properties file you're loading.  I have a little
code snippet here:
http://slapfest.blogspot.com/2005/07/what-version-of-class-or-resource-am-i.html

that you can use to find your log4j.properties.  There may be a problem
with that: in the cl.getResource() call, you may need to use
"log4j.properties" rather than "/log4j.properties", but I can't remember.
That'll tell you if your definition is even getting loaded or if your
servlet container is actually getting another log4j config from somewhere
else.

As far as your progammatically created appender, I can tell you why you
won't see any output from there: you're not adding the appender to your
logger.  Try something like this:

Logger logger = Logger.getLogger(EchoService.class);
BasicConfigurator.configure();

SimpleLayout layout = new SimpleLayout();

FileAppender appender = new FileAppender(layout,"connectionlog.txt",true);

if (appender != null)
{
    logger.addAppender(appender);
}

BTW, as far as the BasicConfigurator stuff?  My guess is that that call is
completely unnecessary and could even screw up your configuration (which is
another possible reason why you might not be seeing any output into your
log files, if it's somehow nuking the default configuration, which actually
uses PropertyConfigurator).



                                                                           
             "William Mok"                                                 
             <wmok@memotrax.co                                             
             m>                                                         To 
                                       "Log4J Users List"                  
             08/16/2005 11:57          <lo...@logging.apache.org>     
             AM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         Re: Log4j Configuration             
               "Log4J Users                                                
                   List"                                                   
             <log4j-user@loggi                                             
              ng.apache.org>                                               
                                                                           
                                                                           




Thanks,
I have included the log4j.properties file in the CLASSPATH and restart
tomcat, but I could not find any log file generated under the entire tomcat

directory, after running the servlet.

----- Original Message -----
From: "Harp, George" <GH...@GAINSystems.com>
To: "'Log4J Users List'" <lo...@logging.apache.org>
Sent: Tuesday, August 16, 2005 10:51 AM
Subject: RE: Log4j Configuration


>I don't have to put any configuration code in my appliaction I just make
> sure that log4j.properties or log4j.xml is in the clas path.
>
> -----Original Message-----
> From: William Mok [mailto:wmok@memotrax.com]
> Sent: Tuesday, August 16, 2005 12:35 PM
> To: log4j-user@logging.apache.org
> Subject: Log4j Configuration
>
>
> Hi,
>
> I have the following log4j.properties file:
>
>
----------------------------------------------------------------------------

> -----------------------------------
> # Set root category priority to INFO and its only appender to CONSOLE.
> log4j.rootCategory=INFO, CONSOLE
> #log4j.rootCategory=INFO, CONSOLE, LOGFILE
>
> # Set the enterprise logger category to FATAL and its only appender to
> CONSOLE.
> log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
>
> # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
> log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
> log4j.appender.CONSOLE.Threshold=INFO
> log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
> log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
>
> # LOGFILE is set to be a File appender using a PatternLayout.
> log4j.appender.LOGFILE=org.apache.log4j.FileAppender
> log4j.appender.LOGFILE.File=axis.log
> log4j.appender.LOGFILE.Append=true
> log4j.appender.LOGFILE.Threshold=INFO
> log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
> log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x -
> %m%n
>
----------------------------------------------------------------------------

> --------------------------------------------------------
>
> At the same time, I also have the following lines in my java servlet
>
>
----------------------------------------------------------------------------

> --------------------------------------------------------
>           Logger logger = Logger.getLogger(EchoService.class);
>                BasicConfigurator.configure();
>
>                SimpleLayout layout = new SimpleLayout();
>
>                FileAppender appender = null;
>
>                try
>                {
>                        appender = new
> FileAppender(layout,"connectionlog.txt",true);
>                }
>
----------------------------------------------------------------------------

> ------------------------------------------------------------
>
> Questions:
>
> 1. So how does this configuration work, does the java code override the
> configuration on properties file?
> 2. What does BasicConfigurator do?
> 3. In propertes file, log4j.appender.LOGFILE.File=axis.log, but I cannot
> find this axis.log anywhere after running the servlet.
> In the java servlet, I have the line "appender = new
> FileAppender(layout,"connectionlog.txt",true);", but I cannot find the
> connectionlog.txt file anywhere.
>
> Thanks.
>
> William
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j Configuration

Posted by Ri...@ahm.honda.com.
"William Mok" <wm...@memotrax.com> wrote on 08/17/2005 05:47:29 PM:
> Your explanation is a lot better than those I found on web. Thx.
> I still have some questions, see below:

Cool, glad it helped.  I've run into all these problems before, so that why
I've got a good knowledge of all the ways you can screw it up :^)

> ----- Original Message -----
> From: <Ri...@ahm.honda.com>
> > "William Mok" <wm...@memotrax.com> wrote on 08/16/2005 03:59:25 PM:
> >> Thanks. Your explanation make everything much clearer.
> > 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?

The root logger is just kind of a default handler so that if you don't have
any specific logging stuff set up for a particular area of your code
there's a place for the messages to go.  That's why the root logger is
usually set to ERROR or FATAL.  Wherever a critical error occurs in your
code, you generally want to know about it.

Child loggers for particular parts of your code hierarchy then let you set
the logging levels and output for particular parts of the functionality
you're developing.  You can set the root logger to ERROR, so that anything
critical that occurs anywhere in your application is logged.  You can then
set the logging levels for each area that you're developing to different
levels so you can see what's going on in there.  So let's say, in addition
to all of the framework code, you've got two packages in your application,
one for business objects and one for the interface.  When you're working on
the business objects, you can set the logging level to DEBUG and get
verbose information about that package, but set the interface logging level
to WARN.  This means that you'll see a ton of information in the logs about
your business objects and only interesting stuff about your interface code.
Now you've developed the business objects, change the settings to WARN for
your business objects and DEBUG for your interface and get a ton of
information about your interface code.  This change in the amount and type
of information you get from each section is done without changing your code
at all, since the filtering is done by just not sending messages to the log
when they're sent with Logger.debug() when that's below the logging level
you've set.

The cool thing is that, if you're suddenly getting weird results from a
section of your code, just ratchet down the logging level and you get a
bunch more information out of that section.  For example, when I've got a
bunch of queries that are getting run, I always output the query itself as
info and usually output the results (as long as there aren't TOO too many
results expected) with debug.  That way, if something odd happens, I can
see the query and its results without having to step through the debugger
slowly, etc.

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

Yeah, then that's just a matter of figuring out what your servlet container
thinks is stdout.



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j Configuration

Posted by William Mok <wm...@memotrax.com>.
Your explanation is a lot better than those I found on web. Thx.
I still have some questions, see below:

----- Original Message ----- 
From: <Ri...@ahm.honda.com>
To: "Log4J Users List" <lo...@logging.apache.org>
Sent: Wednesday, August 17, 2005 8:43 AM
Subject: Re: Log4j Configuration


>
> "William Mok" <wm...@memotrax.com> 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: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j Configuration

Posted by Ri...@ahm.honda.com.
"William Mok" <wm...@memotrax.com> 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.

> 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 :^)

> 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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j Configuration

Posted by William Mok <wm...@memotrax.com>.
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.

Also the check for ClassLoader seems to fail, i.e. cl = NULL as I cannot 
find the "Search and destroy" in any logs.
However, I believe the log4j.properties has been picked up otherwise the 
axis.log file will not be created.

ClassLoader cl = Thread.currentThread().getContextClassLoader();
  while(cl != null)
  {
     java.net.URL loc = cl.getResource("/log4j.properties");
     System.out.println("Search and destroy --> " + loc);
     cl = cl.getParent();
  }


----- Original Message ----- 
From: <Ri...@ahm.honda.com>
To: "Log4J Users List" <lo...@logging.apache.org>
Sent: Tuesday, August 16, 2005 12:52 PM
Subject: Re: Log4j Configuration


> If you create an appender programmatically and independently of the
> properties file, then it will simply work as an additional appender for
> that logger and be completely unaffected by the settings in the properties
> file.  Note that you can do this same thing with the properties file and 
> in
> fact, having just looked at your properties file, I know why, even if
> everything else is set properly, you're not getting any output to your
> axis.log file.  Because you never send anything there.  Note that I 
> removed
> all of the appender definitions other than the name and class assignment:
>
> # Set root category priority to INFO and its only appender to CONSOLE.
> log4j.rootCategory=INFO, CONSOLE
> #log4j.rootCategory=INFO, CONSOLE, LOGFILE
>
> # Set the enterprise logger category to FATAL and its only appender to
> CONSOLE.
> log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
>
> # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
> log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
> ...
>
> # LOGFILE is set to be a File appender using a PatternLayout.
> log4j.appender.LOGFILE=org.apache.log4j.FileAppender
> ...
>
> Basically, you have to understand that loggers and appenders are 
> completely
> independent.  Thus, you create an appender called CONSOLE which logs to 
> the
> console (stdout) and an appender called LOGFILE that logs to axis.log.
> Great.  Create a file and never write anything to it, and see how fast it
> fills up.  Now you create a logger, a rootCategory logger, one for a
> specific package (e.g. your logger for org.apache.axis.enterprise), or
> whatever.  You can set two main attributes for that logger (there are
> others, but don't worry about them for now): the default level for that
> logger (INFO for root and FATAL for org.apache.axis.enterprise) and the
> appender or APPENDERS to which the logger will write its messages.  In 
> this
> file, you're sending everything to the CONSOLE and nothing to the LOGFILE.
> What you probably want to do is something like this:
>
> # Set root category priority to INFO and its only appender to CONSOLE.
> log4j.rootCategory=INFO, CONSOLE
>
> # Set the enterprise logger category to DEBUG and its appenders to CONSOLE
> and LOGFILE
> log4j.logger.org.apache.axis.enterprise=DEBUG, CONSOLE, LOGFILE
>
> # Then add the appender defines here
>
> I'm assuming that, because that LOGFILE appender is called axis.log that
> you want it set for your Axis stuff, so I added it to that.  I also set 
> the
> debug level down to DEBUG instead of FATAL, but really you can set it to
> whatever you want.
>
> So now, based on your properties definition, any message of DEBUG level or
> higher (i.e. pretty much all messages) sent to the
> org.apache.axis.enterprise logger (which will be messages from any class 
> in
> that package or below) will go to the CONSOLE and to the LOGFILE logs. 
> Any
> message of INFO or higher from any other packages will go only to the
> CONSOLE.
>
> Then, when you create a programmatic appender and assign it to a logger,
> messages sent to that logger will go to your new appender IN ADDITION to
> any other appenders already configured for that logger.
>
> Got it? :^)
>
>
>
>
>             "William Mok"
>             <wmok@memotrax.co
>             m>                                                         To
>                                       "Log4J Users List"
>             08/16/2005 12:27          <lo...@logging.apache.org>
>             PM                                                         cc
>
>                                                                   Subject
>             Please respond to         Re: Log4j Configuration
>               "Log4J Users
>                   List"
>             <log4j-user@loggi
>              ng.apache.org>
>
>
>
>
>
>
> Thanks. Rick.
>
> I am going to try all the stuff u advise. However, the thing I don't
> understand is how the log4j. properties file
> work with the FileAppender API call in the code. What I mean is the
> log4j.properties specify a file appender, and then in the code I specify
> another file appender, so is there a conflict?
>
> William
>
> ----- Original Message -----
> From: <Ri...@ahm.honda.com>
> To: "Log4J Users List" <lo...@logging.apache.org>
> Sent: Tuesday, August 16, 2005 12:16 PM
> Subject: Re: Log4j Configuration
>
>
>> William,
>>
>> Two things you can try:
>>
>> First, add an explicit path to the log file name.  So set it to
>> /var/log/axis/axis.log or /home/you/logs/axis.log or c:/tmp/logs/axis.log
>> or whatever is appropriate depending on platform, perms, etc.  You can
>> also
>> do something like ${catalina.home}/logs/axis.log or something like that
>> too.  What's valid is very dependent on your environment, so play around
>> with that.  The default directory for log output is the current
> directory,
>> which in the case of a servlet container will usually be the container's
>> home directory.  So, for example, for Tomcat this means your
>> /usr/local/tomcat or c:\Tomcat or wherever you've got it installed.  I'm
>> not sure where these might go for other containers.
>>
>> Second, check which log4j.properties file you're loading.  I have a
> little
>> code snippet here:
>>
> http://slapfest.blogspot.com/2005/07/what-version-of-class-or-resource-am-i.html
>
>>
>> that you can use to find your log4j.properties.  There may be a problem
>> with that: in the cl.getResource() call, you may need to use
>> "log4j.properties" rather than "/log4j.properties", but I can't remember.
>> That'll tell you if your definition is even getting loaded or if your
>> servlet container is actually getting another log4j config from somewhere
>> else.
>>
>> As far as your progammatically created appender, I can tell you why you
>> won't see any output from there: you're not adding the appender to your
>> logger.  Try something like this:
>>
>> Logger logger = Logger.getLogger(EchoService.class);
>> BasicConfigurator.configure();
>>
>> SimpleLayout layout = new SimpleLayout();
>>
>> FileAppender appender = new
> FileAppender(layout,"connectionlog.txt",true);
>>
>> if (appender != null)
>> {
>>    logger.addAppender(appender);
>> }
>>
>> BTW, as far as the BasicConfigurator stuff?  My guess is that that call
> is
>> completely unnecessary and could even screw up your configuration (which
>> is
>> another possible reason why you might not be seeing any output into your
>> log files, if it's somehow nuking the default configuration, which
>> actually
>> uses PropertyConfigurator).
>>
>>
>>
>>
>>             "William Mok"
>>             <wmok@memotrax.co
>>             m>                                                         To
>>                                       "Log4J Users List"
>>             08/16/2005 11:57          <lo...@logging.apache.org>
>>             AM                                                         cc
>>
>>                                                                   Subject
>>             Please respond to         Re: Log4j Configuration
>>               "Log4J Users
>>                   List"
>>             <log4j-user@loggi
>>              ng.apache.org>
>>
>>
>>
>>
>>
>>
>> Thanks,
>> I have included the log4j.properties file in the CLASSPATH and restart
>> tomcat, but I could not find any log file generated under the entire
>> tomcat
>>
>> directory, after running the servlet.
>>
>> ----- Original Message -----
>> From: "Harp, George" <GH...@GAINSystems.com>
>> To: "'Log4J Users List'" <lo...@logging.apache.org>
>> Sent: Tuesday, August 16, 2005 10:51 AM
>> Subject: RE: Log4j Configuration
>>
>>
>>>I don't have to put any configuration code in my appliaction I just make
>>> sure that log4j.properties or log4j.xml is in the clas path.
>>>
>>> -----Original Message-----
>>> From: William Mok [mailto:wmok@memotrax.com]
>>> Sent: Tuesday, August 16, 2005 12:35 PM
>>> To: log4j-user@logging.apache.org
>>> Subject: Log4j Configuration
>>>
>>>
>>> Hi,
>>>
>>> I have the following log4j.properties file:
>>>
>>>
>>
> ----------------------------------------------------------------------------
>
>>
>>> -----------------------------------
>>> # Set root category priority to INFO and its only appender to CONSOLE.
>>> log4j.rootCategory=INFO, CONSOLE
>>> #log4j.rootCategory=INFO, CONSOLE, LOGFILE
>>>
>>> # Set the enterprise logger category to FATAL and its only appender to
>>> CONSOLE.
>>> log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
>>>
>>> # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
>>> log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
>>> log4j.appender.CONSOLE.Threshold=INFO
>>> log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
>>> log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
>>>
>>> # LOGFILE is set to be a File appender using a PatternLayout.
>>> log4j.appender.LOGFILE=org.apache.log4j.FileAppender
>>> log4j.appender.LOGFILE.File=axis.log
>>> log4j.appender.LOGFILE.Append=true
>>> log4j.appender.LOGFILE.Threshold=INFO
>>> log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
>>> log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x -
>>> %m%n
>>>
>>
> ----------------------------------------------------------------------------
>
>>
>>> --------------------------------------------------------
>>>
>>> At the same time, I also have the following lines in my java servlet
>>>
>>>
>>
> ----------------------------------------------------------------------------
>
>>
>>> --------------------------------------------------------
>>>           Logger logger = Logger.getLogger(EchoService.class);
>>>                BasicConfigurator.configure();
>>>
>>>                SimpleLayout layout = new SimpleLayout();
>>>
>>>                FileAppender appender = null;
>>>
>>>                try
>>>                {
>>>                        appender = new
>>> FileAppender(layout,"connectionlog.txt",true);
>>>                }
>>>
>>
> ----------------------------------------------------------------------------
>
>>
>>> ------------------------------------------------------------
>>>
>>> Questions:
>>>
>>> 1. So how does this configuration work, does the java code override the
>>> configuration on properties file?
>>> 2. What does BasicConfigurator do?
>>> 3. In propertes file, log4j.appender.LOGFILE.File=axis.log, but I cannot
>>> find this axis.log anywhere after running the servlet.
>>> In the java servlet, I have the line "appender = new
>>> FileAppender(layout,"connectionlog.txt",true);", but I cannot find the
>>> connectionlog.txt file anywhere.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j Configuration

Posted by Ri...@ahm.honda.com.
If you create an appender programmatically and independently of the
properties file, then it will simply work as an additional appender for
that logger and be completely unaffected by the settings in the properties
file.  Note that you can do this same thing with the properties file and in
fact, having just looked at your properties file, I know why, even if
everything else is set properly, you're not getting any output to your
axis.log file.  Because you never send anything there.  Note that I removed
all of the appender definitions other than the name and class assignment:

# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE
#log4j.rootCategory=INFO, CONSOLE, LOGFILE

# Set the enterprise logger category to FATAL and its only appender to
CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE

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

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

Basically, you have to understand that loggers and appenders are completely
independent.  Thus, you create an appender called CONSOLE which logs to the
console (stdout) and an appender called LOGFILE that logs to axis.log.
Great.  Create a file and never write anything to it, and see how fast it
fills up.  Now you create a logger, a rootCategory logger, one for a
specific package (e.g. your logger for org.apache.axis.enterprise), or
whatever.  You can set two main attributes for that logger (there are
others, but don't worry about them for now): the default level for that
logger (INFO for root and FATAL for org.apache.axis.enterprise) and the
appender or APPENDERS to which the logger will write its messages.  In this
file, you're sending everything to the CONSOLE and nothing to the LOGFILE.
What you probably want to do is something like this:

# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE

# Set the enterprise logger category to DEBUG and its appenders to CONSOLE
and LOGFILE
log4j.logger.org.apache.axis.enterprise=DEBUG, CONSOLE, LOGFILE

# Then add the appender defines here

I'm assuming that, because that LOGFILE appender is called axis.log that
you want it set for your Axis stuff, so I added it to that.  I also set the
debug level down to DEBUG instead of FATAL, but really you can set it to
whatever you want.

So now, based on your properties definition, any message of DEBUG level or
higher (i.e. pretty much all messages) sent to the
org.apache.axis.enterprise logger (which will be messages from any class in
that package or below) will go to the CONSOLE and to the LOGFILE logs.  Any
message of INFO or higher from any other packages will go only to the
CONSOLE.

Then, when you create a programmatic appender and assign it to a logger,
messages sent to that logger will go to your new appender IN ADDITION to
any other appenders already configured for that logger.

Got it? :^)



                                                                           
             "William Mok"                                                 
             <wmok@memotrax.co                                             
             m>                                                         To 
                                       "Log4J Users List"                  
             08/16/2005 12:27          <lo...@logging.apache.org>     
             PM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         Re: Log4j Configuration             
               "Log4J Users                                                
                   List"                                                   
             <log4j-user@loggi                                             
              ng.apache.org>                                               
                                                                           
                                                                           




Thanks. Rick.

I am going to try all the stuff u advise. However, the thing I don't
understand is how the log4j. properties file
work with the FileAppender API call in the code. What I mean is the
log4j.properties specify a file appender, and then in the code I specify
another file appender, so is there a conflict?

William

----- Original Message -----
From: <Ri...@ahm.honda.com>
To: "Log4J Users List" <lo...@logging.apache.org>
Sent: Tuesday, August 16, 2005 12:16 PM
Subject: Re: Log4j Configuration


> William,
>
> Two things you can try:
>
> First, add an explicit path to the log file name.  So set it to
> /var/log/axis/axis.log or /home/you/logs/axis.log or c:/tmp/logs/axis.log
> or whatever is appropriate depending on platform, perms, etc.  You can
> also
> do something like ${catalina.home}/logs/axis.log or something like that
> too.  What's valid is very dependent on your environment, so play around
> with that.  The default directory for log output is the current
directory,
> which in the case of a servlet container will usually be the container's
> home directory.  So, for example, for Tomcat this means your
> /usr/local/tomcat or c:\Tomcat or wherever you've got it installed.  I'm
> not sure where these might go for other containers.
>
> Second, check which log4j.properties file you're loading.  I have a
little
> code snippet here:
>
http://slapfest.blogspot.com/2005/07/what-version-of-class-or-resource-am-i.html

>
> that you can use to find your log4j.properties.  There may be a problem
> with that: in the cl.getResource() call, you may need to use
> "log4j.properties" rather than "/log4j.properties", but I can't remember.
> That'll tell you if your definition is even getting loaded or if your
> servlet container is actually getting another log4j config from somewhere
> else.
>
> As far as your progammatically created appender, I can tell you why you
> won't see any output from there: you're not adding the appender to your
> logger.  Try something like this:
>
> Logger logger = Logger.getLogger(EchoService.class);
> BasicConfigurator.configure();
>
> SimpleLayout layout = new SimpleLayout();
>
> FileAppender appender = new
FileAppender(layout,"connectionlog.txt",true);
>
> if (appender != null)
> {
>    logger.addAppender(appender);
> }
>
> BTW, as far as the BasicConfigurator stuff?  My guess is that that call
is
> completely unnecessary and could even screw up your configuration (which
> is
> another possible reason why you might not be seeing any output into your
> log files, if it's somehow nuking the default configuration, which
> actually
> uses PropertyConfigurator).
>
>
>
>
>             "William Mok"
>             <wmok@memotrax.co
>             m>                                                         To
>                                       "Log4J Users List"
>             08/16/2005 11:57          <lo...@logging.apache.org>
>             AM                                                         cc
>
>                                                                   Subject
>             Please respond to         Re: Log4j Configuration
>               "Log4J Users
>                   List"
>             <log4j-user@loggi
>              ng.apache.org>
>
>
>
>
>
>
> Thanks,
> I have included the log4j.properties file in the CLASSPATH and restart
> tomcat, but I could not find any log file generated under the entire
> tomcat
>
> directory, after running the servlet.
>
> ----- Original Message -----
> From: "Harp, George" <GH...@GAINSystems.com>
> To: "'Log4J Users List'" <lo...@logging.apache.org>
> Sent: Tuesday, August 16, 2005 10:51 AM
> Subject: RE: Log4j Configuration
>
>
>>I don't have to put any configuration code in my appliaction I just make
>> sure that log4j.properties or log4j.xml is in the clas path.
>>
>> -----Original Message-----
>> From: William Mok [mailto:wmok@memotrax.com]
>> Sent: Tuesday, August 16, 2005 12:35 PM
>> To: log4j-user@logging.apache.org
>> Subject: Log4j Configuration
>>
>>
>> Hi,
>>
>> I have the following log4j.properties file:
>>
>>
>
----------------------------------------------------------------------------

>
>> -----------------------------------
>> # Set root category priority to INFO and its only appender to CONSOLE.
>> log4j.rootCategory=INFO, CONSOLE
>> #log4j.rootCategory=INFO, CONSOLE, LOGFILE
>>
>> # Set the enterprise logger category to FATAL and its only appender to
>> CONSOLE.
>> log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
>>
>> # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
>> log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
>> log4j.appender.CONSOLE.Threshold=INFO
>> log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
>> log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
>>
>> # LOGFILE is set to be a File appender using a PatternLayout.
>> log4j.appender.LOGFILE=org.apache.log4j.FileAppender
>> log4j.appender.LOGFILE.File=axis.log
>> log4j.appender.LOGFILE.Append=true
>> log4j.appender.LOGFILE.Threshold=INFO
>> log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
>> log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x -
>> %m%n
>>
>
----------------------------------------------------------------------------

>
>> --------------------------------------------------------
>>
>> At the same time, I also have the following lines in my java servlet
>>
>>
>
----------------------------------------------------------------------------

>
>> --------------------------------------------------------
>>           Logger logger = Logger.getLogger(EchoService.class);
>>                BasicConfigurator.configure();
>>
>>                SimpleLayout layout = new SimpleLayout();
>>
>>                FileAppender appender = null;
>>
>>                try
>>                {
>>                        appender = new
>> FileAppender(layout,"connectionlog.txt",true);
>>                }
>>
>
----------------------------------------------------------------------------

>
>> ------------------------------------------------------------
>>
>> Questions:
>>
>> 1. So how does this configuration work, does the java code override the
>> configuration on properties file?
>> 2. What does BasicConfigurator do?
>> 3. In propertes file, log4j.appender.LOGFILE.File=axis.log, but I cannot
>> find this axis.log anywhere after running the servlet.
>> In the java servlet, I have the line "appender = new
>> FileAppender(layout,"connectionlog.txt",true);", but I cannot find the
>> connectionlog.txt file anywhere.



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j Configuration

Posted by William Mok <wm...@memotrax.com>.
Thanks. Rick.

I am going to try all the stuff u advise. However, the thing I don't 
understand is how the log4j. properties file
work with the FileAppender API call in the code. What I mean is the 
log4j.properties specify a file appender, and then in the code I specify 
another file appender, so is there a conflict?

William

----- Original Message ----- 
From: <Ri...@ahm.honda.com>
To: "Log4J Users List" <lo...@logging.apache.org>
Sent: Tuesday, August 16, 2005 12:16 PM
Subject: Re: Log4j Configuration


> William,
>
> Two things you can try:
>
> First, add an explicit path to the log file name.  So set it to
> /var/log/axis/axis.log or /home/you/logs/axis.log or c:/tmp/logs/axis.log
> or whatever is appropriate depending on platform, perms, etc.  You can 
> also
> do something like ${catalina.home}/logs/axis.log or something like that
> too.  What's valid is very dependent on your environment, so play around
> with that.  The default directory for log output is the current directory,
> which in the case of a servlet container will usually be the container's
> home directory.  So, for example, for Tomcat this means your
> /usr/local/tomcat or c:\Tomcat or wherever you've got it installed.  I'm
> not sure where these might go for other containers.
>
> Second, check which log4j.properties file you're loading.  I have a little
> code snippet here:
> http://slapfest.blogspot.com/2005/07/what-version-of-class-or-resource-am-i.html
>
> that you can use to find your log4j.properties.  There may be a problem
> with that: in the cl.getResource() call, you may need to use
> "log4j.properties" rather than "/log4j.properties", but I can't remember.
> That'll tell you if your definition is even getting loaded or if your
> servlet container is actually getting another log4j config from somewhere
> else.
>
> As far as your progammatically created appender, I can tell you why you
> won't see any output from there: you're not adding the appender to your
> logger.  Try something like this:
>
> Logger logger = Logger.getLogger(EchoService.class);
> BasicConfigurator.configure();
>
> SimpleLayout layout = new SimpleLayout();
>
> FileAppender appender = new FileAppender(layout,"connectionlog.txt",true);
>
> if (appender != null)
> {
>    logger.addAppender(appender);
> }
>
> BTW, as far as the BasicConfigurator stuff?  My guess is that that call is
> completely unnecessary and could even screw up your configuration (which 
> is
> another possible reason why you might not be seeing any output into your
> log files, if it's somehow nuking the default configuration, which 
> actually
> uses PropertyConfigurator).
>
>
>
>
>             "William Mok"
>             <wmok@memotrax.co
>             m>                                                         To
>                                       "Log4J Users List"
>             08/16/2005 11:57          <lo...@logging.apache.org>
>             AM                                                         cc
>
>                                                                   Subject
>             Please respond to         Re: Log4j Configuration
>               "Log4J Users
>                   List"
>             <log4j-user@loggi
>              ng.apache.org>
>
>
>
>
>
>
> Thanks,
> I have included the log4j.properties file in the CLASSPATH and restart
> tomcat, but I could not find any log file generated under the entire 
> tomcat
>
> directory, after running the servlet.
>
> ----- Original Message -----
> From: "Harp, George" <GH...@GAINSystems.com>
> To: "'Log4J Users List'" <lo...@logging.apache.org>
> Sent: Tuesday, August 16, 2005 10:51 AM
> Subject: RE: Log4j Configuration
>
>
>>I don't have to put any configuration code in my appliaction I just make
>> sure that log4j.properties or log4j.xml is in the clas path.
>>
>> -----Original Message-----
>> From: William Mok [mailto:wmok@memotrax.com]
>> Sent: Tuesday, August 16, 2005 12:35 PM
>> To: log4j-user@logging.apache.org
>> Subject: Log4j Configuration
>>
>>
>> Hi,
>>
>> I have the following log4j.properties file:
>>
>>
> ----------------------------------------------------------------------------
>
>> -----------------------------------
>> # Set root category priority to INFO and its only appender to CONSOLE.
>> log4j.rootCategory=INFO, CONSOLE
>> #log4j.rootCategory=INFO, CONSOLE, LOGFILE
>>
>> # Set the enterprise logger category to FATAL and its only appender to
>> CONSOLE.
>> log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
>>
>> # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
>> log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
>> log4j.appender.CONSOLE.Threshold=INFO
>> log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
>> log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
>>
>> # LOGFILE is set to be a File appender using a PatternLayout.
>> log4j.appender.LOGFILE=org.apache.log4j.FileAppender
>> log4j.appender.LOGFILE.File=axis.log
>> log4j.appender.LOGFILE.Append=true
>> log4j.appender.LOGFILE.Threshold=INFO
>> log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
>> log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x -
>> %m%n
>>
> ----------------------------------------------------------------------------
>
>> --------------------------------------------------------
>>
>> At the same time, I also have the following lines in my java servlet
>>
>>
> ----------------------------------------------------------------------------
>
>> --------------------------------------------------------
>>           Logger logger = Logger.getLogger(EchoService.class);
>>                BasicConfigurator.configure();
>>
>>                SimpleLayout layout = new SimpleLayout();
>>
>>                FileAppender appender = null;
>>
>>                try
>>                {
>>                        appender = new
>> FileAppender(layout,"connectionlog.txt",true);
>>                }
>>
> ----------------------------------------------------------------------------
>
>> ------------------------------------------------------------
>>
>> Questions:
>>
>> 1. So how does this configuration work, does the java code override the
>> configuration on properties file?
>> 2. What does BasicConfigurator do?
>> 3. In propertes file, log4j.appender.LOGFILE.File=axis.log, but I cannot
>> find this axis.log anywhere after running the servlet.
>> In the java servlet, I have the line "appender = new
>> FileAppender(layout,"connectionlog.txt",true);", but I cannot find the
>> connectionlog.txt file anywhere.
>>
>> Thanks.
>>
>> William
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org