SlideShare a Scribd company logo
LOGS
A presentation about why and how we should
care about them.
Vanessa Gomes de Lima
WHY DO I NEED
LOGS?
Logs are mostly needed for monitoring and
troubleshooting. Put yourself in a
troubleshooter's shoes and think what type of logs
you'd like to have when something wrong is
happening or has happened in the dead of night.
Logs have no fixed beginning or end; they are
streams, flowing continuously as long as the app is
operating.
10 TIPS FOR PROPER
APPLICATION
LOGGING
1. USE THE
APPROPRIATE
TOOLS FOR THE JOB
USE THE APPROPRIATE TOOLS FOR THE JOB
✘ System.out.println( "Database connection " +
connection.status());
✘ print("logging");
Use tools that are specific for logging.
✓ log.debug("Found {} records matching filter: '{}'" ,
records, filter);
2. LOGGING LEVELS
DON'T FORGET LOGGING LEVELS
● ERROR – something terribly wrong had happened, that
must be investigated immediately. No system can tolerate
items logged on this level.
● WARN – the process might be continued, but take extra
caution.
DON'T FORGET LOGGING LEVELS
● INFO – Important business process has finished.
● DEBUG – Developers stuff.
● TRACE – Very detailed information, intended only for
development.
3. AVOID SIDE
EFFECTS
Logging statements should have no or little
impact on the application’s behavior.
AVOID SIDE EFFECTS
✘ Logs that throw exceptions
✘ Logs that slow down the application
4. BE CONCISE AND
DESCRIPTIVE
BE CONCISE AND DESCRIPTIVE
✘ log.info("Logging...");
✘ log.info("Passou porr***!!!!" )
✘ log.error("Database error..." );
✘ log.error("Something went wrong" );
✘ logger.error(str(e))
BE CONCISE AND DESCRIPTIVE
● Each log statement should contain both data and
description
✓ log.debug("Message with id '{}' processed" ,
message.getMessageId());
✓ log.error("[Pictures Upload] Upload picture with id: {}
failed.", picture.getId());
✓ Don't log any personal information nor passwords.
5. TUNE YOUR
PATTERN
TUNE YOUR PATTERN
● A simple logging pattern includes:
○ Time
○ Logging level
○ Name of thread
○ Simple logger name
○ Message
<pattern>%d{HH:mm:ss.SSS} %-5level [%thread][%logger{0}]
%m%n</pattern>
OUT 2016-08-02 07:14:51,926 ERROR [SimpleAsyncTaskExecutor-1] [Pictures
Upload] Upload picture with id: 3456 failed.
✘ You should never include file name, class name and line
number, although it’s very tempting.
log.info(User. class.getName())
6. LOG METHOD
ARGUMENTS AND
RETURN VALUES
LOG METHOD ARGS AND RETURN VALUES
● Consider logging arguments and return values specially
when the interaction is happening with external systems,
databases, waits, etc.
● You should consider DEBUG or TRACE levels as best suited
for these types of logs.
def upload(id):
log.debug("[Pictures Upload] Start Upload picture with id:
{}", id))
#code…
#code...
log.debug("[Pictures Upload] Upload picture with id: {}
finished", id)
return id
7. WATCH OUT FOR
EXTERNAL SYSTEMS
If you communicate with an external system, consider logging every piece of data that
comes out from your application and gets in.
8. LOG EXCEPTIONS
PROPERLY
LOG EXCEPTIONS PROPERLY
● If you really want to log an Exception, write the clear
nature of the problem and pass the exception to your
logger.
SLF4j
✘ log.error(e.getMessage());
✘ log.error(str(e))
✓ log.error("[User Auth] Failed for user {}. Problem:
{}", user.getId(), e);
OUT 2016-08-02 07:16:27,660 ERROR [SimpleAsyncTaskExecutor-1] [User Auth]
Failed for user: 3456. Problem:
org.springframework.web.client.ResourceAccessException: I/O error on PUT
request for "http://host": Connection timed out
LOG EXCEPTIONS PROPERLY
log.error("[User Auth] Failed for user {}. Problem:
{}", user.getId(), e);
9. EASY TO READ,
EASY TO PARSE
EASY TO READ, EASY TO PARSE
● Write logging messages in such a way, that they could be
understood both by humans and computers
● Avoid formatting of numbers
● Use patterns that can be easily recognized by regular
expressions
10. DO YOU KNOW
WHAT YOU ARE
LOGGING?
DO YOU KNOW WHAT ARE YOU LOGGING?
● Make sure your logs tell a story about how your
application is working. You can do that by:
a. List the steps of your application
b. Log each step and substep at the right log level
c. Make sure you identify parallel work
d. Be happy!
REFERENCES
● Apache Commons Logging
● 10 Tips for Proper Application Logging
● Patterns for Logging Diagnostic Messages
THANK YOU
For questions or suggestions:
Vanessa Gomes de Lima
vlima@thoughtworks.com

More Related Content

PDF
TYPO3 User Group - Lausanne - 12 novembre 2013
PPTX
MojoPortal And Log4net
PPTX
Logging, Serilog, Structured Logging, Seq
ODP
Troubleshooting Plone
PPTX
Logging.pptxbjjjjbhhn bhnjnnnnnnnnnnnn
PDF
Instrumentation of Software Systems
ODP
dJango
TYPO3 User Group - Lausanne - 12 novembre 2013
MojoPortal And Log4net
Logging, Serilog, Structured Logging, Seq
Troubleshooting Plone
Logging.pptxbjjjjbhhn bhnjnnnnnnnnnnnn
Instrumentation of Software Systems
dJango

Similar to 10 Tips to improve your application logs (20)

PPTX
PPTX
Praesidio - Log.error("impossible-")
PDF
Post-Mortem Debugging and Web Development
ODP
PPTX
Java Logging
PDF
Hacking Ruby on Rails at Railswaycon09
PDF
TDC 2015 - POA - Trilha PHP - Shit Happens
PDF
PPTX
Functional and non functional application logging
PPT
LoggingBestPractices
PDF
Building of systems of automatic C/C++ code logging
PPTX
How to Use OWASP Security Logging
PPT
General Principles of Web Security
PDF
Helpful logging with Java
PPTX
Python Programming Essentials - M27 - Logging module
PDF
Good practices for debugging Selenium and Appium tests
PDF
Django best practices for logging and signals
PDF
Coding for production
PDF
Advanced iOS Debbuging (Reloaded)
Praesidio - Log.error("impossible-")
Post-Mortem Debugging and Web Development
Java Logging
Hacking Ruby on Rails at Railswaycon09
TDC 2015 - POA - Trilha PHP - Shit Happens
Functional and non functional application logging
LoggingBestPractices
Building of systems of automatic C/C++ code logging
How to Use OWASP Security Logging
General Principles of Web Security
Helpful logging with Java
Python Programming Essentials - M27 - Logging module
Good practices for debugging Selenium and Appium tests
Django best practices for logging and signals
Coding for production
Advanced iOS Debbuging (Reloaded)

Recently uploaded (20)

PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Mushroom cultivation and it's methods.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Hybrid model detection and classification of lung cancer
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
TLE Review Electricity (Electricity).pptx
SOPHOS-XG Firewall Administrator PPT.pptx
DP Operators-handbook-extract for the Mautical Institute
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
OMC Textile Division Presentation 2021.pptx
Encapsulation theory and applications.pdf
Web App vs Mobile App What Should You Build First.pdf
Chapter 5: Probability Theory and Statistics
Digital-Transformation-Roadmap-for-Companies.pptx
Heart disease approach using modified random forest and particle swarm optimi...
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Mushroom cultivation and it's methods.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
WOOl fibre morphology and structure.pdf for textiles
Hybrid model detection and classification of lung cancer
Zenith AI: Advanced Artificial Intelligence
cloud_computing_Infrastucture_as_cloud_p
Programs and apps: productivity, graphics, security and other tools
TLE Review Electricity (Electricity).pptx

10 Tips to improve your application logs

  • 1. LOGS A presentation about why and how we should care about them. Vanessa Gomes de Lima
  • 2. WHY DO I NEED LOGS?
  • 3. Logs are mostly needed for monitoring and troubleshooting. Put yourself in a troubleshooter's shoes and think what type of logs you'd like to have when something wrong is happening or has happened in the dead of night.
  • 4. Logs have no fixed beginning or end; they are streams, flowing continuously as long as the app is operating.
  • 5. 10 TIPS FOR PROPER APPLICATION LOGGING
  • 7. USE THE APPROPRIATE TOOLS FOR THE JOB ✘ System.out.println( "Database connection " + connection.status()); ✘ print("logging"); Use tools that are specific for logging. ✓ log.debug("Found {} records matching filter: '{}'" , records, filter);
  • 9. DON'T FORGET LOGGING LEVELS ● ERROR – something terribly wrong had happened, that must be investigated immediately. No system can tolerate items logged on this level. ● WARN – the process might be continued, but take extra caution.
  • 10. DON'T FORGET LOGGING LEVELS ● INFO – Important business process has finished. ● DEBUG – Developers stuff. ● TRACE – Very detailed information, intended only for development.
  • 11. 3. AVOID SIDE EFFECTS Logging statements should have no or little impact on the application’s behavior.
  • 12. AVOID SIDE EFFECTS ✘ Logs that throw exceptions ✘ Logs that slow down the application
  • 13. 4. BE CONCISE AND DESCRIPTIVE
  • 14. BE CONCISE AND DESCRIPTIVE ✘ log.info("Logging..."); ✘ log.info("Passou porr***!!!!" ) ✘ log.error("Database error..." ); ✘ log.error("Something went wrong" ); ✘ logger.error(str(e))
  • 15. BE CONCISE AND DESCRIPTIVE ● Each log statement should contain both data and description ✓ log.debug("Message with id '{}' processed" , message.getMessageId()); ✓ log.error("[Pictures Upload] Upload picture with id: {} failed.", picture.getId()); ✓ Don't log any personal information nor passwords.
  • 17. TUNE YOUR PATTERN ● A simple logging pattern includes: ○ Time ○ Logging level ○ Name of thread ○ Simple logger name ○ Message <pattern>%d{HH:mm:ss.SSS} %-5level [%thread][%logger{0}] %m%n</pattern> OUT 2016-08-02 07:14:51,926 ERROR [SimpleAsyncTaskExecutor-1] [Pictures Upload] Upload picture with id: 3456 failed. ✘ You should never include file name, class name and line number, although it’s very tempting. log.info(User. class.getName())
  • 18. 6. LOG METHOD ARGUMENTS AND RETURN VALUES
  • 19. LOG METHOD ARGS AND RETURN VALUES ● Consider logging arguments and return values specially when the interaction is happening with external systems, databases, waits, etc. ● You should consider DEBUG or TRACE levels as best suited for these types of logs. def upload(id): log.debug("[Pictures Upload] Start Upload picture with id: {}", id)) #code… #code... log.debug("[Pictures Upload] Upload picture with id: {} finished", id) return id
  • 20. 7. WATCH OUT FOR EXTERNAL SYSTEMS If you communicate with an external system, consider logging every piece of data that comes out from your application and gets in.
  • 22. LOG EXCEPTIONS PROPERLY ● If you really want to log an Exception, write the clear nature of the problem and pass the exception to your logger. SLF4j ✘ log.error(e.getMessage()); ✘ log.error(str(e)) ✓ log.error("[User Auth] Failed for user {}. Problem: {}", user.getId(), e); OUT 2016-08-02 07:16:27,660 ERROR [SimpleAsyncTaskExecutor-1] [User Auth] Failed for user: 3456. Problem: org.springframework.web.client.ResourceAccessException: I/O error on PUT request for "http://host": Connection timed out
  • 23. LOG EXCEPTIONS PROPERLY log.error("[User Auth] Failed for user {}. Problem: {}", user.getId(), e);
  • 24. 9. EASY TO READ, EASY TO PARSE
  • 25. EASY TO READ, EASY TO PARSE ● Write logging messages in such a way, that they could be understood both by humans and computers ● Avoid formatting of numbers ● Use patterns that can be easily recognized by regular expressions
  • 26. 10. DO YOU KNOW WHAT YOU ARE LOGGING?
  • 27. DO YOU KNOW WHAT ARE YOU LOGGING? ● Make sure your logs tell a story about how your application is working. You can do that by: a. List the steps of your application b. Log each step and substep at the right log level c. Make sure you identify parallel work d. Be happy!
  • 28. REFERENCES ● Apache Commons Logging ● 10 Tips for Proper Application Logging ● Patterns for Logging Diagnostic Messages
  • 29. THANK YOU For questions or suggestions: Vanessa Gomes de Lima vlima@thoughtworks.com