Skip to content

Logging

disksing edited this page Dec 13, 2021 · 4 revisions

Logging

client-go uses pingcap/log for logging messages. pingcap/log internall adopts go.uber.org/zap as the logging framework.

pingcap/log provides a set of global methods for configuring loggers. The easiest way is to create a logger with the InitLogger function, and then use ReplaceGlobals() to set the logger as a global logger.

client-go also supports passing a logger through context. It also exports a handy function tikv.WithLogContext() that can be used to set the logger in a context.

Session ID

In common usage, code that calls the client-go interface may have different contexts, such as different connections or different users. A common requirement is the need for client-go to identify different contexts in the log to help troubleshoot problems. This requirement can also be achieved by passing additional information through the context. Using the util.SetSessionID function, we can pass a session id of type uint64 to client-go. client-go will record this session id in the logs.

Clone this wiki locally