SlideShare a Scribd company logo
©2010 Improving Enterprises, Inc.
Logging For Fun and Profit
Jane Prusakova
Jane.Prusakova@ImprovingEnter
prises.com
http://softwareandotherthings.blog
spot.com
Improving Enterprises
AA.com
2013
©2010 Improving Enterprises, Inc.
Why
How-to
Using the results
©2010 Improving Enterprises, Inc.
Why logging?
Enquiring minds want to know!
Avoid programming-by-coincidence
Trace what the users do
See effects of
Integration
Multithreading
High load
©2010 Improving Enterprises, Inc.
When to use logging?
Greenfield development
Brownfield development
what came before
the effect of changes
Maintenance and troubleshooting
trace bugs
Bonus
Evolve apps based on users behavior
©2010 Improving Enterprises, Inc.
Logging [vs Debugging]
Set up once, always ready to use
Minimum disruption to the flow
Works locally and in the cloud
Faster data collection
Collected data is persisted
©2010 Improving Enterprises, Inc.
How-to
Using the results
©2010 Improving Enterprises, Inc.
Yes, I want to setup logging!
Pick a framework
Proper configuration
Consider ways to parse logs
Logging will change with the application
©2010 Improving Enterprises, Inc.
Log4J SLF4J
Apache MIT license
Logging framework Logging facade
Configuration, log levels and categories,
rotate log files, thread-safe logging.
Support: online documentation, tutorials,
online forums.
©2010 Improving Enterprises, Inc.
Where to write logs?
Console
File system
DB
Queue mechanisms
Combination
©2010 Improving Enterprises, Inc.
Database Files
Easy to parse,
hard to evolve
Very hard to parse,
easy to change
Uses DB
connections
Requires FS
access
Can cause app
crash, loss of logs,
slow down app
Can fill up space
©2010 Improving Enterprises, Inc.
Configuring Log4J
Java properties-style
XML
Programmatically
Hard-coded
Takes preference
©2010 Improving Enterprises, Inc.
Log Message
What to log with the message
Importance level
When
Where in the code
Data being processed
Thread information
©2010 Improving Enterprises, Inc.
Example layout
log4j.appender.stdout.layout.ConversionPattern=
%d %5p [%t] (%F:%L) - %m%n
- Date
- Log Level
- Thread name
- File and line (slow to retrieve)
©2010 Improving Enterprises, Inc.
Enough and but not too much
Logging should support in code
correctness
readability
performance
Consider making logs easier to use
©2010 Improving Enterprises, Inc.
Best Practices
Relate each message to generating point
Code
Data
Format messages for readability
Use .ToString on objects
©2010 Improving Enterprises, Inc.
More Best Practices
Input and output
Errors and exceptions
Transitions
Integration points
Thread rendezvous
©2010 Improving Enterprises, Inc.
Log input and output
public int calculateCost(String user, Flight flight)
{
log.debug(“calculateCost: user “ + user + “:
“ + flight);
int cost = … ;
… // cost calculation
log.debug((“calculateCost: cost for “ + user
+ “ on “ + flight + “: “ + cost);
return cost;
}
©2010 Improving Enterprises, Inc.
Log errors and exceptions
// do dangerous work
result = DoDangerousWork(user, flight);
}
catch (Exception e)
{
log.error(“methodName: exception in
DoDangerousWork for user “ + user + “ on “ +
flight, e);
// recover or re-throw
}
©2010 Improving Enterprises, Inc.
More
Log destination, parameters, outcomes
DB calls
SOAP calls
Wait time
Thread joins
Available memory
Memory-intensive operations
Intermediate calculation results
For complicated calculations
©2010 Improving Enterprises, Inc.
Practices to avoid
Little information
… // step 1
Logger.info(“did something”);
… // ste 2
Logger.info(“did more work”);
foreach (…) {
… // useful work
Logger.info(“working hard”);
}
©2010 Improving Enterprises, Inc.
Watch for logging-caused bugs
Side effects
Logger.info(count++ “: did something”);
Errors and exceptions
Logger.info(m.GetValue());
©2010 Improving Enterprises, Inc.
More practices to avoid
DRY principle applies
©2010 Improving Enterprises, Inc.
Using the results
©2010 Improving Enterprises, Inc.
You’ve got logs!
Rotate logs: by size, by time
Retention policy
2-level storage
Provide access - read only!
Transfer and analysis
Warning: large datasets
©2010 Improving Enterprises, Inc.
Security and performance
Moving and processing
can impact performance
Absolutely no sensitive
data
©2010 Improving Enterprises, Inc.
Learning from the logs
Never rely on eye-balling
WYS is not WYG
Aggregate data
Distinguish common and
rare
©2010 Improving Enterprises, Inc.
Tools
Process datasets:
Line by line
grep, Perl, awk, cut, tail, head
Load entire file to eyeball
vi, notepad++
Better way to eyeball
more, less
©2010 Improving Enterprises, Inc.
Learning from the logs
> grep userName MyApplication.log
grep methodName MyApplication.log
grep threadName MyApplication.log
tail -2000 VeryImportant.log | grep Exception
grep FATAL MyApplication.log
©2010 Improving Enterprises, Inc.
Querying logs using Awk
GNU Awk www.gnu.org/software/gawk
create histograms
Wait times
Number of calls
Exceptions per time period or per user
Compare and relate events
Exception stacks traces
Outcomes by caller or thread
©2010 Improving Enterprises, Inc.
Logging For Fun and Profit
Jane Prusakova
Jane.Prusakova@ImprovingEnter
prises.com
http://softwareandotherthings.blog
spot.com
Improving Enterprises
AA.com
2013

More Related Content

Similar to Application logging for fun and profit (20)

PDF
Developer Fundamentals - Logging
Axel Irriger
 
PPT
19-reliabilitytesting.ppt
Anilteaser
 
PDF
LOGGING FOR FUN, AND PROFIT
Informatics Summit
 
PDF
Mining Development Knowledge to Understand and Support Software Logging Pract...
SAIL_QU
 
PDF
Helpful logging with Java
roskakori
 
PDF
Opslogger: Operations code (should be) production quality too!
Sean Reilly
 
PDF
Un-broken Logging - Operability.io 2015 - Matthew Skelton
Skelton Thatcher Consulting Ltd
 
PDF
Un-broken logging - the foundation of software operability - Operability.io -...
Matthew Skelton
 
PDF
Day 2 05 - steve feldman - logging matters
Steve Feldman
 
PDF
Sustainable Logging – SplunkLive! 2014
Paul Gilowey
 
PPTX
Cashing in on logging and exception data
Stackify
 
PPTX
Good code
Jane Prusakova
 
PDF
Un-broken Logging - TechnologyUG - Leeds - Matthew Skelton
Skelton Thatcher Consulting Ltd
 
PDF
P&MSP2012 - Logging Frameworks
Daniele Dell'Aglio
 
PPTX
Practical Data Management - ACRL DCIG Webinar
Kristin Briney
 
PDF
10 Tips to improve your application logs
Vanessa Gomes
 
PPT
Choosing Your Log Management Approach: Buy, Build or Outsource
Anton Chuvakin
 
PPTX
MojoPortal And Log4net
VerifiedAD.com
 
PDF
Logging
James Hollingworth
 
KEY
Message passing
Damien Krotkine
 
Developer Fundamentals - Logging
Axel Irriger
 
19-reliabilitytesting.ppt
Anilteaser
 
LOGGING FOR FUN, AND PROFIT
Informatics Summit
 
Mining Development Knowledge to Understand and Support Software Logging Pract...
SAIL_QU
 
Helpful logging with Java
roskakori
 
Opslogger: Operations code (should be) production quality too!
Sean Reilly
 
Un-broken Logging - Operability.io 2015 - Matthew Skelton
Skelton Thatcher Consulting Ltd
 
Un-broken logging - the foundation of software operability - Operability.io -...
Matthew Skelton
 
Day 2 05 - steve feldman - logging matters
Steve Feldman
 
Sustainable Logging – SplunkLive! 2014
Paul Gilowey
 
Cashing in on logging and exception data
Stackify
 
Good code
Jane Prusakova
 
Un-broken Logging - TechnologyUG - Leeds - Matthew Skelton
Skelton Thatcher Consulting Ltd
 
P&MSP2012 - Logging Frameworks
Daniele Dell'Aglio
 
Practical Data Management - ACRL DCIG Webinar
Kristin Briney
 
10 Tips to improve your application logs
Vanessa Gomes
 
Choosing Your Log Management Approach: Buy, Build or Outsource
Anton Chuvakin
 
MojoPortal And Log4net
VerifiedAD.com
 
Message passing
Damien Krotkine
 

More from Jane Prusakova (20)

PPTX
Software architecture houstontechfest2020
Jane Prusakova
 
PPTX
Estimating software development
Jane Prusakova
 
PPTX
Better remote teams
Jane Prusakova
 
PPTX
Thoughts on building software architecture
Jane Prusakova
 
PPTX
Improving IT Performance
Jane Prusakova
 
PPTX
Agile Software Development
Jane Prusakova
 
PPTX
Questions of Ethics in Software Development
Jane Prusakova
 
PPTX
Just startcoding
Jane Prusakova
 
PPTX
Just start coding
Jane Prusakova
 
PPTX
Managing remote teams.
Jane Prusakova
 
PPTX
Gender-neutral Recruiting
Jane Prusakova
 
PPTX
Privacy In The Digital Age
Jane Prusakova
 
PPTX
Interview: a Learning Conversation
Jane Prusakova
 
PPTX
Effective Code Review
Jane Prusakova
 
PPTX
Effective Code Review
Jane Prusakova
 
PPTX
Lets talk about good code
Jane Prusakova
 
PPTX
Motivating Knowledge Workers
Jane Prusakova
 
PPTX
What is good code?
Jane Prusakova
 
PPTX
Pragmatic Agile: distributed teams
Jane Prusakova
 
PPTX
A case for remote teams
Jane Prusakova
 
Software architecture houstontechfest2020
Jane Prusakova
 
Estimating software development
Jane Prusakova
 
Better remote teams
Jane Prusakova
 
Thoughts on building software architecture
Jane Prusakova
 
Improving IT Performance
Jane Prusakova
 
Agile Software Development
Jane Prusakova
 
Questions of Ethics in Software Development
Jane Prusakova
 
Just startcoding
Jane Prusakova
 
Just start coding
Jane Prusakova
 
Managing remote teams.
Jane Prusakova
 
Gender-neutral Recruiting
Jane Prusakova
 
Privacy In The Digital Age
Jane Prusakova
 
Interview: a Learning Conversation
Jane Prusakova
 
Effective Code Review
Jane Prusakova
 
Effective Code Review
Jane Prusakova
 
Lets talk about good code
Jane Prusakova
 
Motivating Knowledge Workers
Jane Prusakova
 
What is good code?
Jane Prusakova
 
Pragmatic Agile: distributed teams
Jane Prusakova
 
A case for remote teams
Jane Prusakova
 
Ad

Recently uploaded (20)

PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
Q2 Leading a Tableau User Group - Onboarding
lward7
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Q2 Leading a Tableau User Group - Onboarding
lward7
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Ad

Application logging for fun and profit

  • 1. ©2010 Improving Enterprises, Inc. Logging For Fun and Profit Jane Prusakova Jane.Prusakova@ImprovingEnter prises.com http://softwareandotherthings.blog spot.com Improving Enterprises AA.com 2013
  • 2. ©2010 Improving Enterprises, Inc. Why How-to Using the results
  • 3. ©2010 Improving Enterprises, Inc. Why logging? Enquiring minds want to know! Avoid programming-by-coincidence Trace what the users do See effects of Integration Multithreading High load
  • 4. ©2010 Improving Enterprises, Inc. When to use logging? Greenfield development Brownfield development what came before the effect of changes Maintenance and troubleshooting trace bugs Bonus Evolve apps based on users behavior
  • 5. ©2010 Improving Enterprises, Inc. Logging [vs Debugging] Set up once, always ready to use Minimum disruption to the flow Works locally and in the cloud Faster data collection Collected data is persisted
  • 6. ©2010 Improving Enterprises, Inc. How-to Using the results
  • 7. ©2010 Improving Enterprises, Inc. Yes, I want to setup logging! Pick a framework Proper configuration Consider ways to parse logs Logging will change with the application
  • 8. ©2010 Improving Enterprises, Inc. Log4J SLF4J Apache MIT license Logging framework Logging facade Configuration, log levels and categories, rotate log files, thread-safe logging. Support: online documentation, tutorials, online forums.
  • 9. ©2010 Improving Enterprises, Inc. Where to write logs? Console File system DB Queue mechanisms Combination
  • 10. ©2010 Improving Enterprises, Inc. Database Files Easy to parse, hard to evolve Very hard to parse, easy to change Uses DB connections Requires FS access Can cause app crash, loss of logs, slow down app Can fill up space
  • 11. ©2010 Improving Enterprises, Inc. Configuring Log4J Java properties-style XML Programmatically Hard-coded Takes preference
  • 12. ©2010 Improving Enterprises, Inc. Log Message What to log with the message Importance level When Where in the code Data being processed Thread information
  • 13. ©2010 Improving Enterprises, Inc. Example layout log4j.appender.stdout.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n - Date - Log Level - Thread name - File and line (slow to retrieve)
  • 14. ©2010 Improving Enterprises, Inc. Enough and but not too much Logging should support in code correctness readability performance Consider making logs easier to use
  • 15. ©2010 Improving Enterprises, Inc. Best Practices Relate each message to generating point Code Data Format messages for readability Use .ToString on objects
  • 16. ©2010 Improving Enterprises, Inc. More Best Practices Input and output Errors and exceptions Transitions Integration points Thread rendezvous
  • 17. ©2010 Improving Enterprises, Inc. Log input and output public int calculateCost(String user, Flight flight) { log.debug(“calculateCost: user “ + user + “: “ + flight); int cost = … ; … // cost calculation log.debug((“calculateCost: cost for “ + user + “ on “ + flight + “: “ + cost); return cost; }
  • 18. ©2010 Improving Enterprises, Inc. Log errors and exceptions // do dangerous work result = DoDangerousWork(user, flight); } catch (Exception e) { log.error(“methodName: exception in DoDangerousWork for user “ + user + “ on “ + flight, e); // recover or re-throw }
  • 19. ©2010 Improving Enterprises, Inc. More Log destination, parameters, outcomes DB calls SOAP calls Wait time Thread joins Available memory Memory-intensive operations Intermediate calculation results For complicated calculations
  • 20. ©2010 Improving Enterprises, Inc. Practices to avoid Little information … // step 1 Logger.info(“did something”); … // ste 2 Logger.info(“did more work”); foreach (…) { … // useful work Logger.info(“working hard”); }
  • 21. ©2010 Improving Enterprises, Inc. Watch for logging-caused bugs Side effects Logger.info(count++ “: did something”); Errors and exceptions Logger.info(m.GetValue());
  • 22. ©2010 Improving Enterprises, Inc. More practices to avoid DRY principle applies
  • 23. ©2010 Improving Enterprises, Inc. Using the results
  • 24. ©2010 Improving Enterprises, Inc. You’ve got logs! Rotate logs: by size, by time Retention policy 2-level storage Provide access - read only! Transfer and analysis Warning: large datasets
  • 25. ©2010 Improving Enterprises, Inc. Security and performance Moving and processing can impact performance Absolutely no sensitive data
  • 26. ©2010 Improving Enterprises, Inc. Learning from the logs Never rely on eye-balling WYS is not WYG Aggregate data Distinguish common and rare
  • 27. ©2010 Improving Enterprises, Inc. Tools Process datasets: Line by line grep, Perl, awk, cut, tail, head Load entire file to eyeball vi, notepad++ Better way to eyeball more, less
  • 28. ©2010 Improving Enterprises, Inc. Learning from the logs > grep userName MyApplication.log grep methodName MyApplication.log grep threadName MyApplication.log tail -2000 VeryImportant.log | grep Exception grep FATAL MyApplication.log
  • 29. ©2010 Improving Enterprises, Inc. Querying logs using Awk GNU Awk www.gnu.org/software/gawk create histograms Wait times Number of calls Exceptions per time period or per user Compare and relate events Exception stacks traces Outcomes by caller or thread
  • 30. ©2010 Improving Enterprises, Inc. Logging For Fun and Profit Jane Prusakova Jane.Prusakova@ImprovingEnter prises.com http://softwareandotherthings.blog spot.com Improving Enterprises AA.com 2013

Editor's Notes

  • #3: Shilpa: Without proper planning and clear strategy, the log messages produced by the system may not be useful for problem resolution.Effective logging is a balance between logging enough data to debug problems, while not dumping so much it confuses the issue.
  • #7: Shilpa: Without proper planning and clear strategy, the log messages produced by the system may not be useful for problem resolution.Effective logging is a balance between logging enough data to debug problems, while not dumping so much it confuses the issue.
  • #9: Log4J is old, excellent, widely used framework.SLF4J is written by the same author as Log4J. Both licenses permit for-profit usage.
  • #10: Both Log4net and Nlog are open source, free libraries. Well-used and well-loved, mature technologies, that are known to work very well. No option to buy corporate support, but there is plenty of free support from the user community available online.
  • #11: Console – for debugging purposes onlyWhile I prefer to log to a file: More flexibility to change what is being loggedLogging doesn’t compete with the application for DB connectionsDB access is broken more often than file accessWhy you may choose to log to the DB: Easier to parse logsIt is possible to use Aspects to separate logging concerns from the application logic - for logs that are stable. If you use logging to trace problems as the application is being developed and maintained – putting logs with the code is simpler and helps to shorted the development cycle.
  • #12: While I prefer to log to a file: More flexibility to change what is being loggedLogging doesn’t compete with the application for DB connectionsDB access is broken more often than file accessWhy you may choose to log to the DB: Easier to parse logsIt is possible to use Aspects to separate logging concerns from the application logic - for logs that are stable. If you use logging to trace problems as the application is being developed and maintained – putting logs with the code is simpler and helps to shorted the development cycle.
  • #13: Java properties is older, XML format can be more convenient since lots of other configuration is also done in XML.Whichever configuration file is found first on the file path is loaded and used. Configuring logging in code is generally a bad idea – any changes will require a re-compile and re-install.
  • #14: Where in the code can be specified approximately, by outputting class, or in details, with file name, full class path, line number of the log request. Depending on the situation, it maybe helpful to have: Method caller informationthread diagnostic context-additional information on the state of the calling codeEach logging event should generate 1 line in the log file – makes for easier log processing.
  • #15: While I prefer to log to a file: More flexibility to change what is being loggedLogging doesn’t compete with the application for DB connectionsDB access is broken more often than file accessWhy you may choose to log to the DB: Easier to parse logsIt is possible to use Aspects to separate logging concerns from the application logic - for logs that are stable. If you use logging to trace problems as the application is being developed and maintained – putting logs with the code is simpler and helps to shorted the development cycle.
  • #16: Go back to examples
  • #17: Go back to examples
  • #18: Go back to examples
  • #19: Go back to examples
  • #21: Unless step 1 or step 2 throw, we already know both will happen – no need to log the second.When putting loggin inside a loop, it’s helpful to record loop counter and the item being processed.
  • #22: Make sure logging operation itself will not add errors.Wrapping logging code in try-catch adds lines, making code less readable, and overhead. So, test!
  • #23: It is important that logs are dense with information. If logging an object with no ToString method, it’s full type name will be printed – bad.Frameworks provide a way to post file and line from where logging is done – no need to do it in text. It’s fine to reduce logging as the code becomes stable and appears to have no more bugs.
  • #24: Shilpa: Without proper planning and clear strategy, the log messages produced by the system may not be useful for problem resolution.Effective logging is a balance between logging enough data to debug problems, while not dumping so much it confuses the issue.
  • #25: How to handle large log files,e.g Roll the files.... (zip them up after certain days etc....)
  • #26: Programs that experience issues tend to log more, causing higher log volume, more stress on the disk, and more frequent log rotation. Which could make the situation worse. Watching log’s rate of growth can provide information on the health of the application.
  • #27: A rare bug is harder to trace – and usually presents less of a problem to the business. When arbitraging future work, use logs to learn what users want.
  • #28: Cygwin-provided Unix utilities work great on Windows
  • #29: Target your research: Trace by user, by what happens in a particular piece of code, or what is logged at a particular level.
  • #30: A rare bug is harder to trace – and usually presents less of a problem to the business. When arbitraging future work, use logs to learn what users want.