Logging Levels in Log4j - Tutorialspoint Examples
Logging Levels in Log4j - Tutorialspoint Examples
Logginglevelsinlog4j|Tutorialspointexamples
Tutorialspointexamples
(http://tutorialspointexamples.com)
Learnjavatutorialwithexamplesforbeginnersonline
Search
LoggingLevelsInLog4j
Logginglevels:
Alllogginglevelsaredefinedintheorg.apache.log4j.Levelclass.Wecanalsocreateourownlevels.
Logginglevelsaregivenbelow:
1.ALL:Alllevelsincludingcustomlevelsalso.
2.DEBUG:Ithelpsdevelopersinapplicationdebugging.
3.INFO:Itgivestheinformationabouttheprogressofapplicationanditsstates.
4.WARN:Itgiveswarningforunexpectedevents.
5.ERROR:Itprovidestheinformationabouterrorevents.
6.FATAL:Itprovidestheinformationaboutapplicationabort.
7.OFF:Itturnsoffallthelogging.ItisoppositetotheALLlevel.
Standardorderofalllogginglevels:
ALL<DEBUG<INFO<WARN<ERROR<FATAL<OFF.
i.e.IflogginglevelsettoFATALthenonlyFATALmessageswillbedisplayed,iflogginglevelsetto
ERRORthenERRORandFATALmessageswillbedisplayedandsoon.
InthebelowexampleaswesettheloggingleveltoWARNsoonlyWARN,ERRORandFATALmessages
willbedisplayed.TheDEBUGandINFOmessagewillnotdisplay.
Example:
Log4jTest.java
http://tutorialspointexamples.com/logginglevelsinlog4jexampletutorial/
1/6
1/3/2016
Logginglevelsinlog4j|Tutorialspointexamples
importorg.apache.log4j.BasicConfigurator;
importorg.apache.log4j.Level;
importorg.apache.log4j.Logger;
/**
*Thisclassisusedtoshowtheuseof
*logginglevelsinLog4jwiththeBasicConfigurator.
*@authorjavawithease
*/
publicclassLog4jTest{
//GettheLoggerobject.
privatestaticLoggerlog=Logger.getLogger(Log4jTest.class);
publicstaticvoidmain(String[]args){
//ConfiguringLog4j,Itwilllogallmessagesonconsole.
//BasicConfiguratoruseConsoleAppenderandPatternLayout
//forallloggers.
BasicConfigurator.configure();
//Setlogginglevel
log.setLevel(Level.WARN);
//loggermessages
log.debug("Log4jdebugmessagetest.");
log.info("Log4jinfomessagetest.");
log.warn("Log4jwarnmessagetest.");
log.error("Log4jerrormessagetest.");
log.fatal("Log4jfatalmessagetest.");
}
}
Output:
0[main]WARNcom.javawithease.business.Log4jTest
Log4jwarnmessagetest.
1[main]ERRORcom.javawithease.business.Log4jTest
Log4jerrormessagetest.
1[main]FATALcom.javawithease.business.Log4jTest
Log4jfatalmessagetest.
Downloadthisexample.(http://tutorialspointexamples.com/wp
content/uploads/2014/09/Log4jExample3.rar)
NextTopic:Log4jfileappender.(http://tutorialspointexamples.com/log4jfileappender/)
PreviousTopic:Log4jexampleusinglog4jxmlfile.(http://tutorialspointexamples.com/log4j
exampleusinglog4jxmlfile/)
RelatedTopics:
Howtobuildjavaprojectusingantineclipse?(http://tutorialspointexamples.com/howtobuildjava
projectusingantineclipse/)
JAXBmarshallingconvertjavaobjecttoxmlexample.(http://tutorialspointexamples.com/jaxb
marshallingconvertjavaobjecttoxmlexampleusingonepojo/)
http://tutorialspointexamples.com/logginglevelsinlog4jexampletutorial/
2/6
1/3/2016
Logginglevelsinlog4j|Tutorialspointexamples
HowtocreatepdffileinjavausingiTextjar?(http://tutorialspointexamples.com/howtocreatepdffile
injavausingitextjar/)
Genericsclassexample.(http://tutorialspointexamples.com/genericsclassexample/)
OGNLinstruts2.(http://tutorialspointexamples.com/ognlinstruts2/)
HibernateOnetoOneMappingusingxml.(http://tutorialspointexamples.com/hibernateonetoone
mappingusingxml/)
SendinlineimageinemailusingJavaMailAPI.(http://tutorialspointexamples.com/sendinlineimage
inemailusingjavamailapi/)
Quartz2JobListenerexample.(http://tutorialspointexamples.com/quartz2joblistenerexample/)
11
0
0
Share
Share
10
0
Share
Share
Log4j Tutorial
Log4joverview.(http://tutorialspointexamples.com/log4joverview/)
Loggerclass.(http://tutorialspointexamples.com/loggerclass/)
Log4jexample.(http://tutorialspointexamples.com/log4jexample/)
Log4jpropertiesfile.(http://tutorialspointexamples.com/log4jexampleusinglog4jpropertiesfile/)
Log4jxmlfile.(http://tutorialspointexamples.com/log4jexampleusinglog4jxmlfile/)
Logginglevels.(http://tutorialspointexamples.com/logginglevelsinlog4j/)
Log4jfileappender.(http://tutorialspointexamples.com/log4jfileappender/)
Log4jmultipleappenders.(http://tutorialspointexamples.com/log4jmultipleappendersexample/)
http://tutorialspointexamples.com/logginglevelsinlog4jexampletutorial/
3/6