logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Krieg <akr...@marketaxess.com>
Subject Attaching appenders to root
Date Mon, 18 Feb 2002 23:21:02 GMT
I know this question is in the FAQ, but the explanation is a little unclear
as to how to resolve this problem.

I'm trying to run the example seen in the manual and I'm getting log4j: 

No appenders could be found for category (ma.bridge.jdbc.MyApp).

I see that this as an item in the FAQ, but my example is nearly equivalent
to the example in the manual and it still doesn't work.  The FAQ says:
"Log4j does not have a default logging target. It is the user's
responsibility to ensure that all categories can inherit an appender. This
can be easily achieved by attaching an appender to the root category."  but
provides no detail on how to do that.  So I looked at my config.properties
file:

log4j.rootLogger=debug, stdout
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


It appears that the first line is attaching the appender "stdout" to the
rootLogger.  So what's going on here?

My Java file looks like this:

package ma.bridge.jdbc;

 import org.apache.log4j.Category;
 import org.apache.log4j.PropertyConfigurator;
 
 public class MyApp {

   static Category logger = Category.getInstance(MyApp.class.getName());

   public static void main(String[] args) {

     
     // BasicConfigurator replaced with PropertyConfigurator.
     PropertyConfigurator.configure(args[0]);

     logger.info("Entering application.");
     logger.info("Exiting application.");    
   }
 }

Thanks in advance,
Adam



log4j tells me to initialize properly.
Logging output is written to a target by using an appender. If no appenders
are attached to a category nor to any of its ancestors, you will get the
following message when trying to log: 

log4j: No appenders could be found for category (some.category.name).
log4j: Please initialize the log4j system properly.


-----Original Message-----
From: Adam Krieg [mailto:akrieg@marketaxess.com]
Sent: Monday, February 18, 2002 3:56 PM
To: 'log4j-user@jakarta.apache.org'
Subject: Centralized Logging class and the State of Log4J


I'm considering using Log4J for a new project, but have some questions about
it that I need to be answered before I make my decision.  I'm interested in
having a single logging class that client classes can call just by writing:

MyLogger.debug(this,"log statement");

I'm passing in a reference to the object in order to keep track of who's
calling the logger, so that the logger can print out that info, if needed.
There will be one configuration for the whole application, which will get
set in this MyLogger class.  But in reading the documentation, it seems that
every class that wants to use the logger has to get an instance of
Category/Logger along the ways of

static Category = Category.getInstance("MyClassName");  ?

If so, that will be a pain when Category gets thrown out the window in a
year.  I'll have to change Category.getInstance to Logger.getLogger all over
the place and use Level instead of Priority and a whole bunch of other
stuff.  I would like to wrap up all this log4J API specific stuff in one
class so when 2003 rolls around, I'm not in global search and replace mode
all over my code.  

This brings me to my second question.  I would use version 1.2, but was put
off by the statement:Log4j version 1.2 is not feature-complete, nor is the
documentation up to date, so I hesitated to use it.  On the other hand it is
obvious that changes on a very fundamental level (Priority vs Level,
Category vs Logger) are occurring going from 1.1 to 1.2, so what is a
developer to do?  What is everybody else doing with this?

Thanks in advance,
Adam


--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:log4j-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:log4j-user-help@jakarta.apache.org>


Mime
View raw message