SlideShare una empresa de Scribd logo
1 de 27
Slide 1
Slide 2




Agenda
 Current Log Implementation Problems!!!
 Log4j Overview
 Log4j And Web Applications
 Log4j And Class Loaders In Application Servers
 Log4j And The “Logging Separation” Problem
 Log4j Implementation In Web Applications
 Log4j And The “Log Rotation” Problem
 Dated Logger Implementation In Web Applications
 For You….
Slide 3




Current Log Implementation
Problems!!!
Slide 4
Slide 5
Slide 6
Slide 7




Log4j Overview
Slide 8




Log4j normally needs to be configured only once. Some new users try to
configure log4j in each and every class. This is very inefficient and just plain
wrong.




A logger is said to be an ancestor of another logger if its name followed by a
dot is a prefix of the descendant logger name.
The root logger resides at the top of the logger hierarchy.
e.g. x.y is parent of x.y.z
Slide 9




Log4j And Web Applications
Slide 10




In practice placing log4j-VERSION.jar in the WEB-INF/lib directory of your
web-application will cause log4j classes to be loaded/unloaded whenever your
web application is loaded/unloaded. Moreover, each copy of the log4j classes
will be treated as a separate unrelated copy by the JVM.

Under Tomcat 3.x and 4.x, you should place the log4j.xml or
log4j.properties under the WEB-INF/classes directory of your web-
applications. Log4j will find the properties file and initialize itself.


   WEB-INF
      Lib
      • log4j-version.jar



      Classes
      • log4j.xml/log4j.properties
Slide 11




Log4j And Class Loaders In
Application Servers
Slide 12




The Java class loader delegation model gives precedence to parent class
loaders. This means that if log4j.jar is available on the CLASSPATH, or
under JAVA_HOME/jar/lib/ext or to any class loader which is a parent of the
webapplication's class loader, then that copy of log4j will be loaded into
memory and shared by all web-applications.
Slide 13




Log4j And The “Logging Separation”
Problem
Slide 14




In a separated logging environment, each web-application can configure log4j
in different ways such that the configuration of one web-application cannot
interfere with the logging configuration of another web application.

Since time immemorial users have struggled to control the logging
configuration of multiple web-applications deployed on the same Servlet
Container (e.g. Tomcat).
Slide 15




Log4j Implementation In Web
Applications
Slide 16




Assuming each web-application is loaded by a distinct class loader, then
placing a copy of log4j.jar under WEB-INF/lib/ directory of each web-
application will automatically result in distinct log4j-logging universes. Simply
put, each webapplication will load its own distinct copy of log4j classes into
memory. All such copies are invisible and inaccessible to each other.
Slide 17




Log4j allows different applications live in their own parallel universe by using
a different LoggerRepository for each application. Given that each hierarchy
(i.e. logger repository) manages its own separate logger tree, logging
separation is a direct consequence of this approach.

The Java Servlet API mandates a unique ServletContext for each web
application. Thus, a web-application can set an attribute for a Servlet context
which can be shared by all Servlet and jsp pages of a web-application but
remain invisible to other web-applications.
In particular, an initialization Servlet can create, set and configure an
independent logger hierarchy in the Servlet context. Subsequently, other
Servlet can obtain the hierarchy stored in the Servlet context in order to retrieve
logger instances.
These logger instances will be attached to the particular hierarchy specific to
the web-application.
Slide 18




This solution relies on the Servlet Container to keep track of the
execution context and provide a different logging environment for each
context.

Each web application has its own class loader and Tomcat sets the Thread
Context Classloader, or TCL, to be the class loader of the currently
executing web application.

Servlet Container provides a separate hierarchy instance for each
web-application. Each logger object that log4j creates is attached to a
hierarchy. The Hierarchy class implements the LoggerRepository interface by
arranging logger objects in a tree according to their name.
Slide 19




Log4j And The “Log Rotation”
Problem
Slide 20




The log file rotation on Application servers fails with following error


log4j: ERROR Failed to rename [<file
name>.log] to [<file name>.log.2010-03-
23].
Slide 21




Log4j And “Multiple Line Printing”
Problem
Slide 22




Logger         Added        Additivity
                                             Output Targets       Comment
Name           Appenders    Flag
                                                                  The root logger does
root           A1           not applicable   A1
                                                                  not have a parent.
                                                                  Appenders in root
x              A-x1, A-x2   true             A1, A-x1, A-x2       are added to
                                                                  appenders in "x".
                                                                  Appenders of "x" and
x.y            none         true             A1, A-x1, A-x2
                                                                  root.
                                             A1, A-x1, A-x2, A-   Appenders in "x.y.z",
x.y.z          A-xyz1       true
                                             xyz1                 "x" and root.
                                                                  No appender
                                                                  accumulation as the
security       A-sec        false            A-sec
                                                                  additivity flag is set
                                                                  to false.
                                                                  Only appenders of
                                                                  "security" as the
security.ACL   none         true             A-sec                additivity flag in
                                                                  "security" is set to
                                                                  false.
Slide 23




Dated Logger Implementation In
Web Applications
Slide 24




DatedFileAppender is an "appender" object designed for use with the
Apache Log4j logging system.

It provides an Apache Tomcat style FileLogger implementation that differs
from the file loggers provided with Log4j.

While the DatedFileAppender was written with Apache Tomcat in mind, it does
not depend on Tomcat and may be used in any other environment.

How to use it?

•Copy the datedFileAppender-1.0.2.jar to the same directory as your other
application jar files and add the jar file name to your CLASSPATH.

•Modify your log4j.properties file to use the DatedFileAppender class (see
below for configuration options).
Slide 25




For You….
Slide 26




Still Have Any
Question? 
Slide 27




Thank You !!!

Más contenido relacionado

Similar a Logger implementation

Profusion of RIAs
Profusion of RIAsProfusion of RIAs
Profusion of RIAsSho Ito
 
Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Frameworkguestd8c458
 
Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]Palak Sanghani
 
Making Applications Work Together In Eclipse
Making Applications Work Together In EclipseMaking Applications Work Together In Eclipse
Making Applications Work Together In EclipseKaniska Mandal
 
Decorating code (Research Paper)
Decorating code (Research Paper)Decorating code (Research Paper)
Decorating code (Research Paper)Jenna Pederson
 
R Programming: Introduction To R Packages
R Programming: Introduction To R PackagesR Programming: Introduction To R Packages
R Programming: Introduction To R PackagesRsquared Academy
 
Smooth transition to Eclipse in practice
Smooth transition to Eclipse in practiceSmooth transition to Eclipse in practice
Smooth transition to Eclipse in practiceguest301ea
 
Gemini WEB and Virgo
Gemini WEB and VirgoGemini WEB and Virgo
Gemini WEB and VirgoHristo Iliev
 
Jsp And Servlets
Jsp And ServletsJsp And Servlets
Jsp And ServletsAdil Jafri
 
Rein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4jRein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4jRazorsight
 
JDD2015: ClassIndex - szybka alternatywa dla skanowania klas - Sławek Piotrowski
JDD2015: ClassIndex - szybka alternatywa dla skanowania klas - Sławek PiotrowskiJDD2015: ClassIndex - szybka alternatywa dla skanowania klas - Sławek Piotrowski
JDD2015: ClassIndex - szybka alternatywa dla skanowania klas - Sławek PiotrowskiPROIDEA
 
Whoops! where did my architecture go?
Whoops! where did my architecture go?Whoops! where did my architecture go?
Whoops! where did my architecture go?Oliver Gierke
 
Designing JEE Application Structure
Designing JEE Application StructureDesigning JEE Application Structure
Designing JEE Application Structureodedns
 
Logging with Logback in Scala
Logging with Logback in ScalaLogging with Logback in Scala
Logging with Logback in ScalaKnoldus Inc.
 
Java%20 collections%20framework
Java%20 collections%20frameworkJava%20 collections%20framework
Java%20 collections%20frameworkIlakkian
 

Similar a Logger implementation (20)

Logback
LogbackLogback
Logback
 
Profusion of RIAs
Profusion of RIAsProfusion of RIAs
Profusion of RIAs
 
Java Collections Framework
Java  Collections  FrameworkJava  Collections  Framework
Java Collections Framework
 
Ajaxworld West 08
Ajaxworld West 08Ajaxworld West 08
Ajaxworld West 08
 
Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]
 
Making Applications Work Together In Eclipse
Making Applications Work Together In EclipseMaking Applications Work Together In Eclipse
Making Applications Work Together In Eclipse
 
Decorating code (Research Paper)
Decorating code (Research Paper)Decorating code (Research Paper)
Decorating code (Research Paper)
 
R Programming: Introduction To R Packages
R Programming: Introduction To R PackagesR Programming: Introduction To R Packages
R Programming: Introduction To R Packages
 
Smooth transition to Eclipse in practice
Smooth transition to Eclipse in practiceSmooth transition to Eclipse in practice
Smooth transition to Eclipse in practice
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
 
Gemini WEB and Virgo
Gemini WEB and VirgoGemini WEB and Virgo
Gemini WEB and Virgo
 
Jsp And Servlets
Jsp And ServletsJsp And Servlets
Jsp And Servlets
 
Rein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4jRein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4j
 
Jira Rev002
Jira Rev002Jira Rev002
Jira Rev002
 
JDD2015: ClassIndex - szybka alternatywa dla skanowania klas - Sławek Piotrowski
JDD2015: ClassIndex - szybka alternatywa dla skanowania klas - Sławek PiotrowskiJDD2015: ClassIndex - szybka alternatywa dla skanowania klas - Sławek Piotrowski
JDD2015: ClassIndex - szybka alternatywa dla skanowania klas - Sławek Piotrowski
 
Whoops! where did my architecture go?
Whoops! where did my architecture go?Whoops! where did my architecture go?
Whoops! where did my architecture go?
 
Designing JEE Application Structure
Designing JEE Application StructureDesigning JEE Application Structure
Designing JEE Application Structure
 
Logging with Logback in Scala
Logging with Logback in ScalaLogging with Logback in Scala
Logging with Logback in Scala
 
Java%20 collections%20framework
Java%20 collections%20frameworkJava%20 collections%20framework
Java%20 collections%20framework
 
Jfxpub binding
Jfxpub bindingJfxpub binding
Jfxpub binding
 

Más de Abhishek Chikane

Más de Abhishek Chikane (10)

MediaWiki for ALM
MediaWiki for ALMMediaWiki for ALM
MediaWiki for ALM
 
Tracking universal immunization
Tracking universal immunizationTracking universal immunization
Tracking universal immunization
 
Web Application Architecture
Web Application ArchitectureWeb Application Architecture
Web Application Architecture
 
Authentication Server
Authentication ServerAuthentication Server
Authentication Server
 
Creating Hardware Inventory
Creating Hardware InventoryCreating Hardware Inventory
Creating Hardware Inventory
 
Porting Java App To Cloud
Porting Java App To CloudPorting Java App To Cloud
Porting Java App To Cloud
 
Cloud Computing And Salesforce
Cloud Computing And SalesforceCloud Computing And Salesforce
Cloud Computing And Salesforce
 
Changing Trends In Cloud Computing
Changing Trends In Cloud ComputingChanging Trends In Cloud Computing
Changing Trends In Cloud Computing
 
Live broadcasting
Live broadcastingLive broadcasting
Live broadcasting
 
CAPTCHA
CAPTCHACAPTCHA
CAPTCHA
 

Último

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Último (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Logger implementation

  • 2. Slide 2 Agenda  Current Log Implementation Problems!!!  Log4j Overview  Log4j And Web Applications  Log4j And Class Loaders In Application Servers  Log4j And The “Logging Separation” Problem  Log4j Implementation In Web Applications  Log4j And The “Log Rotation” Problem  Dated Logger Implementation In Web Applications  For You….
  • 3. Slide 3 Current Log Implementation Problems!!!
  • 8. Slide 8 Log4j normally needs to be configured only once. Some new users try to configure log4j in each and every class. This is very inefficient and just plain wrong. A logger is said to be an ancestor of another logger if its name followed by a dot is a prefix of the descendant logger name. The root logger resides at the top of the logger hierarchy. e.g. x.y is parent of x.y.z
  • 9. Slide 9 Log4j And Web Applications
  • 10. Slide 10 In practice placing log4j-VERSION.jar in the WEB-INF/lib directory of your web-application will cause log4j classes to be loaded/unloaded whenever your web application is loaded/unloaded. Moreover, each copy of the log4j classes will be treated as a separate unrelated copy by the JVM. Under Tomcat 3.x and 4.x, you should place the log4j.xml or log4j.properties under the WEB-INF/classes directory of your web- applications. Log4j will find the properties file and initialize itself. WEB-INF Lib • log4j-version.jar Classes • log4j.xml/log4j.properties
  • 11. Slide 11 Log4j And Class Loaders In Application Servers
  • 12. Slide 12 The Java class loader delegation model gives precedence to parent class loaders. This means that if log4j.jar is available on the CLASSPATH, or under JAVA_HOME/jar/lib/ext or to any class loader which is a parent of the webapplication's class loader, then that copy of log4j will be loaded into memory and shared by all web-applications.
  • 13. Slide 13 Log4j And The “Logging Separation” Problem
  • 14. Slide 14 In a separated logging environment, each web-application can configure log4j in different ways such that the configuration of one web-application cannot interfere with the logging configuration of another web application. Since time immemorial users have struggled to control the logging configuration of multiple web-applications deployed on the same Servlet Container (e.g. Tomcat).
  • 15. Slide 15 Log4j Implementation In Web Applications
  • 16. Slide 16 Assuming each web-application is loaded by a distinct class loader, then placing a copy of log4j.jar under WEB-INF/lib/ directory of each web- application will automatically result in distinct log4j-logging universes. Simply put, each webapplication will load its own distinct copy of log4j classes into memory. All such copies are invisible and inaccessible to each other.
  • 17. Slide 17 Log4j allows different applications live in their own parallel universe by using a different LoggerRepository for each application. Given that each hierarchy (i.e. logger repository) manages its own separate logger tree, logging separation is a direct consequence of this approach. The Java Servlet API mandates a unique ServletContext for each web application. Thus, a web-application can set an attribute for a Servlet context which can be shared by all Servlet and jsp pages of a web-application but remain invisible to other web-applications. In particular, an initialization Servlet can create, set and configure an independent logger hierarchy in the Servlet context. Subsequently, other Servlet can obtain the hierarchy stored in the Servlet context in order to retrieve logger instances. These logger instances will be attached to the particular hierarchy specific to the web-application.
  • 18. Slide 18 This solution relies on the Servlet Container to keep track of the execution context and provide a different logging environment for each context. Each web application has its own class loader and Tomcat sets the Thread Context Classloader, or TCL, to be the class loader of the currently executing web application. Servlet Container provides a separate hierarchy instance for each web-application. Each logger object that log4j creates is attached to a hierarchy. The Hierarchy class implements the LoggerRepository interface by arranging logger objects in a tree according to their name.
  • 19. Slide 19 Log4j And The “Log Rotation” Problem
  • 20. Slide 20 The log file rotation on Application servers fails with following error log4j: ERROR Failed to rename [<file name>.log] to [<file name>.log.2010-03- 23].
  • 21. Slide 21 Log4j And “Multiple Line Printing” Problem
  • 22. Slide 22 Logger Added Additivity Output Targets Comment Name Appenders Flag The root logger does root A1 not applicable A1 not have a parent. Appenders in root x A-x1, A-x2 true A1, A-x1, A-x2 are added to appenders in "x". Appenders of "x" and x.y none true A1, A-x1, A-x2 root. A1, A-x1, A-x2, A- Appenders in "x.y.z", x.y.z A-xyz1 true xyz1 "x" and root. No appender accumulation as the security A-sec false A-sec additivity flag is set to false. Only appenders of "security" as the security.ACL none true A-sec additivity flag in "security" is set to false.
  • 23. Slide 23 Dated Logger Implementation In Web Applications
  • 24. Slide 24 DatedFileAppender is an "appender" object designed for use with the Apache Log4j logging system. It provides an Apache Tomcat style FileLogger implementation that differs from the file loggers provided with Log4j. While the DatedFileAppender was written with Apache Tomcat in mind, it does not depend on Tomcat and may be used in any other environment. How to use it? •Copy the datedFileAppender-1.0.2.jar to the same directory as your other application jar files and add the jar file name to your CLASSPATH. •Modify your log4j.properties file to use the DatedFileAppender class (see below for configuration options).
  • 26. Slide 26 Still Have Any Question? 