Application Logging for large systems

904 views

Published on

Logging what is taking place in your application provides important insights into applications at runtime, and can be extremely helpful to support analysts when something goes wrong.

We'll discuss best practices about what, why, and how to log and what to avoid when logging, as well as where write your logs and how to decide what logging framework to use. Time permitting, we'll talk about log analysis tools to help make sense of large log files as well.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
904
On SlideShare
0
From Embeds
0
Number of Embeds
22
Actions
Shares
0
Downloads
19
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Application Logging for large systems

  1. 1. ©2010 Improving Enterprises, Inc. Logging For Fun and Profit Jane Prusakova Jane.Prusakova@ImprovingEnterprises.com http://softwareandotherthings.blogspot.com Improving Enterprises Houston JUG 2014
  2. 2. ©2010 Improving Enterprises, Inc. Jane Prusakova Hard-core developer Data science geek Dancer and photographer
  3. 3. ©2010 Improving Enterprises, Inc. Why How-to Using the results So lets talk about logging…
  4. 4. ©2010 Improving Enterprises, Inc. Peek into the soul Real setup Real data Real users Real work Dev environment Happy path Minimum load Limited data
  5. 5. ©2010 Improving Enterprises, Inc. Inside the cloud No programming-by-coincidence Replaces debugging Works on server
  6. 6. ©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
  7. 7. ©2010 Improving Enterprises, Inc. Logging helps with… Integration Multithreading High load
  8. 8. ©2010 Improving Enterprises, Inc. What else? Trace what the users do Features Sequences Data flow
  9. 9. ©2010 Improving Enterprises, Inc. When to use logging? New systems New features Bug fixing
  10. 10. ©2010 Improving Enterprises, Inc. Are logs forever? Permanent Errors Extraordinary situations
  11. 11. ©2010 Improving Enterprises, Inc. Some are seasonal Very temporary Debugging info Trace bug fixes
  12. 12. ©2010 Improving Enterprises, Inc. Others last awhile Medium term Data flow Resource utilization Optimization points
  13. 13. ©2010 Improving Enterprises, Inc. How-to Using the results
  14. 14. ©2010 Improving Enterprises, Inc. Yes, I want to setup logging! Pick a framework Configure logging Storage and access Getting value from logs
  15. 15. ©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.
  16. 16. ©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
  17. 17. ©2010 Improving Enterprises, Inc. Where to write logs? Console File system DB Queue mechanisms Combination
  18. 18. ©2010 Improving Enterprises, Inc. Logging configuration Java properties-style XML Programmatically Hard-coded Takes preference
  19. 19. ©2010 Improving Enterprises, Inc. Log Message What to log with the message Importance level Timestamp Where in the code Data being processed System state info
  20. 20. ©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)
  21. 21. ©2010 Improving Enterprises, Inc. Good log messages Support code Correctness Readability Performance
  22. 22. ©2010 Improving Enterprises, Inc. Better log messages Relate to generating point Code Data
  23. 23. ©2010 Improving Enterprises, Inc. Best log messages Are formatted for Readability Aggregation
  24. 24. ©2010 Improving Enterprises, Inc. Logging objects .toString() org.apache.commons.lang.builder.ToStringBuilder log.info(myDataObject);
  25. 25. ©2010 Improving Enterprises, Inc. What to log Input and output Errors and exceptions Computation results Integration points Thread rendezvous
  26. 26. ©2010 Improving Enterprises, Inc. Input and output public int calculateCost(String user, Flight flight) { log.debug(“calculateCost: “ + user + “: “ + flight); int cost = … ; … // cost calculation log.debug((“calculateCost: cost for “ + user + “: “ + flight + “ = “ + cost); return cost; }
  27. 27. ©2010 Improving Enterprises, Inc. Errors and exceptions // do dangerous work result = DoDangerousWork(user, flight); } catch (Exception e) { log.error(“methodName: exception in DoDangerousWork for “ + user + “: “ + flight, e); // recover or re-throw }
  28. 28. ©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
  29. 29. ©2010 Improving Enterprises, Inc. Avoid Little information … // step 1 logger.info(“did something - XXXX”); … // step 2 logger.info(“did more work - YYYY”); foreach (…) { … // useful work logger.info(“working hard”); }
  30. 30. ©2010 Improving Enterprises, Inc. Avoid Code cluttering if (logger.isDebugEnabled()) { logger.debug(“Show Views"); logger.debug("Address:n" + view.getAddress()); logger.debug("Email:n" + view.getEmail()); }
  31. 31. ©2010 Improving Enterprises, Inc. Watch for logging-caused bugs Side effects Logger.info(count++ + “: did something”); Errors and exceptions Logger.info(m.GetValue());
  32. 32. ©2010 Improving Enterprises, Inc. DRY principle applies
  33. 33. ©2010 Improving Enterprises, Inc. Growing, growing… Naming conventions Rotation by size by time
  34. 34. ©2010 Improving Enterprises, Inc. You’ve got logs! Real-time access Deal with space limitations Warning: large datasets
  35. 35. ©2010 Improving Enterprises, Inc. Security Absolutely No Sensitive Data
  36. 36. ©2010 Improving Enterprises, Inc. Using the results
  37. 37. ©2010 Improving Enterprises, Inc. Learning from the logs Never rely on eye-balling WYS is not WYG Distinguish common and rare
  38. 38. ©2010 Improving Enterprises, Inc. Code and logs
  39. 39. ©2010 Improving Enterprises, Inc. Process log Line by line No need to load entire file Aggregate events Relate to time
  40. 40. ©2010 Improving Enterprises, Inc. Tools Utilities grep sort uniq Scripting Perl Awk sed
  41. 41. ©2010 Improving Enterprises, Inc. Learning from the logs > grep userName myApplication-MMDDYYYY.log > grep methodName myApplication-MMDDYYYY.log > grep FATAL myApplication-MMDDYYYY.log > tail -2000 myApplication-MMDDYYYY.log | grep Exception
  42. 42. ©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
  43. 43. ©2010 Improving Enterprises, Inc. AWK demo Logs for the demo generously provided by http://42graphy.org/
  44. 44. ©2010 Improving Enterprises, Inc. Jane.Prusakova at ImprovingEnterprises.com SoftwareAndOtherThings.blogspot.com @jprusakova Jane Prusakova http://www.slideshare.net/jprusakova
  45. 45. ©2010 Improving Enterprises, Inc. Logging For Fun and Profit Jane Prusakova Jane.Prusakova@ImprovingEnterprises.com http://softwareandotherthings.blogspot.com Improving Enterprises Houston JUG 2014

×