SlideShare a Scribd company logo
log4j.xml Example
-Gagandeep Singh
1. Output to Console
Redirect the logging to console.
log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-
5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
2. Output to File
Redirect the logging to a file..
log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="false" />
<param name="maxFileSize" value="10KB" />
<param name="maxBackupIndex" value="5" />
<!-- For Tomcat -->
<param name="file" value="${catalina.home}/logs/myStruts1App.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
3. Output to Console and File
Full example to output the logging to both console and file.
log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="false" />
<param name="maxFileSize" value="10MB" />
<param name="maxBackupIndex" value="10" />
<param name="file" value="${catalina.home}/logs/myStruts1App.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
<root>
<level value="ERROR" />
<appender-ref ref="file" />
</root> </log4j:configuration>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="console" />
<appender-ref ref="file" />
</root>
</log4j:configuration>

More Related Content

PPTX
4. copy2 in Laravel
PPTX
3. Copy1 in Laravel
PDF
How To Connect To Active Directory PowerShell
PPTX
6. Add numbers in Laravel
PPTX
2.hello popescu2 in Laravel
PPTX
1. Hello Popescu in Laravel
PDF
How To Connect to Active Directory User Validation
PPTX
9. Radio1 in Laravel
4. copy2 in Laravel
3. Copy1 in Laravel
How To Connect To Active Directory PowerShell
6. Add numbers in Laravel
2.hello popescu2 in Laravel
1. Hello Popescu in Laravel
How To Connect to Active Directory User Validation
9. Radio1 in Laravel

What's hot (20)

PDF
Alfresco study37 alfresco_ng2_components
PDF
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
PDF
Alfresco study presentation 38th customize How-To WebDAV
PDF
Windows PowerShell Basics – How To Create powershell for loop
PPTX
Windows power shell basics
PDF
Filling the flask
PPTX
DevOps and Chef
PDF
Python RESTful webservices with Python: Flask and Django solutions
PDF
Introduction to Flask Micro Framework
PPTX
Make BDD great again
PDF
Common mistakes functional java vjug
PDF
Common mistakes functional java | Oracle Code One 2018
PPT
Learn REST API with Python
PPTX
8. Move in Laravel
PDF
Getting Started-with-Laravel
PDF
Ten common mistakes made with Functional Java JBCNConf18
PPTX
RESTful Web Development with CakePHP
DOC
Awstats installation
TXT
Ip lab
PPTX
Designing CakePHP plugins for consuming APIs
Alfresco study37 alfresco_ng2_components
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Alfresco study presentation 38th customize How-To WebDAV
Windows PowerShell Basics – How To Create powershell for loop
Windows power shell basics
Filling the flask
DevOps and Chef
Python RESTful webservices with Python: Flask and Django solutions
Introduction to Flask Micro Framework
Make BDD great again
Common mistakes functional java vjug
Common mistakes functional java | Oracle Code One 2018
Learn REST API with Python
8. Move in Laravel
Getting Started-with-Laravel
Ten common mistakes made with Functional Java JBCNConf18
RESTful Web Development with CakePHP
Awstats installation
Ip lab
Designing CakePHP plugins for consuming APIs
Ad

Viewers also liked (8)

PPTX
Understanding JSP -Servlets
PPTX
Log4jprop example
PPT
PPTX
Introduction to webservices
PPTX
Jsf login logout project
PPTX
PPT
Web Sphere Administration guide – Packaging and Deploying Jee Applications
PPTX
Application server vs Web Server
Understanding JSP -Servlets
Log4jprop example
Introduction to webservices
Jsf login logout project
Web Sphere Administration guide – Packaging and Deploying Jee Applications
Application server vs Web Server
Ad

Similar to Log4jxml ex (9)

DOC
Log4j
PPT
Logging with Logback in Scala
ODP
Logging with Logback in Scala
PDF
Java Logging discussion Log4j,Slf4j
PPTX
Log4j is a reliable, fast and flexible
PPT
PPTX
SLF4J Explained........
PPTX
Picking log4j2 for mule
Log4j
Logging with Logback in Scala
Logging with Logback in Scala
Java Logging discussion Log4j,Slf4j
Log4j is a reliable, fast and flexible
SLF4J Explained........
Picking log4j2 for mule

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
Teaching material agriculture food technology
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Empathic Computing: Creating Shared Understanding
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Teaching material agriculture food technology
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
MYSQL Presentation for SQL database connectivity
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
Machine learning based COVID-19 study performance prediction
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
Empathic Computing: Creating Shared Understanding

Log4jxml ex

  • 2. 1. Output to Console Redirect the logging to console. log4j.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %- 5p %c{1}:%L - %m%n" /> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="console" /> </root> </log4j:configuration>
  • 3. 2. Output to File Redirect the logging to a file.. log4j.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'> <appender name="file" class="org.apache.log4j.RollingFileAppender"> <param name="append" value="false" /> <param name="maxFileSize" value="10KB" /> <param name="maxBackupIndex" value="5" /> <!-- For Tomcat --> <param name="file" value="${catalina.home}/logs/myStruts1App.log" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" /> </layout> </appender>
  • 4. 3. Output to Console and File Full example to output the logging to both console and file. log4j.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" /> </layout> </appender> <appender name="file" class="org.apache.log4j.RollingFileAppender"> <param name="append" value="false" /> <param name="maxFileSize" value="10MB" /> <param name="maxBackupIndex" value="10" /> <param name="file" value="${catalina.home}/logs/myStruts1App.log" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" /> </layout>
  • 5. <root> <level value="ERROR" /> <appender-ref ref="file" /> </root> </log4j:configuration> </appender> <root> <level value="DEBUG" /> <appender-ref ref="console" /> <appender-ref ref="file" /> </root> </log4j:configuration>