SlideShare a Scribd company logo
(Conditional) Logging 
Considered Harmful 
JAX London 2014
About Me 
Sean Reilly 
@seanjreilly
Logging Is Not Harmful 
In fact, it’s often useful. 
Conditional logging is harmful.
What I Mean By 
“Conditional” 
• Many loggers, organised by class name 
• Many log levels: 
• SEVERE, ERROR, WARN, INFO, DEBUG, 
TRACE 
• SEVERE, WARNING, INFO, CONFIG, FINE, 
FINER, FINEST 
• ERROR, WARN, INFO, DEBUG, TRACE 
• Message only logged if log level is active for a logger
Conditional Logging 
Frameworks 
• log4j 
• java.util.logging 
• Logback 
• slf4j 
• commons logging
Why Developers Log This 
Way 
• “We can log everything in 
development and INFO in production” 
• “When something unexpected 
happens in production, we can 
increase the log level dynamically and 
get the extra information we need” 
• “It helps us debug while developing”
The Real Reason 
What other options are there?
Why Did We Decide To 
Use Something Else?
The Real Reason Why
A Poor Fit For Agile 
Development 
• Difficult to test 
• Bad OO practices 
• Not friendly with dependency injection 
• Not Spring/Guice/IoC Container compatible 
• Custom configuration files 
• Not refactor-friendly 
• Produces important (maybe) untested code
Who Should Logging Be 
For? 
Operations!
What About Developers? 
Developers should 
run unit tests in a 
debugger
What To Change? 
• Not just a change in libraries 
• Not just a change in pattern 
• Change the process! 
Log for operations, not 
developers
The New 
Process
What Most Teams Do Now 
• Developers add logging while working on other 
stories 
• Usually without much guidance 
• Hand off to operations at the end 
• Operations figures out how to monitor 
• This isn’t tested 
• This usually isn’t much of a feedback loop 
• When there is, it’s probably informal
A Better Process 
• Stories for logging in the 
backlog 
• The Operations team is the 
customer 
• Collaborate between ops and 
dev
A Sample Story 
“As operations, I want a log 
entry to be written when the 
application starts, so that I can 
determine how often this 
happens over a period of 
time”
Operations Deserves 
• To know exactly what 
messages can occur 
• What each message means 
• Exactly what they should do
Operations Deserves 
Sometimes this is 
“something completely 
unexpected has 
happened, and you should 
call the developers”.
The New 
Pattern
Enum Based Logging
Enum Based Logging 
• An enum of all log messages
Enum Based Logging 
• An enum of all log messages 
• Each enum value has a 
unique code
Enum Based Logging 
• An enum of all log messages 
• Each enum value has a 
unique code 
• Each enum value has a 
format string
Enum Based Logging 
• An enum of all log messages 
• Each enum value has a unique code 
• Each enum value has a format string 
• To log: provide an enum value and 
format string arguments
The Output 
2014-­‐04-­‐30T17:46:49Z,-­‐,GDS-­‐0000,Published 
42 
records 
2014-­‐04-­‐30T17:48:18Z,-­‐,GDS-­‐0000,Published 
64 
records 
2014-­‐04-­‐30T17:52:45Z,-­‐,GDS-­‐0006,Config 
file 
foo.conf 
not 
found
Code Sample
Open Source
The Library 
• Open source (Apache2) 
• Opinionated 
• Simple output, easy to read, easy to 
parse 
• Small, simple, no transitive dependencies 
• Java 8 required
Testability Features 
• Designed for testability 
• Special test double 
• Mock framework agnostic 
• Contract tests for your enums 
• OpsLogger instances always use 
injection
Unique Features 
• Can automatically generate 
documentation 
• Logrotate friendly 
• Easy to parse with logstash 
• Special stack trace handling
Project Status 
• Release Candidate 
• Production Quality Code, properly tested 
• Good feature set 
• Needs documentation 
• Use in a serious production project 
before version 1.0
Gradle Dependencies 
repositories 
{ 
jcenter() 
} 
dependencies 
{ 
compile 
“com.equalexperts:opslogger:0.1.0-­‐rc1" 
testCompile 
“com.equalexperts:opslogger-­‐support:0.1.0-­‐rc1" 
}
Maven Dependencies 
<dependency> 
<groupId>com.equalexperts</groupId> 
<artifactId>opslogger</artifactId> 
<version>0.1.0-­‐rc1</version> 
</dependency> 
<dependency> 
<groupId>com.equalexperts</groupId> 
<artifactId>opslogger-­‐support</artifactId> 
<version>0.1.0-­‐rc1</version> 
<scope>test</scope> 
</dependency>
Thanks!

More Related Content

ODP
2014 ZAP Workshop 2: Contexts and Fuzzing
ODP
OWASP 2015 AppSec EU ZAP 2.4.0 and beyond..
ODP
BSides Manchester 2014 ZAP Advanced Features
PPTX
Rsyslog version naming (v8.6.0+)
ODP
2014 ZAP Workshop 1: Getting Started
PPTX
Ansible: What, Why & How
ODP
OWASP 2013 APPSEC USA ZAP Hackathon
ODP
OWASP 2014 AppSec EU ZAP Advanced Features
2014 ZAP Workshop 2: Contexts and Fuzzing
OWASP 2015 AppSec EU ZAP 2.4.0 and beyond..
BSides Manchester 2014 ZAP Advanced Features
Rsyslog version naming (v8.6.0+)
2014 ZAP Workshop 1: Getting Started
Ansible: What, Why & How
OWASP 2013 APPSEC USA ZAP Hackathon
OWASP 2014 AppSec EU ZAP Advanced Features

What's hot (20)

ODP
JoinSEC 2013 London - ZAP Intro
PPTX
Rebooting design in RavenDB
ODP
OWASP 2013 EU Tour Amsterdam ZAP Intro
ODP
OWASP 2013 AppSec EU Hamburg - ZAP Innovations
PPTX
Staying friendly with the gc
ODP
BlackHat 2014 OWASP ZAP Turbo Talk
ODP
JavaOne 2014 Security Testing for Developers using OWASP ZAP
PPTX
ZAP @FOSSASIA2015
ODP
OWASP 2013 Limerick - ZAP: Whats even newer
ODP
AllDayDevOps ZAP automation in CI
PDF
MPI, Erlang and the web
PPTX
Power shell v3 session1
PDF
High Performance Systems in Go - GopherCon 2014
ODP
Automating OWASP ZAP - DevCSecCon talk
PPTX
Ansible API
ODP
OWASP Zed Attack Proxy Demonstration - OWASP Bangalore Nov 22 2014
ODP
OWASP 2013 APPSEC USA Talk - OWASP ZAP
KEY
Sentry (SF Python, Feb)
PDF
Scaling Humans - BigPanda's Fabulous ChatOps Adventure - Erik Zaadi, BigPanda...
PDF
Devoxx PL 2018 - Microservices in action at the Dutch National Police
JoinSEC 2013 London - ZAP Intro
Rebooting design in RavenDB
OWASP 2013 EU Tour Amsterdam ZAP Intro
OWASP 2013 AppSec EU Hamburg - ZAP Innovations
Staying friendly with the gc
BlackHat 2014 OWASP ZAP Turbo Talk
JavaOne 2014 Security Testing for Developers using OWASP ZAP
ZAP @FOSSASIA2015
OWASP 2013 Limerick - ZAP: Whats even newer
AllDayDevOps ZAP automation in CI
MPI, Erlang and the web
Power shell v3 session1
High Performance Systems in Go - GopherCon 2014
Automating OWASP ZAP - DevCSecCon talk
Ansible API
OWASP Zed Attack Proxy Demonstration - OWASP Bangalore Nov 22 2014
OWASP 2013 APPSEC USA Talk - OWASP ZAP
Sentry (SF Python, Feb)
Scaling Humans - BigPanda's Fabulous ChatOps Adventure - Erik Zaadi, BigPanda...
Devoxx PL 2018 - Microservices in action at the Dutch National Police
Ad

Similar to Conditional Logging Considered Harmful - Sean Reilly (20)

PDF
Opslogger: Operations code (should be) production quality too!
PDF
FireBug And FirePHP
PPTX
Functionality, security and performance monitoring of web assets (e.g. Joomla...
PPTX
Java Logging
PDF
Enterprise PHP
PPT
PDF
Redundant devops
PDF
Lotuscript for large systems
PDF
Logging Application Behavior to MongoDB
PPTX
Build software like a bag of marbles, not a castle of LEGO®
KEY
Messaging, interoperability and log aggregation - a new framework
PPTX
Ansible Best Practices - July 30
PDF
Gearman: A Job Server made for Scale
KEY
Make It Cooler: Using Decentralized Version Control
PPTX
Putting Compilers to Work
PPTX
Praesidio - Log.error("impossible-")
PDF
Finding Needles in Haystacks
PDF
Erlang factory SF 2011 "Erlang and the big switch in social games"
PDF
Erlang, the big switch in social games
ZIP
All My Tests Are Passing, Now What?
Opslogger: Operations code (should be) production quality too!
FireBug And FirePHP
Functionality, security and performance monitoring of web assets (e.g. Joomla...
Java Logging
Enterprise PHP
Redundant devops
Lotuscript for large systems
Logging Application Behavior to MongoDB
Build software like a bag of marbles, not a castle of LEGO®
Messaging, interoperability and log aggregation - a new framework
Ansible Best Practices - July 30
Gearman: A Job Server made for Scale
Make It Cooler: Using Decentralized Version Control
Putting Compilers to Work
Praesidio - Log.error("impossible-")
Finding Needles in Haystacks
Erlang factory SF 2011 "Erlang and the big switch in social games"
Erlang, the big switch in social games
All My Tests Are Passing, Now What?
Ad

More from JAXLondon2014 (20)

PDF
GridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
PDF
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
PPTX
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
PDF
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
PPT
API Management - a hands on workshop - Paul Fremantle
PDF
'Bootiful' Code with Spring Boot - Josh Long
PDF
The Full Stack Java Developer - Josh Long
PDF
The Economies of Scaling Software - Josh Long and Abdelmonaim Remani
PDF
Dataflow, the Forgotten Way - Russel Winder
PDF
Habits of Highly Effective Technical Teams - Martijn Verburg
PDF
The Lazy Developer's Guide to Cloud Foundry - Holly Cummins
PPTX
Testing within an Agile Environment - Beyza Sakir and Chris Gollop
PDF
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
PDF
Squeezing Performance of out of In-Memory Data Grids - Fuad Malikov
PDF
Spocktacular Testing - Russel Winder
PDF
Server Side JavaScript on the Java Platform - David Delabassee
PDF
Reflection Madness - Dr. Heinz Kabutz
PDF
Rapid Web Application Development with MongoDB and the JVM - Trisha Gee
PDF
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
PDF
Personal Retrospectives - Johannes Thönes
GridGain 6.0: Open Source In-Memory Computing Platform - Nikita Ivanov
Performance Metrics for your Delivery Pipeline - Wolfgang Gottesheim
How to randomly access data in close-to-RAM speeds but a lower cost with SSD’...
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
API Management - a hands on workshop - Paul Fremantle
'Bootiful' Code with Spring Boot - Josh Long
The Full Stack Java Developer - Josh Long
The Economies of Scaling Software - Josh Long and Abdelmonaim Remani
Dataflow, the Forgotten Way - Russel Winder
Habits of Highly Effective Technical Teams - Martijn Verburg
The Lazy Developer's Guide to Cloud Foundry - Holly Cummins
Testing within an Agile Environment - Beyza Sakir and Chris Gollop
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Squeezing Performance of out of In-Memory Data Grids - Fuad Malikov
Spocktacular Testing - Russel Winder
Server Side JavaScript on the Java Platform - David Delabassee
Reflection Madness - Dr. Heinz Kabutz
Rapid Web Application Development with MongoDB and the JVM - Trisha Gee
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
Personal Retrospectives - Johannes Thönes

Recently uploaded (20)

PDF
natwest.pdf company description and business model
PPTX
Self management and self evaluation presentation
PPT
First Aid Training Presentation Slides.ppt
PPTX
Tour Presentation Educational Activity.pptx
PPTX
_ISO_Presentation_ISO 9001 and 45001.pptx
PPTX
Emphasizing It's Not The End 08 06 2025.pptx
PPTX
Impressionism_PostImpressionism_Presentation.pptx
PPTX
Sustainable Forest Management ..SFM.pptx
PPTX
nose tajweed for the arabic alphabets for the responsive
PPTX
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
PPTX
lesson6-211001025531lesson plan ppt.pptx
PDF
Instagram's Product Secrets Unveiled with this PPT
PPTX
Intro to ISO 9001 2015.pptx wareness raising
PPTX
Human Mind & its character Characteristics
PDF
Presentation1 [Autosaved].pdf diagnosiss
PPTX
worship songs, in any order, compilation
PPTX
PHIL.-ASTRONOMY-AND-NAVIGATION of ..pptx
PPTX
fundraisepro pitch deck elegant and modern
PPTX
An Unlikely Response 08 10 2025.pptx
PPT
The Effect of Human Resource Management Practice on Organizational Performanc...
natwest.pdf company description and business model
Self management and self evaluation presentation
First Aid Training Presentation Slides.ppt
Tour Presentation Educational Activity.pptx
_ISO_Presentation_ISO 9001 and 45001.pptx
Emphasizing It's Not The End 08 06 2025.pptx
Impressionism_PostImpressionism_Presentation.pptx
Sustainable Forest Management ..SFM.pptx
nose tajweed for the arabic alphabets for the responsive
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
lesson6-211001025531lesson plan ppt.pptx
Instagram's Product Secrets Unveiled with this PPT
Intro to ISO 9001 2015.pptx wareness raising
Human Mind & its character Characteristics
Presentation1 [Autosaved].pdf diagnosiss
worship songs, in any order, compilation
PHIL.-ASTRONOMY-AND-NAVIGATION of ..pptx
fundraisepro pitch deck elegant and modern
An Unlikely Response 08 10 2025.pptx
The Effect of Human Resource Management Practice on Organizational Performanc...

Conditional Logging Considered Harmful - Sean Reilly

  • 1. (Conditional) Logging Considered Harmful JAX London 2014
  • 2. About Me Sean Reilly @seanjreilly
  • 3. Logging Is Not Harmful In fact, it’s often useful. Conditional logging is harmful.
  • 4. What I Mean By “Conditional” • Many loggers, organised by class name • Many log levels: • SEVERE, ERROR, WARN, INFO, DEBUG, TRACE • SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST • ERROR, WARN, INFO, DEBUG, TRACE • Message only logged if log level is active for a logger
  • 5. Conditional Logging Frameworks • log4j • java.util.logging • Logback • slf4j • commons logging
  • 6. Why Developers Log This Way • “We can log everything in development and INFO in production” • “When something unexpected happens in production, we can increase the log level dynamically and get the extra information we need” • “It helps us debug while developing”
  • 7. The Real Reason What other options are there?
  • 8. Why Did We Decide To Use Something Else?
  • 10. A Poor Fit For Agile Development • Difficult to test • Bad OO practices • Not friendly with dependency injection • Not Spring/Guice/IoC Container compatible • Custom configuration files • Not refactor-friendly • Produces important (maybe) untested code
  • 11. Who Should Logging Be For? Operations!
  • 12. What About Developers? Developers should run unit tests in a debugger
  • 13. What To Change? • Not just a change in libraries • Not just a change in pattern • Change the process! Log for operations, not developers
  • 15. What Most Teams Do Now • Developers add logging while working on other stories • Usually without much guidance • Hand off to operations at the end • Operations figures out how to monitor • This isn’t tested • This usually isn’t much of a feedback loop • When there is, it’s probably informal
  • 16. A Better Process • Stories for logging in the backlog • The Operations team is the customer • Collaborate between ops and dev
  • 17. A Sample Story “As operations, I want a log entry to be written when the application starts, so that I can determine how often this happens over a period of time”
  • 18. Operations Deserves • To know exactly what messages can occur • What each message means • Exactly what they should do
  • 19. Operations Deserves Sometimes this is “something completely unexpected has happened, and you should call the developers”.
  • 22. Enum Based Logging • An enum of all log messages
  • 23. Enum Based Logging • An enum of all log messages • Each enum value has a unique code
  • 24. Enum Based Logging • An enum of all log messages • Each enum value has a unique code • Each enum value has a format string
  • 25. Enum Based Logging • An enum of all log messages • Each enum value has a unique code • Each enum value has a format string • To log: provide an enum value and format string arguments
  • 26. The Output 2014-­‐04-­‐30T17:46:49Z,-­‐,GDS-­‐0000,Published 42 records 2014-­‐04-­‐30T17:48:18Z,-­‐,GDS-­‐0000,Published 64 records 2014-­‐04-­‐30T17:52:45Z,-­‐,GDS-­‐0006,Config file foo.conf not found
  • 29. The Library • Open source (Apache2) • Opinionated • Simple output, easy to read, easy to parse • Small, simple, no transitive dependencies • Java 8 required
  • 30. Testability Features • Designed for testability • Special test double • Mock framework agnostic • Contract tests for your enums • OpsLogger instances always use injection
  • 31. Unique Features • Can automatically generate documentation • Logrotate friendly • Easy to parse with logstash • Special stack trace handling
  • 32. Project Status • Release Candidate • Production Quality Code, properly tested • Good feature set • Needs documentation • Use in a serious production project before version 1.0
  • 33. Gradle Dependencies repositories { jcenter() } dependencies { compile “com.equalexperts:opslogger:0.1.0-­‐rc1" testCompile “com.equalexperts:opslogger-­‐support:0.1.0-­‐rc1" }
  • 34. Maven Dependencies <dependency> <groupId>com.equalexperts</groupId> <artifactId>opslogger</artifactId> <version>0.1.0-­‐rc1</version> </dependency> <dependency> <groupId>com.equalexperts</groupId> <artifactId>opslogger-­‐support</artifactId> <version>0.1.0-­‐rc1</version> <scope>test</scope> </dependency>