astilog

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2019 License: MIT Imports: 16 Imported by: 0

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

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

func ContextWithFields

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

func Debug

func Debug(v ...interface{})

Global logger shortcuts

func DebugC

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

func DebugCf

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

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

func ErrorCf

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

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

func FatalCf

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

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

func InfoCf

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 SetLogger

func SetLogger(l Logger)

SetLogger sets the global logger

func Warn

func Warn(v ...interface{})

func WarnC

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

func WarnCf

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

func Warnf

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

func WithField

func WithField(k, v string)

func WithFields

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

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

func (*Logrus) DebugC

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

func (*Logrus) DebugCf

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

func (*Logrus) Debugf

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

func (*Logrus) Error

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

func (*Logrus) ErrorC

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

func (*Logrus) ErrorCf

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

func (*Logrus) Errorf

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

func (*Logrus) Fatal

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

func (*Logrus) FatalC

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

func (*Logrus) FatalCf

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

func (*Logrus) Fatalf

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

func (*Logrus) Info

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

func (*Logrus) InfoC

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

func (*Logrus) InfoCf

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

func (*Logrus) Infof

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

func (*Logrus) Warn

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

func (*Logrus) WarnC

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

func (*Logrus) WarnCf

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

func (*Logrus) Warnf

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

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

type Writer

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

Writer represents an object capable of writing to the logger

func NewWriter

func NewWriter(fs ...WriterFunc) *Writer

NewWriter creates a new writer

func (*Writer) Close

func (w *Writer) Close() error

Close closes the writer

func (*Writer) Write

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

Write implements the io.Writer interface

type WriterFunc

type WriterFunc func(text string)

WriterFunc represents a writer func

func LoggerFuncToWriterFunc

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