Exception and Error-Log (Server Side)

Exception and Error-Log (Server Side)

Explains basis of exception and error-log, and proposes to collect all related information to one log record for intuitive debugging.

4ccf6c02807d06f043a71435c48ce86a?s=128

Kengo TODA

May 21, 2016
Tweet

Transcript

  1. EXCEPTION AND ERROR LOG (SERVER SIDE) 2016/May/21 Kengo TODA

  2. AGENDA What is error-log and exception? Why we need error-log

    and exception? How we need to use them? Appendix: How to use log levels?
  3. WHAT IS ERROR-LOG?

  4. INTERFACE OF LOG (SLF4J) Level Message with placeholder Exception Mapped

    Diagnostic Contexts
  5. SLF4J PLACEHOLDER Placeholder is effective to optimise performance Logging library

    will invoke #toString() only when they need. It also makes log format intuitive. Logging library will concat them only when they need. No need to wrap by 
 if(logger.isXxxEnabled()){…}
  6. LOG (SLF4J) WITH EXCEPTION

  7. WHAT IS EXCEPTION?

  8. EXCEPTION Class Message Cause Suppressed (Java 7~)

  9. SUPPRESSED EXCEPTION

  10. WHY WE NEED ERROR- LOG AND EXCEPTION?

  11. WHY WE NEED THEM? Error log is necessary to make

    system easy to understand. Even though you don’t know internal implementations, log tells you what is problem and which action you should take.
  12. WHY WE NEED THEM? Exception is necessary to tell problem

    to your caller. If you expect caller does proper recovery, provide enough information to recover.
  13. HOW WE SHOULD USE ERROR-LOG AND EXCEPTION?

  14. TELL ENOUGH INFO Developer and system administrator want to know

    problem and next action, so log necessary information to check their usage and reproduce problem for debugging.
  15. COLLECT INFO TO ONE PLACE Even if you use two

    or more log records to tell information, developer and system administrator don’t know it and they may pick only one log record to handle problem.
  16. COLLECT INFO TO ONE PLACE Use cause and suppressed exception

    to collect related information to one place (log record), then developer and system administrator don’t lose important information.
  17. CAUTION Be careful: do not log personal and/or sensitive information

    (e.g. credit card number). Ensure that your framework logs exceptions thrown by your code, or you’ll lose valuable information. Too many log makes system really slow, costly and hard to maintain. Use proper log level to reduce needless logs.
  18. WRAP UP Error-log is for telling WHY & next ACTION

    Cause and SuppressedException help you to collect related information to one log record
  19. THANK YOU!

  20. APPENDIX: HOW TO USE LOG LEVELS?

  21. HOW TO CHOOSE LOG LEVEL debug/trace log: To debug/trace running

    system. It might affect performance of system. Basically disabled in production env but we may enable it only in specific class/package. info log: To log data which should be checked by system or administrator later. It should not affect performance of system. warn log: To tell minor problem to system and/or administrator. The definition of ‘minor’ depends on development policy or log monitoring policy. error log: To tell major problem to system and/or administrator. The definition of ‘major’ depends on development policy or development policy or log monitoring policy. fatal log: To tell severe problem to system and/or administrator. The definition of ‘severe’ depends on development policy or log monitoring policy. Really complex and many ‘it depends’
  22. KEY POINTS Is your information for system administrator (including log

    collector)? Then use INFO, WARN, ERROR or FATAL. Others are only for developers. Understand your policy to monitor logs, then you will find proper level for your log. If you have no policy to decide log level yet, refer Log4j’s definition for each levels.