Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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.

Kengo TODA

May 21, 2016
Tweet

More Decks by Kengo TODA

Other Decks in Technology

Transcript

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

    View full-size slide

  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?

    View full-size slide

  3. WHAT IS ERROR-LOG?

    View full-size slide

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

    View full-size slide

  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()){…}

    View full-size slide

  6. LOG (SLF4J) WITH EXCEPTION

    View full-size slide

  7. WHAT IS EXCEPTION?

    View full-size slide

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

    View full-size slide

  9. SUPPRESSED EXCEPTION

    View full-size slide

  10. WHY WE NEED ERROR-
    LOG AND EXCEPTION?

    View full-size slide

  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.

    View full-size slide

  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.

    View full-size slide

  13. HOW WE SHOULD USE
    ERROR-LOG AND EXCEPTION?

    View full-size slide

  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.

    View full-size slide

  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.

    View full-size slide

  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.

    View full-size slide

  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.

    View full-size slide

  18. WRAP UP
    Error-log is for telling WHY & next ACTION
    Cause and SuppressedException help you to
    collect related information to one log record

    View full-size slide

  19. APPENDIX: HOW TO
    USE LOG LEVELS?

    View full-size slide

  20. 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’

    View full-size slide

  21. 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.

    View full-size slide