SlideShare una empresa de Scribd logo
1 de 10
The Log4E logging plug-in
-Gagandeep Singh
What is logging good for?
• Tracing program execution during development
• Debugging
• Providing an audit trail for a program
• Recording soft-errors (lost connections, etc.) for
monitoring performance and troubleshooting
• A logging framework lets you use different logging
levels
– You can turn different types of messages on and off
– You can send different types of messages to different
destinations
Adding logging code
• Replaces System.out.println() calls throughout
• Don’t need to be removed
• Like adding System.out.println() calls, it’s
somewhat tedious to add logging code
• Utility of logging code is improved if it’s
consistent—logs can be searched with scripts,
for example
The Log4E plug-in
• Provides wizards that automate the addition
of logging code
• Add import and declaration for logger
• Insert logging at start and end of methods
• Insert logging of variables and method
parameters
What Log4E doesn’t do
• Log4E does not provide a logging framework
• Doesn’t configure your framework
• Doesn’t make a fresh pot of coffee
Choosing a logging framework
• Log4E supports three logging frameworks:
– Log4J
– Java 1.4 Logging
– Jakarta Commons Logging
• Log4J is the original logging framework that Java
1.4 logging is modeled after
• Jakarta Commons Logging is actually a wrapper for
logging frameworks
• We’ll use Log4J in this example because it’s
mature, well-documented and supported, and
easier to configure
Installing Log4J
• Download a zip or compressed tarfile from:
Apache.org website
• Uncompress to a local directory
• In your Eclipse project’s properties
– Locate Java Build Path
– On Libraries page, click on Add External Jars
– Browse for your Log4J directory, and locate the log4J Jar
file in the /dist/lib directory
– Press Open, followed by OK
Create a Log4J configuration file
• The easiest way to configure Log4J is to add a
log4j.properties file to your source directory.
• There are many options available which we won’t
cover here, but essentially you need to define:
– A logger
– An appender
– A pattern layout
• The following example uses the default root logger,
appends to the console and prints the date, time,
message priority, thread and message
A sample log4j.properties file
# Logger
log4j.rootLogger=DEBUG, ConApp
# Appender
log4j.appender.ConApp=org.apache.log4j.ConsoleAppender
# PatternLayout
log4j.appender.ConApp.layout=org.apache.log4j.PatternLayout
log4j.appender.ConApp.layout.ConversionPattern=%d [%t] %-5p %c
- %m%n
Demo
• Create a simple Java application
• Ensure log4j is on class path
• Use Log4E to add several types of logging
messages
• Run program

Más contenido relacionado

La actualidad más candente

Appium & Robot Framework
Appium & Robot FrameworkAppium & Robot Framework
Appium & Robot FrameworkFurkan Ertürk
 
Database table schema explained of Opencart
Database table schema explained of OpencartDatabase table schema explained of Opencart
Database table schema explained of OpencartSelf
 
Robot framework Gowthami Goli
Robot framework Gowthami GoliRobot framework Gowthami Goli
Robot framework Gowthami GoliGowthami Buddi
 
My Journey with Laravel by Shavkat, Ecompile.io
My Journey with Laravel by Shavkat, Ecompile.ioMy Journey with Laravel by Shavkat, Ecompile.io
My Journey with Laravel by Shavkat, Ecompile.ioappleseeds-my
 
Robot Framework Dos And Don'ts
Robot Framework Dos And Don'tsRobot Framework Dos And Don'ts
Robot Framework Dos And Don'tsPekka Klärck
 
Introduction to Robot Framework (external)
Introduction to Robot Framework (external)Introduction to Robot Framework (external)
Introduction to Robot Framework (external)Zhe Li
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework OpenDaylight
 
Robot Framework :: Demo login application
Robot Framework :: Demo login applicationRobot Framework :: Demo login application
Robot Framework :: Demo login applicationSomkiat Puisungnoen
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework IntroductionPekka Klärck
 
Practical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProPractical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProSam Bowne
 
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...Xebia Nederland BV
 

La actualidad más candente (19)

Appium & Robot Framework
Appium & Robot FrameworkAppium & Robot Framework
Appium & Robot Framework
 
Robot framework
Robot frameworkRobot framework
Robot framework
 
Robot framework
Robot frameworkRobot framework
Robot framework
 
Database table schema explained of Opencart
Database table schema explained of OpencartDatabase table schema explained of Opencart
Database table schema explained of Opencart
 
Robot framework Gowthami Goli
Robot framework Gowthami GoliRobot framework Gowthami Goli
Robot framework Gowthami Goli
 
Robot framework and selenium2 library
Robot framework and selenium2 libraryRobot framework and selenium2 library
Robot framework and selenium2 library
 
My Journey with Laravel by Shavkat, Ecompile.io
My Journey with Laravel by Shavkat, Ecompile.ioMy Journey with Laravel by Shavkat, Ecompile.io
My Journey with Laravel by Shavkat, Ecompile.io
 
Robot Framework Dos And Don'ts
Robot Framework Dos And Don'tsRobot Framework Dos And Don'ts
Robot Framework Dos And Don'ts
 
Introduction to Robot Framework (external)
Introduction to Robot Framework (external)Introduction to Robot Framework (external)
Introduction to Robot Framework (external)
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
 
Robot Framework :: Demo login application
Robot Framework :: Demo login applicationRobot Framework :: Demo login application
Robot Framework :: Demo login application
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introduction
 
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan PeshovJavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
 
Introduction to Robot Framework
Introduction to Robot FrameworkIntroduction to Robot Framework
Introduction to Robot Framework
 
Introduction to robot framework
Introduction to robot frameworkIntroduction to robot framework
Introduction to robot framework
 
Lesson1 intro
Lesson1 introLesson1 intro
Lesson1 intro
 
Practical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProPractical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA Pro
 
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
 

Similar a Log4e

Log4j with selenium tutorial: How to Setup log4j logging in selenium automati...
Log4j with selenium tutorial: How to Setup log4j logging in selenium automati...Log4j with selenium tutorial: How to Setup log4j logging in selenium automati...
Log4j with selenium tutorial: How to Setup log4j logging in selenium automati...Chirag Thumar
 
Functional Application Logging : Code Examples Using Spring Boot and Logback
Functional Application Logging : Code Examples Using Spring Boot and LogbackFunctional Application Logging : Code Examples Using Spring Boot and Logback
Functional Application Logging : Code Examples Using Spring Boot and LogbackMohammad Sabir Khan
 
Logging Application Behavior to MongoDB
Logging Application Behavior to MongoDBLogging Application Behavior to MongoDB
Logging Application Behavior to MongoDBRobert Stewart
 
Log4j is a reliable, fast and flexible
Log4j is a reliable, fast and flexibleLog4j is a reliable, fast and flexible
Log4j is a reliable, fast and flexibleRamakrishna kapa
 
Conditional Logging Considered Harmful - Sean Reilly
Conditional Logging Considered Harmful - Sean ReillyConditional Logging Considered Harmful - Sean Reilly
Conditional Logging Considered Harmful - Sean ReillyJAXLondon2014
 
Mule debugging logging_configuration_in_mule
Mule debugging logging_configuration_in_muleMule debugging logging_configuration_in_mule
Mule debugging logging_configuration_in_mulekunal vishe
 
Icon UK 2018 - Spring forward: an introduction to Spring boot and Thymeleaf f...
Icon UK 2018 - Spring forward: an introduction to Spring boot and Thymeleaf f...Icon UK 2018 - Spring forward: an introduction to Spring boot and Thymeleaf f...
Icon UK 2018 - Spring forward: an introduction to Spring boot and Thymeleaf f...Frank van der Linden
 
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)mfrancis
 
The new OSGi LogService 1.4 and integrating with SLF4J
The new OSGi LogService 1.4 and integrating with SLF4JThe new OSGi LogService 1.4 and integrating with SLF4J
The new OSGi LogService 1.4 and integrating with SLF4Jbjhargrave
 
Deployment Strategies: Managing Code, Content, and Configurations
Deployment Strategies: Managing Code, Content, and ConfigurationsDeployment Strategies: Managing Code, Content, and Configurations
Deployment Strategies: Managing Code, Content, and Configurationsnyccamp
 
appengine ja night #25 Google App Engine for PHP (English)
appengine ja night #25 Google App Engine for PHP (English)appengine ja night #25 Google App Engine for PHP (English)
appengine ja night #25 Google App Engine for PHP (English)Ryo Yamasaki
 
Profiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsProfiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsAchievers Tech
 
From XPages Hero to OSGi Guru: Taking the Scary out of Building Extension Lib...
From XPages Hero to OSGi Guru: Taking the Scary out of Building Extension Lib...From XPages Hero to OSGi Guru: Taking the Scary out of Building Extension Lib...
From XPages Hero to OSGi Guru: Taking the Scary out of Building Extension Lib...Paul Withers
 

Similar a Log4e (20)

Log4e
Log4eLog4e
Log4e
 
Java Logging
Java LoggingJava Logging
Java Logging
 
Log4j with selenium tutorial: How to Setup log4j logging in selenium automati...
Log4j with selenium tutorial: How to Setup log4j logging in selenium automati...Log4j with selenium tutorial: How to Setup log4j logging in selenium automati...
Log4j with selenium tutorial: How to Setup log4j logging in selenium automati...
 
Log4j slideshare
Log4j slideshareLog4j slideshare
Log4j slideshare
 
Logging
LoggingLogging
Logging
 
Functional Application Logging : Code Examples Using Spring Boot and Logback
Functional Application Logging : Code Examples Using Spring Boot and LogbackFunctional Application Logging : Code Examples Using Spring Boot and Logback
Functional Application Logging : Code Examples Using Spring Boot and Logback
 
Logging Application Behavior to MongoDB
Logging Application Behavior to MongoDBLogging Application Behavior to MongoDB
Logging Application Behavior to MongoDB
 
Logback
LogbackLogback
Logback
 
Log4j is a reliable, fast and flexible
Log4j is a reliable, fast and flexibleLog4j is a reliable, fast and flexible
Log4j is a reliable, fast and flexible
 
Conditional Logging Considered Harmful - Sean Reilly
Conditional Logging Considered Harmful - Sean ReillyConditional Logging Considered Harmful - Sean Reilly
Conditional Logging Considered Harmful - Sean Reilly
 
Mule debugging logging_configuration_in_mule
Mule debugging logging_configuration_in_muleMule debugging logging_configuration_in_mule
Mule debugging logging_configuration_in_mule
 
AtoM feature development
AtoM feature developmentAtoM feature development
AtoM feature development
 
Icon UK 2018 - Spring forward: an introduction to Spring boot and Thymeleaf f...
Icon UK 2018 - Spring forward: an introduction to Spring boot and Thymeleaf f...Icon UK 2018 - Spring forward: an introduction to Spring boot and Thymeleaf f...
Icon UK 2018 - Spring forward: an introduction to Spring boot and Thymeleaf f...
 
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
 
The new OSGi LogService 1.4 and integrating with SLF4J
The new OSGi LogService 1.4 and integrating with SLF4JThe new OSGi LogService 1.4 and integrating with SLF4J
The new OSGi LogService 1.4 and integrating with SLF4J
 
Deployment Strategies: Managing Code, Content, and Configurations
Deployment Strategies: Managing Code, Content, and ConfigurationsDeployment Strategies: Managing Code, Content, and Configurations
Deployment Strategies: Managing Code, Content, and Configurations
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
 
appengine ja night #25 Google App Engine for PHP (English)
appengine ja night #25 Google App Engine for PHP (English)appengine ja night #25 Google App Engine for PHP (English)
appengine ja night #25 Google App Engine for PHP (English)
 
Profiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty DetailsProfiling and Tuning a Web Application - The Dirty Details
Profiling and Tuning a Web Application - The Dirty Details
 
From XPages Hero to OSGi Guru: Taking the Scary out of Building Extension Lib...
From XPages Hero to OSGi Guru: Taking the Scary out of Building Extension Lib...From XPages Hero to OSGi Guru: Taking the Scary out of Building Extension Lib...
From XPages Hero to OSGi Guru: Taking the Scary out of Building Extension Lib...
 

Más de Gagandeep Singh

Jsf login logout project
Jsf login logout projectJsf login logout project
Jsf login logout projectGagandeep Singh
 
Introduction to webservices
Introduction to webservicesIntroduction to webservices
Introduction to webservicesGagandeep Singh
 
Web Sphere Administration guide – Packaging and Deploying Jee Applications
Web Sphere Administration guide – Packaging and Deploying Jee ApplicationsWeb Sphere Administration guide – Packaging and Deploying Jee Applications
Web Sphere Administration guide – Packaging and Deploying Jee ApplicationsGagandeep Singh
 
Understanding JSP -Servlets
Understanding JSP -ServletsUnderstanding JSP -Servlets
Understanding JSP -ServletsGagandeep Singh
 
Application server vs Web Server
Application server vs Web ServerApplication server vs Web Server
Application server vs Web ServerGagandeep Singh
 

Más de Gagandeep Singh (8)

Jsf login logout project
Jsf login logout projectJsf login logout project
Jsf login logout project
 
Introduction to webservices
Introduction to webservicesIntroduction to webservices
Introduction to webservices
 
Autosys
AutosysAutosys
Autosys
 
Log4jxml ex
Log4jxml exLog4jxml ex
Log4jxml ex
 
Log4jprop example
Log4jprop exampleLog4jprop example
Log4jprop example
 
Web Sphere Administration guide – Packaging and Deploying Jee Applications
Web Sphere Administration guide – Packaging and Deploying Jee ApplicationsWeb Sphere Administration guide – Packaging and Deploying Jee Applications
Web Sphere Administration guide – Packaging and Deploying Jee Applications
 
Understanding JSP -Servlets
Understanding JSP -ServletsUnderstanding JSP -Servlets
Understanding JSP -Servlets
 
Application server vs Web Server
Application server vs Web ServerApplication server vs Web Server
Application server vs Web Server
 

Último

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Último (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

Log4e

  • 1. The Log4E logging plug-in -Gagandeep Singh
  • 2. What is logging good for? • Tracing program execution during development • Debugging • Providing an audit trail for a program • Recording soft-errors (lost connections, etc.) for monitoring performance and troubleshooting • A logging framework lets you use different logging levels – You can turn different types of messages on and off – You can send different types of messages to different destinations
  • 3. Adding logging code • Replaces System.out.println() calls throughout • Don’t need to be removed • Like adding System.out.println() calls, it’s somewhat tedious to add logging code • Utility of logging code is improved if it’s consistent—logs can be searched with scripts, for example
  • 4. The Log4E plug-in • Provides wizards that automate the addition of logging code • Add import and declaration for logger • Insert logging at start and end of methods • Insert logging of variables and method parameters
  • 5. What Log4E doesn’t do • Log4E does not provide a logging framework • Doesn’t configure your framework • Doesn’t make a fresh pot of coffee
  • 6. Choosing a logging framework • Log4E supports three logging frameworks: – Log4J – Java 1.4 Logging – Jakarta Commons Logging • Log4J is the original logging framework that Java 1.4 logging is modeled after • Jakarta Commons Logging is actually a wrapper for logging frameworks • We’ll use Log4J in this example because it’s mature, well-documented and supported, and easier to configure
  • 7. Installing Log4J • Download a zip or compressed tarfile from: Apache.org website • Uncompress to a local directory • In your Eclipse project’s properties – Locate Java Build Path – On Libraries page, click on Add External Jars – Browse for your Log4J directory, and locate the log4J Jar file in the /dist/lib directory – Press Open, followed by OK
  • 8. Create a Log4J configuration file • The easiest way to configure Log4J is to add a log4j.properties file to your source directory. • There are many options available which we won’t cover here, but essentially you need to define: – A logger – An appender – A pattern layout • The following example uses the default root logger, appends to the console and prints the date, time, message priority, thread and message
  • 9. A sample log4j.properties file # Logger log4j.rootLogger=DEBUG, ConApp # Appender log4j.appender.ConApp=org.apache.log4j.ConsoleAppender # PatternLayout log4j.appender.ConApp.layout=org.apache.log4j.PatternLayout log4j.appender.ConApp.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
  • 10. Demo • Create a simple Java application • Ensure log4j is on class path • Use Log4E to add several types of logging messages • Run program

Notas del editor

  1. When programming, it’s common to put System.out.println() statements in a program to follow its execution. These are usually removed at before releasing the program to the user community, since this would fill the screen with stuff that is meaningless to them. It’s also common to add extra System.out.println() statements temporarily when debugging—to dump out state information such as variable values, for example—that might provide clues to what is going on. Some types of programs require that certain events be logged in order to provide an audit trail. Unlike previous examples, this type of information is usually written to a file. Finally, it is usually desirable to log errors that occur during the course of execution of a program.
  2. Jakarta Commons Logging provides a façade so you can code to a common API and switch between logging frameworks easily—in other words, you don’t have to code for either Java Logging or Log4J. That makes a lot of sense, but it’s a complication we’ll avoid here, since ultimately we have to choose between the two frameworks either way.
  3. Log4J configuration will be covered in little more detail later, when we explore developing an Eclipse plug-in for editing log4j configuration files. Briefly, though: Logger—you need an instance of logger to send messages. You get a root, anonymous logger automatically, but normally, you’ll want to obtain a named, child instance by calling the the root logger’s getLogger(String name) method. Appender—the appender or appenders (which are specified in the config file) directs the message to the appropriate destination. Examples are ConsoleAppender, FileAppender, SMTPAppender, which send messages, respectively, to the console, a file and by email. You can define multiple appenders, with messages sorted by priority. For example, everything goes to the console, warnings and fatal errors go to a file, and fatal errors send an email message to the system administrator. Layouts—These define the format of the message, They use conversion specifiers which are similar to the format specifier used for C printf(). Some examples are shown in the log4j config file that follows.
  4. Pattern layouts are similar to C printf format patterns. The following conversion specifiers are used here: %d – Date and time %t – Thread name %-5p – priority of message (p) displayed left-justified (-) in a 5 character-wide field (5) %c – Name of logger (loggers were previously called categories, hence the abbrev.) %m – Message sent by logger %n – new line character