diary: github.com/bakins/diary Index | Files

package diary

import "github.com/bakins/diary"

Package diary provides a simple JSON logger.

Index

Package Files

diary.go stack.go

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.

func Debug Uses

func Debug(msg string, context ...Context)

Debug uses the default logger to log a message at the "debug" log level.

func Error Uses

func Error(msg string, err error, context ...Context)

Error uses the default logger to log a message at the "error" log level.

func Fatal Uses

func Fatal(msg string, err error, context ...Context)

Fatal uses the default logger to log a message at the "fatal" log level. It then calls os.Exit

func Info Uses

func Info(msg string, context ...Context)

Info uses the default logger to log a message at the "info" log level.

func SetCallerKey Uses

func SetCallerKey(key string) func(*Logger) error

SetCallerKey creates a function that will set the caller key. Generally, used when create a new logger.

func SetCallerSkip Uses

func SetCallerSkip(i int) func(*Logger) error

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 Uses

func SetContext(ctx Context) func(*Logger) error

SetContext creates a function that sets the context. Generally, used when create a new logger.

func SetErrorKey Uses

func SetErrorKey(key string) func(*Logger) error

SetErrorKey creates a function that will set the error key. Generally, used when create a new logger.

func SetLevel Uses

func SetLevel(lvl Level) func(*Logger) error

SetLevel creates a function that sets the log level. Generally, used when create a new logger.

func SetLevelKey Uses

func SetLevelKey(key string) func(*Logger) error

SetLevelKey creates a funtion that sets the level key. Generally, used when create a new logger.

func SetMessageKey Uses

func SetMessageKey(key string) func(*Logger) error

SetMessageKey creates a funtion that sets the message key. Generally, used when create a new logger.

func SetTimeKey Uses

func SetTimeKey(key string) func(*Logger) error

SetTimeKey creates a funtion that sets the time key. Generally, used when create a new logger.

func SetWriter Uses

func SetWriter(w io.Writer) func(*Logger) error

SetWriter creates a function that will set the writer. Generally, used when create a new logger.

type Call Uses

type Call struct {
    // contains filtered or unexported fields
}

Call records a single function invocation from a goroutine stack.

func (Call) Format Uses

func (c Call) Format(s fmt.State, verb rune)

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 Uses

func (c Call) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It formats the Call the same as fmt.Sprintf("%v", c).

func (Call) String Uses

func (c Call) String() string

String implements fmt.Stinger. It is equivalent to fmt.Sprintf("%v", c).

type Context Uses

type Context map[string]interface{}

Context is a map of key/value pairs. These are Marshalled and included in the log output.

type Level Uses

type Level int

Level is the level of the log entry

func LevelFromString Uses

func LevelFromString(levelString string) (Level, error)

LevelFromString returns the appropriate Level from a string name. Useful for parsing command line args and configuration files.

func (Level) String Uses

func (l Level) String() string

String returns the name of a Level.

type Logger Uses

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 Uses

func GetDefaultLogger() *Logger

GetDefaultLogger returns a Logger with the default settings

func New Uses

func New(context Context, options ...OptionsFunc) (*Logger, error)

New creates a logger.

func (*Logger) Debug Uses

func (l *Logger) Debug(msg string, context ...Context)

Debug logs a message at the "debug" log level.

func (*Logger) Error Uses

func (l *Logger) Error(msg string, err error, context ...Context)

Error logs a message at the "error" log level.

func (*Logger) Fatal Uses

func (l *Logger) Fatal(msg string, err error, context ...Context)

Fatal logs a message at the "fatal" log level. It then calls os.Exit

func (*Logger) Info Uses

func (l *Logger) Info(msg string, context ...Context)

Info logs a message at the "info" log level.

func (*Logger) New Uses

func (l *Logger) New(context Context, options ...OptionsFunc) (*Logger, error)

New creates a copy of the logger with additional options. Initial options are inherited from the original. The two loggers are independent.

type OptionsFunc Uses

type OptionsFunc func(*Logger) error

OptionsFunc is a function passed to new for setting options on a new logger.

type Value Uses

type Value struct {
    Func interface{}
}

A Value generates a log value. It represents a dynamic value which is re-evaluated with each log event.

func (Value) MarshalJSON Uses

func (v Value) MarshalJSON() ([]byte, error)

Package diary imports 11 packages (graph). Updated 2016-09-09. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).