Documentation ¶
Overview ¶
Package logger provides logging wrappers
These wrappers allow us to standardize logging while still using a third-party logging package.
This package is currently implemented on top of the sirupsen/logrus package:
https://github.com/sirupsen/logrus
The APIs here add package and calling function to all logs.
Where possible, fields passed to logs are parameterized, to standardize log formatting to make log searches based on these fields easier.
Logging of trace and debug logs are enabled/disabled on a per package basis.
Index ¶
- Constants
- func AddLogTarget(writer io.Writer)
- func DebugID(id string, args ...interface{})
- func DebugfID(id string, format string, args ...interface{})
- func DebugfIDWithError(id string, err error, format string, args ...interface{})
- func DebugfIDWithTxnID(id string, transIDStr string, format string, args ...interface{})
- func Down(confMap conf.ConfMap) (err error)
- func Error(args ...interface{})
- func ErrorWithError(err error, args ...interface{})
- func Errorf(format string, args ...interface{})
- func ErrorfWithError(err error, format string, args ...interface{})
- func ErrorfWithErrorTxnID(err error, transIDStr string, format string, args ...interface{})
- func FatalWithError(err error, args ...interface{})
- func Fatalf(format string, args ...interface{})
- func FatalfWithError(err error, format string, args ...interface{})
- func Info(args ...interface{})
- func InfoWithError(err error, args ...interface{})
- func Infof(format string, args ...interface{})
- func InfofWithError(err error, format string, args ...interface{})
- func InfofWithErrorTxnID(err error, transIDStr string, format string, args ...interface{})
- func PanicfWithError(err error, format string, args ...interface{})
- func ParseLogEntry(entry string) (map[string]string, error)
- func ParseLogForFunc(logcopy LogTarget, funcName string, logEntryRE *regexp.Regexp, maxEntries int) (fields map[string]string, entryIdx int, err error)
- func SignaledFinish(confMap conf.ConfMap) (err error)
- func SignaledStart(confMap conf.ConfMap) (err error)
- func TraceWithError(err error, args ...interface{})
- func Tracef(format string, args ...interface{})
- func TracefWithError(err error, format string, args ...interface{})
- func Up(confMap conf.ConfMap) (err error)
- func WarnWithError(err error, args ...interface{})
- func Warnf(format string, args ...interface{})
- func WarnfWithError(err error, format string, args ...interface{})
- type FuncCtx
- type Level
- type LogBuffer
- type LogTarget
Constants ¶
const DbgInodeInternal string = "debug_inode_internal"
packageDebugSettings controls which debug logs are enabled for particular packages.
If a package is in this map, then debug logging for that package is considered to be enabled for debug tags in the package's map entry. If a debug log's tag is NOT in this list, OR if the package is not in the map, debug logs for that package will NOT be emitted.
Unlike trace settings, debug settings are stored as a list of enabled debug tags. Bear in mind that these tags are evaluated on a package + tag basis, so the same tag can be used on different packages without conflict.
const DbgInternal string = "debug_internal"
const DbgTesting string = "debug_test"
Variables ¶
This section is empty.
Functions ¶
func AddLogTarget ¶
Add another target for log messages to be written to. writer is an object with an io.Writer interface that's called once for each log message.
Logger.Up() must be called before this function is used.
func DebugfIDWithError ¶
func DebugfIDWithTxnID ¶
func ErrorWithError ¶
func ErrorWithError(err error, args ...interface{})
func ErrorfWithError ¶
func ErrorfWithErrorTxnID ¶
func FatalWithError ¶
func FatalWithError(err error, args ...interface{})
func FatalfWithError ¶
func InfoWithError ¶
func InfoWithError(err error, args ...interface{})
func InfofWithError ¶
func InfofWithErrorTxnID ¶
func PanicfWithError ¶
func ParseLogEntry ¶
Given a log entry captured by LogTarget (above) parse out the various fields and return them as a map.
The fields parsed are "time", "level", "msg", "error", "function", "goroutine", and "package". Not all fields are present in every message, in which case the field name is not a key in the map.
func ParseLogForFunc ¶
func ParseLogForFunc(logcopy LogTarget, funcName string, logEntryRE *regexp.Regexp, maxEntries int) (fields map[string]string, entryIdx int, err error)
Parse the log entries, starting with the most recent, looking for a message generated by a function named funcName and a "msg=" that matches the regular expression logEntryRE, within the most recent maxEntries lines of the log.
If found, return the parsed fields from the log message, which are a combination of the fields returned by ParseLogEntry() and the fields in the passed regular expression (which must use names for the matching parts). funcName must match the contents of the field "function" returned by ParseLogEntry(). entryIdx is the index of the entry in the log with 0 being the most recent.
If not found, return an error.
Example: logEntryRE can be very simple, but here is a complicated one from trackedlock/api_test.go that matches the following message (where "\n" in the message represents embededded newlines).
msg="trackedlock watcher: *trackedlock.Mutex at 0xc420110000 locked for 2.0 sec; stack at Lock() call:\ngoroutine 19 [running]:..."
logEntryRe is `^trackedlock watcher: (?P<type>[*a-zA-Z0-9_.]+) at (?P<ptr>0x[0-9a-f]+) locked for (?P<time>[0-9.]+) sec rank 0; stack at call to (?P<locker>[a-zA-Z0-9_()]+):\\n(?P<lockStack>.*)$`
func SignaledFinish ¶
func SignaledStart ¶
func TraceWithError ¶
func TraceWithError(err error, args ...interface{})
func TracefWithError ¶
func WarnWithError ¶
func WarnWithError(err error, args ...interface{})
func WarnfWithError ¶
Types ¶
type FuncCtx ¶
type FuncCtx struct {
// contains filtered or unexported fields
}
This struct is an optimization so that package and function are only extracted once per function.
func TraceEnter ¶
func (*FuncCtx) TraceExit ¶
TraceExit generates a function exit trace with the provided parameters, and using the package and function set in FuncCtx (if set).
The implementation of this function assumes that it will be called deferred. This assumption only matters in the case where this API is called without having called TraceEnter* first, since that is the only case where this function will attempt to determine the calling function.
func (*FuncCtx) TraceExitErr ¶
type Level ¶
type Level int
const ( // PanicLevel corresponds to logrus.PanicLevel; Logrus will log and then call panic with the log message PanicLevel Level = iota // FatalLevel corresponds to logrus.FatalLevel; Logrus will log and then calls `os.Exit(1)`. // It will exit even if the logging level is set to Panic. FatalLevel // ErrorLevel corresponds to logrus.ErrorLevel ErrorLevel // WarnLevel corresponds to logrus.WarnLevel WarnLevel // InfoLevel corresponds to logrus.InfoLevel; These are general operational entries about what's going on inside the application. InfoLevel // TraceLevel is used for operational logs that trace success path through the application. // Whether these are logged is controlled on a per-package basis by settings in this file. // When enabled, these are logged at logrus.InfoLevel. TraceLevel // DebugLevel is used for very verbose logging, intended to debug internal operations of a // particular area. Whether these are logged is controlled on a per-package basis by settings // in this file. // When enabled, these are logged at logrus.DebugLevel. DebugLevel )
Our logging levels - These are the different logging levels supported by this package.
We have more detailed logging levels than the logrus log package. As a result, when we do our logging we need to map from our levels to the logrus ones before calling logrus APIs.
type LogBuffer ¶
type LogBuffer struct { sync.Mutex LogEntries []string // most recent log entry is [0] TotalEntries int // count of all entries seen }
An example of a log target that captures the most recent n lines of log into an array. Useful for writing test cases.
There should really be a lock or clever RCU mechanism to coordinate access/updates to the array, but its not really necessary for test case code (and adds overhead).