Skip to content

Logging

Seulgi Kim edited this page Apr 2, 2019 · 8 revisions

Logging

$ RUST_LOG="debug" codechain

$ RUST_LOG="tx=trace,sync=info" codechain

Log Level

CodeChain has five log level, error, warn, info, debug and trace.

The error level represents the event something can be dangerous, but it can still run. In the case that cannot run anymore, it must crash ASAP instead of logging.

The warn level represents the event that is potentially dangerous.

The info level represents the event that is not dangerous, but it's useful to know for users.

The debug level represents the event that is useful for developers not for users.

codechain-logger

macros

CodeChain has the macro for designated log targets, cerror, cwarn, cinfo, cdebug and ctrace. These macros are designed for the designated targets.

How to Add a New Target

The available targets are described in log_target. You must add a new mapping to add a new target.

(TARGET_ID_IN_CODE) => {
    "target_name_in_logger"
};

The TARGET_ID_IN_CODE is the identifier that will be used by macros. If you add the mapping as above, you can use the logging macro like cwarn(TARGET_ID_IN_CODE, "message to be logged");.