astilog

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2019 License: MIT Imports: 16 Imported by: 236

README

Golang logger that aims to provide a simple but complete interface for a logger.

Global or local?

Declare a global logger

// Set logger
astilog.SetLogger(astilog.New(astilog.Configuration{}))

// Use logger
astilog.Info("This is a log message")

Declare a local logger

// Create logger
l := astilog.New(astilog.Configuration{})

// Use logger
l.Info("This is a log message")

Documentation

Index

Constants

View Source
const (
	FormatJSON = "json"
	FormatText = "text"
)

Formats

View Source
const (
	OutFile   = "file"
	OutStdOut = "stdout"
	OutSyslog = "syslog"
)

Outs

Variables

View Source
var (
	AppName  = flag.String("logger-app-name", "", "the logger's app name")
	Filename = flag.String("logger-filename", "", "the logger's filename")
	Verbose  = flag.Bool("logger-verbose", false, "if true, then log level is debug")
)

Flags

Functions

func ContextWithField added in v1.1.0

func ContextWithField(parent context.Context, k string, v interface{}) context.Context

func ContextWithFields added in v1.1.0

func ContextWithFields(parent context.Context, fs Fields) context.Context

func Debug

func Debug(v ...interface{})

Global logger shortcuts

func DebugC added in v1.1.0

func DebugC(ctx context.Context, v ...interface{})

func DebugCf added in v1.1.0

func DebugCf(ctx context.Context, format string, v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Error

func Error(v ...interface{})

func ErrorC added in v1.1.0

func ErrorC(ctx context.Context, v ...interface{})

func ErrorCf added in v1.1.0

func ErrorCf(ctx context.Context, format string, v ...interface{})

func Errorf

func Errorf(format string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

func FatalC added in v1.1.0

func FatalC(ctx context.Context, v ...interface{})

func FatalCf added in v1.1.0

func FatalCf(ctx context.Context, format string, v ...interface{})

func Fatalf

func Fatalf(format string, v ...interface{})

func FlagInit

func FlagInit()

FlagInit initializes the package based on flags

func Info

func Info(v ...interface{})

func InfoC added in v1.1.0

func InfoC(ctx context.Context, v ...interface{})

func InfoCf added in v1.1.0

func InfoCf(ctx context.Context, format string, v ...interface{})

func Infof

func Infof(format string, v ...interface{})

func SetDefaultLogger

func SetDefaultLogger()

SetDefaultLogger sets the default logger

func SetHandyFlags added in v1.1.0

func SetHandyFlags()

SetHandyFlags sets handy flags

func SetLogger

func SetLogger(l Logger)

SetLogger sets the global logger

func Warn

func Warn(v ...interface{})

func WarnC added in v1.1.0

func WarnC(ctx context.Context, v ...interface{})

func WarnCf added in v1.1.0

func WarnCf(ctx context.Context, format string, v ...interface{})

func Warnf

func Warnf(format string, v ...interface{})

func WithField added in v1.1.0

func WithField(k, v string)

func WithFields added in v1.1.0

func WithFields(fs Fields)

Types

type Configuration

type Configuration struct {
	AppName          string `toml:"app_name"`
	DisableColors    bool   `toml:"disable_colors"`
	DisableTimestamp bool   `toml:"disable_timestamp"`
	Filename         string `toml:"filename"`
	FullTimestamp    bool   `toml:"full_timestamp"`
	Format           string `toml:"format"`
	MessageKey       string `toml:"message_key"`
	Out              string `toml:"out"`
	TimestampFormat  string `toml:"timestamp_format"`
	Verbose          bool   `toml:"verbose"`
}

Configuration represents the configuration of the logger

func FlagConfig

func FlagConfig() Configuration

FlagConfig generates a Configuration based on flags

type Fields

type Fields map[string]interface{}

Fields represents logger fields

type Logger

type Logger interface {
	Debug(v ...interface{})
	DebugC(ctx context.Context, v ...interface{})
	DebugCf(ctx context.Context, format string, v ...interface{})
	Debugf(format string, v ...interface{})
	Info(v ...interface{})
	InfoC(ctx context.Context, v ...interface{})
	InfoCf(ctx context.Context, format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warn(v ...interface{})
	WarnC(ctx context.Context, v ...interface{})
	WarnCf(ctx context.Context, format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Error(v ...interface{})
	ErrorC(ctx context.Context, v ...interface{})
	ErrorCf(ctx context.Context, format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Fatal(v ...interface{})
	FatalC(ctx context.Context, v ...interface{})
	FatalCf(ctx context.Context, format string, v ...interface{})
	Fatalf(format string, v ...interface{})
	WithField(k string, v interface{})
	WithFields(fs Fields)
}

Logger represents a logger

func GetLogger

func GetLogger() Logger

GetLogger returns the global logger

func New

func New(c Configuration) Logger

New creates a new Logger

func NopLogger

func NopLogger() Logger

NopLogger returns a nop logger

type LoggerSetter

type LoggerSetter interface {
	SetLogger(l Logger)
}

LoggerSetter represents a logger setter

type Logrus

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

Logrus represents a logrus logger

func (*Logrus) Debug added in v1.1.0

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

func (*Logrus) DebugC added in v1.1.0

func (l *Logrus) DebugC(ctx context.Context, v ...interface{})

func (*Logrus) DebugCf added in v1.1.0

func (l *Logrus) DebugCf(ctx context.Context, format string, v ...interface{})

func (*Logrus) Debugf added in v1.1.0

func (l *Logrus) Debugf(format string, v ...interface{})

func (*Logrus) Error added in v1.1.0

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

func (*Logrus) ErrorC added in v1.1.0

func (l *Logrus) ErrorC(ctx context.Context, v ...interface{})

func (*Logrus) ErrorCf added in v1.1.0

func (l *Logrus) ErrorCf(ctx context.Context, format string, v ...interface{})

func (*Logrus) Errorf added in v1.1.0

func (l *Logrus) Errorf(format string, v ...interface{})

func (*Logrus) Fatal added in v1.1.0

func (l *Logrus) Fatal(v ...interface{})

func (*Logrus) FatalC added in v1.1.0

func (l *Logrus) FatalC(ctx context.Context, v ...interface{})

func (*Logrus) FatalCf added in v1.1.0

func (l *Logrus) FatalCf(ctx context.Context, format string, v ...interface{})

func (*Logrus) Fatalf added in v1.1.0

func (l *Logrus) Fatalf(format string, v ...interface{})

func (*Logrus) Info added in v1.1.0

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

func (*Logrus) InfoC added in v1.1.0

func (l *Logrus) InfoC(ctx context.Context, v ...interface{})

func (*Logrus) InfoCf added in v1.1.0

func (l *Logrus) InfoCf(ctx context.Context, format string, v ...interface{})

func (*Logrus) Infof added in v1.1.0

func (l *Logrus) Infof(format string, v ...interface{})

func (*Logrus) Warn added in v1.1.0

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

func (*Logrus) WarnC added in v1.1.0

func (l *Logrus) WarnC(ctx context.Context, v ...interface{})

func (*Logrus) WarnCf added in v1.1.0

func (l *Logrus) WarnCf(ctx context.Context, format string, v ...interface{})

func (*Logrus) Warnf added in v1.1.0

func (l *Logrus) Warnf(format string, v ...interface{})

func (*Logrus) WithField

func (l *Logrus) WithField(k string, v interface{})

func (*Logrus) WithFields

func (l *Logrus) WithFields(fs Fields)

func (*Logrus) Write added in v1.1.0

func (l *Logrus) Write(b []byte) (n int, err error)

type Writer added in v1.1.0

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

Writer represents an object capable of writing to the logger

func NewWriter added in v1.1.0

func NewWriter(fs ...WriterFunc) *Writer

NewWriter creates a new writer

func (*Writer) Close added in v1.1.0

func (w *Writer) Close() error

Close closes the writer

func (*Writer) Write added in v1.1.0

func (w *Writer) Write(i []byte) (n int, err error)

Write implements the io.Writer interface

type WriterFunc added in v1.1.0

type WriterFunc func(text string)

WriterFunc represents a writer func

func LoggerFuncToWriterFunc added in v1.1.0

func LoggerFuncToWriterFunc(fn func(args ...interface{})) WriterFunc

LoggerFuncToWriterFunc converts a logger func to a writer func

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL