| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|
#1 (permalink) |
|
Member
Join Date: Apr 2007
Location: Right now in Chennai
Posts: 30
Thanks: 5 Thanked 5 Times in 3 Posts Thanks: 5
Thanked 5 Times in 3 Posts
Rep Power: 2
|
log4j:WARN No appenders could be found for logger
hi,
i used logging in my java application. i placed log4j.jar and log4j.xml file paths given in classpath. i am getting 2 warning Messages. Those are as follows log4j:WARN No appenders could be found for logger (samp.Test1). log4j:WARN Please initialize the log4j system properly. log4j.xml is attached ...
Last edited by ananthkolli; 11-05-07 at 01:52 PM. |
|
|
|
|
|
#2 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 78 Times in 63 Posts Thanks: 57
Thanked 78 Times in 63 Posts
Rep Power: 17
|
Re: log4j:WARN No appenders could be found for logger
Hi ananth,
The problem is u r not telling the logger class from which file u have to get the configuration for logging. that is the problem over there , now what u have to do is u have to specify the logging class, which appender it has to use for logging purposes . let me give u an example on this If u r using the log4j properties file, then there is no need of telling the logger class, because the logger will be searching for the log4j.properties file by default. if this file is not present i,e ( u r defining the logging properties in an xml file , then u have to explicitly tell the logger class from which appender it has to take) Let us assume u have ur SampleLog.cfg.xml is present in your context root directory, then ur logger class should look like this import java.net.URL; import org.apache.log4j.Logger; import org.apache.log4j.xml.DOMConfigurator; public class SampleLogger { static{ try{ URL url = SampleLogger.class.getResource("/SampleLog.cfg.xml"); DOMConfigurator.configure(url); }catch(Exception e) { } } static Logger l=Logger.getLogger(SampleLogger.class.getName()); public static void debug(String msg) { l.debug(msg); } public static void info(String msg) { l.info(msg); } public static void warn(String msg) { l.warn(msg); } public static void error(String msg) { l.error(msg); } public static void fatal(String msg) { l.fatal(msg); } } Pls check the highlighted lines in the logger class, now u can understand what happens while logging any statement you have to log this way SampleLogger.info("This is my log info statement"); SampleLogger.debug("This is my log debug statement"); if u r loggin works properly, then usually the log will be created in the BIN directory/ root directory of your web/application server Let me know your questions Thank You
__________________
M0h@n Last edited by t_mohan; 14-05-07 at 08:11 PM. |
|
|
|
|
|
#4 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 78 Times in 63 Posts Thanks: 57
Thanked 78 Times in 63 Posts
Rep Power: 17
|
Re: log4j:WARN No appenders could be found for logger
Welcome Ananth,
Pls feel free to ask me if u have any more questions
__________________
M0h@n |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|