Documentation ¶
Overview ¶
Package diary provides a simple JSON logger.
Index ¶
- Constants
- Variables
- func Debug(msg string, context ...Context)
- func Error(msg string, err error, context ...Context)
- func Fatal(msg string, err error, context ...Context)
- func Info(msg string, context ...Context)
- func SetCallerKey(key string) func(*Logger) error
- func SetCallerSkip(i int) func(*Logger) error
- func SetContext(ctx Context) func(*Logger) error
- func SetErrorKey(key string) func(*Logger) error
- func SetLevel(lvl Level) func(*Logger) error
- func SetLevelKey(key string) func(*Logger) error
- func SetMessageKey(key string) func(*Logger) error
- func SetTimeKey(key string) func(*Logger) error
- func SetWriter(w io.Writer) func(*Logger) error
- type Call
- type Context
- type Level
- type Logger
- func (l *Logger) Debug(msg string, context ...Context)
- func (l *Logger) Error(msg string, err error, context ...Context)
- func (l *Logger) Fatal(msg string, err error, context ...Context)
- func (l *Logger) Info(msg string, context ...Context)
- func (l *Logger) New(context Context, options ...OptionsFunc) (*Logger, error)
- type OptionsFunc
- type Value
Constants ¶
const ( DefaultTimeKey = "ts" DefaultLevelKey = "lvl" DefaultMessageKey = "message" DefaultCallerKey = "caller" DefaultErrorKey = "error" DefaultCallerSkip = 2 )
Default keys for log output
const ( LevelFatal = iota LevelError LevelInfo LevelDebug )
Log Levels
Variables ¶
var ErrNoFunc = errors.New("no call stack information")
ErrNoFunc means that the Call has a nil *runtime.Func. The most likely cause is a Call with the zero value.
Functions ¶
func Fatal ¶
Fatal uses the default logger to log a message at the "fatal" log level. It then calls os.Exit
func SetCallerKey ¶
SetCallerKey creates a function that will set the caller key. Generally, used when create a new logger.
func SetCallerSkip ¶
SetCallerSkip creates a function that will set the caller stack skip. Generally, used when create a new logger. This can be used if you call the logger fromyour own utility function but want the caller info for the caller of your own utility function rather than the utility function.
func SetContext ¶
SetContext creates a function that sets the context. Generally, used when create a new logger.
func SetErrorKey ¶
SetErrorKey creates a function that will set the error key. Generally, used when create a new logger.
func SetLevel ¶
SetLevel creates a function that sets the log level. Generally, used when create a new logger.
func SetLevelKey ¶
SetLevelKey creates a funtion that sets the level key. Generally, used when create a new logger.
func SetMessageKey ¶
SetMessageKey creates a funtion that sets the message key. Generally, used when create a new logger.
func SetTimeKey ¶
SetTimeKey creates a funtion that sets the time key. Generally, used when create a new logger.
Types ¶
type Call ¶
type Call struct {
// contains filtered or unexported fields
}
Call records a single function invocation from a goroutine stack.
func (Call) Format ¶
Format implements fmt.Formatter with support for the following verbs.
%s source file %d line number %n function name %v equivalent to %s:%d
It accepts the '+' and '#' flags for most of the verbs as follows.
%+s path of source file relative to the compile time GOPATH %#s full path of source file %+n import path qualified function name %+v equivalent to %+s:%d %#v equivalent to %#s:%d
func (Call) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It formats the Call the same as fmt.Sprintf("%v", c).
type Context ¶
type Context map[string]interface{}
Context is a map of key/value pairs. These are Marshalled and included in the log output.
type Level ¶
type Level int
Level is the level of the log entry
func LevelFromString ¶
LevelFromString returns the appropriate Level from a string name. Useful for parsing command line args and configuration files.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the actual logger. The default log level is debug and the default writer is STDOUT.
func GetDefaultLogger ¶
func GetDefaultLogger() *Logger
GetDefaultLogger returns a Logger with the default settings
type OptionsFunc ¶
OptionsFunc is a function passed to new for setting options on a new logger.