aschuma

JAVA :: Error Logging :: Advices

Aug 17th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. https://blog.codecentric.de/en/2016/01/using-exceptions-to-write-robust-software-for-stable-production/
  2.  
  3. Log messages
  4.  
  5. The primary purpose of the log message is to help the analysis of the problem after it occurred (post mortem). The log message should contain all relevant information to identify the problem and its cause fast and with high probability. What are the questions a log message for a problem should be able to answer?
  6.  
  7. - What has been tried?
  8. - Which were the parameter values?
  9. - What was the result? This usually means the caught exception or some error code.
  10. - How does the method react to this?
  11. - Optional: What are possible reasons for the problem?
  12. - Optional: What are possible consequences?
  13.  
  14. For some time now, I prefer to write such log messages starting with “Failed to ” and which form one or more sentences. So the pattern is “Failed to VERB with/for/of/from OBJECT.”
  15.  
  16. Some fictitious examples:
  17.  
  18. WARN: “Failed to create scaled thumbnail file for /tmp/foo.gif. Will return the original file as thumbnail. This may increase the used bandwidth. Saved the original file unter /tmp/bc2384d4-555d-11e5-9913-600308a94de6 for later analysis. Is imagemagick installed and in the PATH?”
  19.  
  20. ERROR: “Failed to get prices for Contract[…] from the backend. Will return null to indicate no-price. Does the monitoring at http://…. show a problem with the backend?”
  21.  
  22. INFO: “Failed to send email about Contract[…] to [email protected]. Will retry 3 more times after a timeout of 2.4s.”
  23.  
  24. INFO: “Succeeded in sending email about Contract[…] to [email protected] after 2 tries.”
  25.  
  26. WARN: “Failed to send email about Contract[…] to [email protected]. No more retries left. The number of emails sent in the monthly report may be off.”
  27.  
  28. INFO: “Failed to get logged in user from the HTTP session. Will send a 401 back. User will have to log in once again. Maybe a timed out session?”
  29.  
  30. WARN: “Failed to send event UserLoggedIn[…] using kafka (server …). Will return false to indicate a problem.”
Advertisement
Add Comment
Please, Sign In to add comment