README

LogC

A common and universal logging interface that every package in the simple frameworks org uses.

test status

Adapters to common logging libraries are provided so whatever logging library that you decide to use can be supported.


type Logger interface {
	Trace(args ...interface{})
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	WithField(key string, value interface{}) Logger
	WithFields(fields map[string]interface{}) Logger
	WithError(err error) Logger
}

Using with logrus


log = logc.NewLogrus(logrus.New())

log.Trace("some Trace log")
log.Debug("some Debug log")
log.Info("some Info log")
log.Warn("some Warn log")
log.Error("some Error log")


log.WithField("RequestID",1234).Trace("some Trace log")


log.WithFields(map[string]interface{}{
  "RequestID":  1234,
  "Name":       "SomeName",
}).Info("some Info log")


someError := errors.New("an error occurred")
log.WithError(someError).Error("some Error log")


Currently only logrus is supported but more packages are planned.

Documentation

Overview

Example (Logger)
logrusLog := logrus.New()
logrusLog.SetOutput(os.Stdout)
logrusLog.SetFormatter(&logrus.TextFormatter{
	DisableColors:    true,
	DisableTimestamp: true,
})

log := NewLogrus(logrusLog)

log.Trace("some Trace log")
log.Debug("some Debug log")
log.Info("some Info log")
log.Warn("some Warn log")
log.Error("some Error log")

log.WithField("RequestID", 1234).Trace("some Trace log")

log.WithFields(map[string]interface{}{
	"RequestID": 1234,
	"Name":      "SomeName",
}).Info("some Info log")

someError := errors.New("an error occurred")
log.WithError(someError).Error("some Error log")
Output:

level=info msg="some Info log"
level=warning msg="some Warn log"
level=error msg="some Error log"
level=info msg="some Info log" Name=SomeName RequestID=1234
level=error msg="some Error log" error="an error occurred"

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GormLogger

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

GormLogger .

func NewGormLogger

func NewGormLogger(logger Logger) *GormLogger

NewGormLogger .

func (*GormLogger) Error

func (l *GormLogger) Error(ctx context.Context, s string, args ...interface{})

Error .

func (*GormLogger) Info

func (l *GormLogger) Info(ctx context.Context, s string, args ...interface{})

Info .

func (*GormLogger) LogMode

LogMode .

func (*GormLogger) Trace

func (l *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace .

func (*GormLogger) Warn

func (l *GormLogger) Warn(ctx context.Context, s string, args ...interface{})

Warn .

type Logger

type Logger interface {
	Trace(args ...interface{})
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	WithField(key string, value interface{}) Logger
	WithFields(fields map[string]interface{}) Logger
	WithError(err error) Logger
}

Logger is a basic logging interface

func NewLogrus

func NewLogrus(logger *logrus.Logger) Logger

NewLogrus compatible logger

func NewLogrusEntry

func NewLogrusEntry(entry *logrus.Entry) Logger

NewLogrusEntry compatible logger

type Logrus

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

Logrus compatible wrapper for the logger interface

func (*Logrus) Debug

func (l *Logrus) Debug(args ...interface{})

Debug .

func (*Logrus) Error

func (l *Logrus) Error(args ...interface{})

Error .

func (*Logrus) Info

func (l *Logrus) Info(args ...interface{})

Info .

func (*Logrus) Trace

func (l *Logrus) Trace(args ...interface{})

Trace .

func (*Logrus) Warn

func (l *Logrus) Warn(args ...interface{})

Warn .

func (*Logrus) WithError

func (l *Logrus) WithError(err error) Logger

WithError .

func (*Logrus) WithField

func (l *Logrus) WithField(key string, value interface{}) Logger

WithField .

func (*Logrus) WithFields

func (l *Logrus) WithFields(fields map[string]interface{}) Logger

WithFields .