0% found this document useful (0 votes)
398 views

Logging Levels in Log4j - Tutorialspoint Examples

Java Logging levels in log4j example tutorial. Log4j logging levels order hierarchy. Let us discuss how to use logging levels in log4j with example. http://tutorialspointexamples.com/logging-levels-in-log4j/. See more at: http://tutorialspointexamples.com/log4j-pdf-java-beginners-eclipse-code-download/

Uploaded by

Jai Pannu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
398 views

Logging Levels in Log4j - Tutorialspoint Examples

Java Logging levels in log4j example tutorial. Log4j logging levels order hierarchy. Let us discuss how to use logging levels in log4j with example. http://tutorialspointexamples.com/logging-levels-in-log4j/. See more at: http://tutorialspointexamples.com/log4j-pdf-java-beginners-eclipse-code-download/

Uploaded by

Jai Pannu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1/3/2016

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

You might also like