SlideShare a Scribd company logo
1 of 30
www.SunilOS.com 1
www.sunilos.com
www.raystec.com
Log4J
03/17/16
03/17/16 www.SunilOS.com 2
Introduction
Use Log4J as a standard approach to log
messages in an application.
Messages can be logged to Console, File,
Network, Database etc.
In other words you can print or store your
application messages to Console or File or
Database or other targets.
It is originally developed by IBM
Now it is Open Source
Logging – Conventional Approach
Write all messages on Console.
Console has limitations.
03/17/16 www.SunilOS.com 3
Application
System.out.println
(“Email is working”);
03/17/16 www.SunilOS.com 4
Message Level
 Logging messages can be categorized as
o Debug Message
 S.o.p(“Now inserting record …..”);
o Information Message
 S.o.p(“Email server is started”);
o Warning Message
 S.o.p(“Email server is not started, Email may get delayed”);
o Error Message
 S.o.p(“IP Exception – Shared drive not accessible”);
o Fatal Message
 S.o.p(“Database server is down”);
 Log4J gives separate methods to log different level of
messages
Log4J : Appenders
Log4J facilitates message logging on
multiple targets
o Console
o File
o Network
o FTP
o Database, etc.
An Appender is configured for each target.
03/17/16 www.SunilOS.com 5
03/17/16 www.SunilOS.com 6
Log Messages
 import org.apache.log4j.Logger;
 public class Test{
 static Logger log = Logger.getLogger(Test.class);//Create Logger
 public static void main(String[] args) {
 log.debug("This is Debug Statement");
 log.info("This is Info Statement");
 log.warn("This is Warn Statement");
 log.error("This is Error Statement");
 log.fatal("This is Fatal Statement");
o int i = 0;
o try {
 int x = 5 / i;
o } catch (RuntimeException e) {
 log.error("Arithmetic Error ",e);
o }
 }
 }
03/17/16 www.SunilOS.com 7
Output
 28 Jun 2007 17:35:41 DEBUG TestLog:15 - This is Debug Statement
 28 Jun 2007 17:35:41 INFO TestLog:16 - This is Info Statement
 28 Jun 2007 17:35:41 WARN TestLog:17 - This is Warn Statement
 28 Jun 2007 17:35:41 ERROR TestLog:18 - This is Error Statement
 28 Jun 2007 17:35:41 FATAL TestLog:19 - This is Fatal Statement
 28 Jun 2007 17:35:41 ERROR TestLog:26 - Arithmetic Error
 java.lang.ArithmeticException: / by zero
 at com.log4J.TestLog.main(TestLog.java:24)
03/17/16 www.SunilOS.com 8
Level Priorities
 Level Priorities
o debug< info< warn < error <fatal
 Logging level can be defined in the log4j.properties.
o log4j.rootLogger=debug, stdout
 Log4J will log all the messages for defined level and its high
priority level.
 For example if defined level is debug then it will log
messages for debug, info, warn and fatal.
 If defined level is warn then it will log messages for warn ,
error and fatal levels.
Configuration File
log4j.properties
XML can also be used
Keep it in root class path folder
It will configure
oAppenders
oMessage Layout
oMessage Target
03/17/16 www.SunilOS.com 9
Appender
An Appender is an object that sends log
messages to their final destination.
It defines message targets.
o Console
o File
o Network
o FTP
o Database
o Etc.
03/17/16 www.SunilOS.com 10
Console Appender
03/17/16 www.SunilOS.com 11
03/17/16 www.SunilOS.com 12
Console Appender
Log messages on Console
Configure Standard Output Appender
### direct log messages to std out ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{dd MMM yyyy
HH:mm:ss} %5p %c{1}:%L - %m%n
### set log category - debug,info,warn,error,fatal
log4j.rootLogger=debug,stdout
File Appender
03/17/16 www.SunilOS.com 13
03/17/16 www.SunilOS.com 14
File Appender
Log messages in a File
### direct messages to file hibernate.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:/temp/corejava.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy
HH:mm:ss} %5p %c{1}:%L - %m%n
### set log category - debug,info,warn,error,fatal
log4j.rootLogger=debug,file, stdout
Message will be sent to two appenders file and stdout
Rolling File Appender
It will roll (create) log files based on size or date or
both depending on configuration.
That means new log file will be created when
03/17/16 www.SunilOS.com 15
File size is full
Date is changed
03/17/16 www.SunilOS.com 16
Other Appenders
 SocketAppender – Dumps log output to a socket
 SyslogAppender – Write to the syslog.
 NTEventLogAppender – Write the logs to the NT Event Log
system.
 SocketAppender – Dumps log output to a socket
 SMTPAppender – Sends Messages to email
 JMSAppender – Sends messages using Java Messaging
Service
 Or create your own. Not that difficult.
Message Pattern
log4j.appender.file.layout.ConversionPattern
=%d{dd MMM yyyy HH:mm:ss} %5p %c{1}:
%L - %m%n
Used to customize the layout of a log entry.
The format is closely related to conversion
pattern of the printf function in ‘c’ language.
03/17/16 www.SunilOS.com 17
03/17/16 www.SunilOS.com 18
PatternLayout Options
 c - Used to output the category of the logging event.
 C - Used to output the fully qualified class name of the caller issuing the logging
request.
 d - Used to output the date of the logging event. The date conversion specifier
may be followed by a date format specifier enclosed between braces. For
example, %d{HH:mm:ss,SSS} or %d{dd MMM yyyy HH:mm:ss,SSS}. If no date
format specifier is given then ISO8601 format is assumed
 F - Used to output the file name where the logging request was issued.
 l - Used to output location information of the caller which generated the logging
event. (C+M+L)
 L - Used to output the line number from where the logging request was issued.
03/17/16 www.SunilOS.com 19
PatternLayout ( Contd.)
 n - Outputs the platform dependent line separator character or
characters.
 M - Used to output the method name where the logging request was
issued.
 p - Used to output the priority of the logging event.
 t - Used to output the name of the thread that generated the logging
event.
 x - Used to output the NDC (nested diagnostic context) associated with
the thread that generated the logging event.
Application Environments
There are different application environment
for different kind of users
Developer develops application in
development Environment
Tester tests application in QA Environment
End User accesses application from
Production Environment ( Live Server )
03/17/16 www.SunilOS.com 20
03/17/16 www.SunilOS.com 21
Application Environments
Development
Tomcat
MySQL
Test ( QA )
Tomcat
MySQL
Production
Tomcat
MySQL
Developer Testers End User
03/17/16 www.SunilOS.com 22
Application Environments
Development
JBoss
Oracle
Test ( QA )
JBoss
Oracle
Production
JBoss
Oracle
Developer Testers End User
03/17/16 www.SunilOS.com 23
Application Environments
Development
Tomcat
Oracle
Test ( QA )
Tomcat
Production
Tomcat
DB
Developer Testers End User
03/17/16 www.SunilOS.com 24
Environments
Development
JBoss
Oracle
Test ( QA )
JBoss
Production
JBoss
Oracle
Developer Testers End User
App Env & Message Level
There are different message levels for
different application environments
o Development Environment : debug
o Test (QA) Environment : info
o Production : warn
03/17/16 www.SunilOS.com 25
Say NO to
System.out.println(“message”);
03/17/16 www.SunilOS.com 26
Say YES to
Log4J
03/17/16 www.SunilOS.com 27
Dependency
log4j.jar
03/17/16 www.SunilOS.com 28
Disclaimer
This is an educational presentation to enhance the
skill of computer science students.
This presentation is available for free to computer
science students.
Some internet images from different URLs are
used in this presentation to simplify technical
examples and correlate examples with the real
world.
We are grateful to owners of these URLs and
pictures.
www.SunilOS.com 2903/17/16
Thank You!
www.SunilOS.com 30
www.SunilOS.com
03/17/16

More Related Content

What's hot

Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4Sunil OS
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/ServletSunil OS
 
Exception Handling
Exception HandlingException Handling
Exception HandlingSunil OS
 
JavaScript
JavaScriptJavaScript
JavaScriptSunil OS
 
Collections Framework
Collections FrameworkCollections Framework
Collections FrameworkSunil OS
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and ConcurrencySunil OS
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and OperatorsSunil OS
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File HandlingSunil OS
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )Sunil OS
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answerskavinilavuG
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulationIntro C# Book
 

What's hot (20)

Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
C++
C++C++
C++
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
 
Java Basics
Java BasicsJava Basics
Java Basics
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
PDBC
PDBCPDBC
PDBC
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answers
 
C Basics
C BasicsC Basics
C Basics
 
Optional in Java 8
Optional in Java 8Optional in Java 8
Optional in Java 8
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
 

Viewers also liked

C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 
Resource Bundle
Resource BundleResource Bundle
Resource BundleSunil OS
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays TechnologiesSunil OS
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFCSunil OS
 
Eschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School SoftwareEschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School SoftwareMayank Jain
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaRavikiran J
 

Viewers also liked (9)

C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
Resource Bundle
Resource BundleResource Bundle
Resource Bundle
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays Technologies
 
C++ oop
C++ oopC++ oop
C++ oop
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFC
 
Eschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School SoftwareEschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School Software
 
Hibernate & JPA perfomance
Hibernate & JPA perfomance Hibernate & JPA perfomance
Hibernate & JPA perfomance
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 
Hibernate
HibernateHibernate
Hibernate
 

Similar to Log4 J

Trouble shoot with linux syslog
Trouble shoot with linux syslogTrouble shoot with linux syslog
Trouble shoot with linux syslogashok191
 
Back-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETBack-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETDavid McCarter
 
Back-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETBack-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETDavid McCarter
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_netNico Ludwig
 
27.1.5 lab convert data into a universal format
27.1.5 lab   convert data into a universal format27.1.5 lab   convert data into a universal format
27.1.5 lab convert data into a universal formatFreddy Buenaño
 
TechDoc - WMB - Administration - Logs
TechDoc - WMB - Administration - LogsTechDoc - WMB - Administration - Logs
TechDoc - WMB - Administration - LogsGlen Brumbaugh
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCIS321
 
Crash dump analysis - experience sharing
Crash dump analysis - experience sharingCrash dump analysis - experience sharing
Crash dump analysis - experience sharingJames Hsieh
 
Logging & Metrics with Docker
Logging & Metrics with DockerLogging & Metrics with Docker
Logging & Metrics with DockerStefan Zier
 
Logging Services for .net - log4net
Logging Services for .net - log4netLogging Services for .net - log4net
Logging Services for .net - log4netGuo Albert
 
Building of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingBuilding of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingPVS-Studio
 
OpenNTF Domino API - Overview Introduction
OpenNTF Domino API - Overview IntroductionOpenNTF Domino API - Overview Introduction
OpenNTF Domino API - Overview IntroductionPaul Withers
 

Similar to Log4 J (20)

Trouble shoot with linux syslog
Trouble shoot with linux syslogTrouble shoot with linux syslog
Trouble shoot with linux syslog
 
Log4j
Log4jLog4j
Log4j
 
11i Logs
11i Logs11i Logs
11i Logs
 
Mp lab manual
Mp lab manualMp lab manual
Mp lab manual
 
Back-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETBack-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NET
 
Back-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETBack-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NET
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
27.1.5 lab convert data into a universal format
27.1.5 lab   convert data into a universal format27.1.5 lab   convert data into a universal format
27.1.5 lab convert data into a universal format
 
TechDoc - WMB - Administration - Logs
TechDoc - WMB - Administration - LogsTechDoc - WMB - Administration - Logs
TechDoc - WMB - Administration - Logs
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
 
Logging
LoggingLogging
Logging
 
Crash dump analysis - experience sharing
Crash dump analysis - experience sharingCrash dump analysis - experience sharing
Crash dump analysis - experience sharing
 
Logging & Metrics with Docker
Logging & Metrics with DockerLogging & Metrics with Docker
Logging & Metrics with Docker
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
Logging Services for .net - log4net
Logging Services for .net - log4netLogging Services for .net - log4net
Logging Services for .net - log4net
 
Building of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code loggingBuilding of systems of automatic C/C++ code logging
Building of systems of automatic C/C++ code logging
 
Backtrack Manual Part6
Backtrack Manual Part6Backtrack Manual Part6
Backtrack Manual Part6
 
project_docs
project_docsproject_docs
project_docs
 
Unix Administration 5
Unix Administration 5Unix Administration 5
Unix Administration 5
 
OpenNTF Domino API - Overview Introduction
OpenNTF Domino API - Overview IntroductionOpenNTF Domino API - Overview Introduction
OpenNTF Domino API - Overview Introduction
 

More from Sunil OS

Threads v3
Threads v3Threads v3
Threads v3Sunil OS
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3Sunil OS
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )Sunil OS
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )Sunil OS
 
Python Pandas
Python PandasPython Pandas
Python PandasSunil OS
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1Sunil OS
 
Angular 8
Angular 8 Angular 8
Angular 8 Sunil OS
 
Python Part 1
Python Part 1Python Part 1
Python Part 1Sunil OS
 

More from Sunil OS (10)

DJango
DJangoDJango
DJango
 
OOP v3
OOP v3OOP v3
OOP v3
 
Threads v3
Threads v3Threads v3
Threads v3
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 

Recently uploaded

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 

Recently uploaded (20)

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 

Log4 J

  • 2. 03/17/16 www.SunilOS.com 2 Introduction Use Log4J as a standard approach to log messages in an application. Messages can be logged to Console, File, Network, Database etc. In other words you can print or store your application messages to Console or File or Database or other targets. It is originally developed by IBM Now it is Open Source
  • 3. Logging – Conventional Approach Write all messages on Console. Console has limitations. 03/17/16 www.SunilOS.com 3 Application System.out.println (“Email is working”);
  • 4. 03/17/16 www.SunilOS.com 4 Message Level  Logging messages can be categorized as o Debug Message  S.o.p(“Now inserting record …..”); o Information Message  S.o.p(“Email server is started”); o Warning Message  S.o.p(“Email server is not started, Email may get delayed”); o Error Message  S.o.p(“IP Exception – Shared drive not accessible”); o Fatal Message  S.o.p(“Database server is down”);  Log4J gives separate methods to log different level of messages
  • 5. Log4J : Appenders Log4J facilitates message logging on multiple targets o Console o File o Network o FTP o Database, etc. An Appender is configured for each target. 03/17/16 www.SunilOS.com 5
  • 6. 03/17/16 www.SunilOS.com 6 Log Messages  import org.apache.log4j.Logger;  public class Test{  static Logger log = Logger.getLogger(Test.class);//Create Logger  public static void main(String[] args) {  log.debug("This is Debug Statement");  log.info("This is Info Statement");  log.warn("This is Warn Statement");  log.error("This is Error Statement");  log.fatal("This is Fatal Statement"); o int i = 0; o try {  int x = 5 / i; o } catch (RuntimeException e) {  log.error("Arithmetic Error ",e); o }  }  }
  • 7. 03/17/16 www.SunilOS.com 7 Output  28 Jun 2007 17:35:41 DEBUG TestLog:15 - This is Debug Statement  28 Jun 2007 17:35:41 INFO TestLog:16 - This is Info Statement  28 Jun 2007 17:35:41 WARN TestLog:17 - This is Warn Statement  28 Jun 2007 17:35:41 ERROR TestLog:18 - This is Error Statement  28 Jun 2007 17:35:41 FATAL TestLog:19 - This is Fatal Statement  28 Jun 2007 17:35:41 ERROR TestLog:26 - Arithmetic Error  java.lang.ArithmeticException: / by zero  at com.log4J.TestLog.main(TestLog.java:24)
  • 8. 03/17/16 www.SunilOS.com 8 Level Priorities  Level Priorities o debug< info< warn < error <fatal  Logging level can be defined in the log4j.properties. o log4j.rootLogger=debug, stdout  Log4J will log all the messages for defined level and its high priority level.  For example if defined level is debug then it will log messages for debug, info, warn and fatal.  If defined level is warn then it will log messages for warn , error and fatal levels.
  • 9. Configuration File log4j.properties XML can also be used Keep it in root class path folder It will configure oAppenders oMessage Layout oMessage Target 03/17/16 www.SunilOS.com 9
  • 10. Appender An Appender is an object that sends log messages to their final destination. It defines message targets. o Console o File o Network o FTP o Database o Etc. 03/17/16 www.SunilOS.com 10
  • 12. 03/17/16 www.SunilOS.com 12 Console Appender Log messages on Console Configure Standard Output Appender ### direct log messages to std out ### log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p %c{1}:%L - %m%n ### set log category - debug,info,warn,error,fatal log4j.rootLogger=debug,stdout
  • 14. 03/17/16 www.SunilOS.com 14 File Appender Log messages in a File ### direct messages to file hibernate.log ### log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File=c:/temp/corejava.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p %c{1}:%L - %m%n ### set log category - debug,info,warn,error,fatal log4j.rootLogger=debug,file, stdout Message will be sent to two appenders file and stdout
  • 15. Rolling File Appender It will roll (create) log files based on size or date or both depending on configuration. That means new log file will be created when 03/17/16 www.SunilOS.com 15 File size is full Date is changed
  • 16. 03/17/16 www.SunilOS.com 16 Other Appenders  SocketAppender – Dumps log output to a socket  SyslogAppender – Write to the syslog.  NTEventLogAppender – Write the logs to the NT Event Log system.  SocketAppender – Dumps log output to a socket  SMTPAppender – Sends Messages to email  JMSAppender – Sends messages using Java Messaging Service  Or create your own. Not that difficult.
  • 17. Message Pattern log4j.appender.file.layout.ConversionPattern =%d{dd MMM yyyy HH:mm:ss} %5p %c{1}: %L - %m%n Used to customize the layout of a log entry. The format is closely related to conversion pattern of the printf function in ‘c’ language. 03/17/16 www.SunilOS.com 17
  • 18. 03/17/16 www.SunilOS.com 18 PatternLayout Options  c - Used to output the category of the logging event.  C - Used to output the fully qualified class name of the caller issuing the logging request.  d - Used to output the date of the logging event. The date conversion specifier may be followed by a date format specifier enclosed between braces. For example, %d{HH:mm:ss,SSS} or %d{dd MMM yyyy HH:mm:ss,SSS}. If no date format specifier is given then ISO8601 format is assumed  F - Used to output the file name where the logging request was issued.  l - Used to output location information of the caller which generated the logging event. (C+M+L)  L - Used to output the line number from where the logging request was issued.
  • 19. 03/17/16 www.SunilOS.com 19 PatternLayout ( Contd.)  n - Outputs the platform dependent line separator character or characters.  M - Used to output the method name where the logging request was issued.  p - Used to output the priority of the logging event.  t - Used to output the name of the thread that generated the logging event.  x - Used to output the NDC (nested diagnostic context) associated with the thread that generated the logging event.
  • 20. Application Environments There are different application environment for different kind of users Developer develops application in development Environment Tester tests application in QA Environment End User accesses application from Production Environment ( Live Server ) 03/17/16 www.SunilOS.com 20
  • 21. 03/17/16 www.SunilOS.com 21 Application Environments Development Tomcat MySQL Test ( QA ) Tomcat MySQL Production Tomcat MySQL Developer Testers End User
  • 22. 03/17/16 www.SunilOS.com 22 Application Environments Development JBoss Oracle Test ( QA ) JBoss Oracle Production JBoss Oracle Developer Testers End User
  • 23. 03/17/16 www.SunilOS.com 23 Application Environments Development Tomcat Oracle Test ( QA ) Tomcat Production Tomcat DB Developer Testers End User
  • 24. 03/17/16 www.SunilOS.com 24 Environments Development JBoss Oracle Test ( QA ) JBoss Production JBoss Oracle Developer Testers End User
  • 25. App Env & Message Level There are different message levels for different application environments o Development Environment : debug o Test (QA) Environment : info o Production : warn 03/17/16 www.SunilOS.com 25
  • 27. Say YES to Log4J 03/17/16 www.SunilOS.com 27
  • 29. Disclaimer This is an educational presentation to enhance the skill of computer science students. This presentation is available for free to computer science students. Some internet images from different URLs are used in this presentation to simplify technical examples and correlate examples with the real world. We are grateful to owners of these URLs and pictures. www.SunilOS.com 2903/17/16