Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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?

Slide 3

Slide 3 text

WHAT IS ERROR-LOG?

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

LOG (SLF4J) WITH EXCEPTION

Slide 7

Slide 7 text

WHAT IS EXCEPTION?

Slide 8

Slide 8 text

EXCEPTION Class Message Cause Suppressed (Java 7~)

Slide 9

Slide 9 text

SUPPRESSED EXCEPTION

Slide 10

Slide 10 text

WHY WE NEED ERROR- LOG AND EXCEPTION?

Slide 11

Slide 11 text

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.

Slide 12

Slide 12 text

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.

Slide 13

Slide 13 text

HOW WE SHOULD USE ERROR-LOG AND EXCEPTION?

Slide 14

Slide 14 text

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.

Slide 15

Slide 15 text

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.

Slide 16

Slide 16 text

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.

Slide 17

Slide 17 text

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.

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

THANK YOU!

Slide 20

Slide 20 text

APPENDIX: HOW TO USE LOG LEVELS?

Slide 21

Slide 21 text

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’

Slide 22

Slide 22 text

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.