xlog

package module
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: BSD-3-Clause Imports: 14 Imported by: 7

README

xlog

Go Reference

Package xlog provides leveled and structured logging. Please see godoc.

Examples

To run any example, please use the command like the following:

cd examples/
go run example1.go

Tests

To run all tests, please use the following command:

go test -v

To run all examples, please use the following command:

go test -v -run=^Example

To run all benchmarks, please use the following command:

go test -v -run=^Benchmark -bench=.

Documentation

Overview

Package xlog provides leveled and structured logging.

Example
package main

import (
	"os"
	"time"

	"github.com/goinsane/xlog"
)

var testTime, _ = time.ParseInLocation("2006-01-02T15:04:05", "2010-11-12T13:14:15", time.Local)

func main() {
	// reset xlog for previous changes if it is running in go test.
	xlog.Reset()
	// change writer of default output to stdout from stderr.
	xlog.SetOutputWriter(os.Stdout)

	// log by Severity.
	// default severity is SeverityInfo.
	// default verbose is 0.
	xlog.Debug("this is debug log. but it won't be shown.")
	xlog.Info("this is info log.")
	xlog.Warning("this is warning log.")
	xlog.V(1).Error("this is error log, verbosity 1. but it won't be shown.")

	// SetSeverity()
	xlog.SetSeverity(xlog.SeverityDebug)
	xlog.Debug("this is debug log. it will now be shown.")

	// SetVerbose() and V()
	xlog.SetVerbose(1)
	xlog.V(1).Error("this is error log, verbosity 1. it will now be shown.")
	xlog.V(2).Warning("this is warning log, verbosity 2. it won't be shown.")

	// SetFlags()
	// default flags is FlagDefault.
	xlog.SetFlags(xlog.FlagDefault | xlog.FlagShortFile)
	xlog.Info("this is info log. you can see file name and line in this log.")

	// log using Print.
	// default print severity is SeverityInfo.
	xlog.Print("this log will be shown as info log.")

	// SetPrintSeverity()
	xlog.SetPrintSeverity(xlog.SeverityWarning)
	xlog.Print("this log will now be shown as warning log.")

	// SetStackTraceSeverity()
	// default stack trace severity is none.
	xlog.SetStackTraceSeverity(xlog.SeverityWarning)
	xlog.Warning("this is warning log. you can see stack trace end of this log.")
	xlog.Error("this is error log. you can still see stack trace end of this log.")
	xlog.Info("this is info log. stack trace won't be shown end of this log.")

	// WithPrefix()
	xlog.WithPrefix("prefix1").Warning("this is warning log with prefix 'prefix1'.")
	xlog.WithPrefix("prefix1").WithPrefix("prefix2").Error("this is error log with both of prefixes 'prefix1' and 'prefix2'.")

	// WithTime()
	xlog.WithTime(testTime).Info("this is info log with custom time.")

	// WithFieldKeyVals()
	xlog.WithFieldKeyVals("key1", "val1", "key2", "val2", "key3", "val3", "key1", "val1-2", "key2", "val2-2").Info("this is info log with several fields.")
}
Output:

Example (Test1)
package main

import (
	"os"
	"time"

	"github.com/goinsane/xlog"
)

func main() {
	// reset xlog for previous changes if it is running in go test.
	xlog.Reset()
	// just show severity.
	xlog.SetFlags(xlog.FlagSeverity)
	// change writer of default output to stdout from stderr.
	xlog.SetOutputWriter(os.Stdout)

	xlog.Debug("this is debug log, verbosity 0. it will not be shown.")
	xlog.Info("this is info log, verbosity 0.")
	xlog.Warning("this is warning log, verbosity 0.")
	xlog.Error("this is error log, verbosity 0.")
	xlog.Print("this is info log, verbosity 0 caused by Print().")
	xlog.V(1).Info("this is info log, verbosity 1. it will not be shown.")

	xlog.SetSeverity(xlog.SeverityDebug)
	xlog.Debug("this is debug log, verbosity 0.")

	xlog.SetVerbose(1)
	xlog.V(0).Info("this is info log, verbosity 0.")
	xlog.V(1).Info("this is info log, verbosity 1.")
	xlog.V(2).Info("this is info log, verbosity 2. it will not be shown.")

	xlog.SetPrintSeverity(xlog.SeverityWarning)
	xlog.Print("this is warning log, verbosity 0 caused by Print().")

	xlog.Warning("this is warning log, verbosity 0.\nwithout padding.")
	xlog.SetFlags(xlog.FlagSeverity | xlog.FlagPadding)
	xlog.Warning("this is warning log, verbosity 0.\nwith padding.")

	xlog.SetFlags(xlog.FlagDefault)
	tm, _ := time.ParseInLocation("2006-01-02T15:04:05", "2019-11-13T21:56:24", time.Local)
	xlog.WithTime(tm).Info("this is info log, verbosity 0.")

}
Output:

INFO - this is info log, verbosity 0.
WARNING - this is warning log, verbosity 0.
ERROR - this is error log, verbosity 0.
INFO - this is info log, verbosity 0 caused by Print().
DEBUG - this is debug log, verbosity 0.
INFO - this is info log, verbosity 0.
INFO - this is info log, verbosity 1.
WARNING - this is warning log, verbosity 0 caused by Print().
WARNING - this is warning log, verbosity 0.
without padding.
WARNING - this is warning log, verbosity 0.
          with padding.
2019/11/13 21:56:24 INFO - this is info log, verbosity 0.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSeverity = errors.New("invalid severity")
	ErrUnknownSeverity = errors.New("unknown severity")
)

Functions

func Debug

func Debug(args ...interface{})

Debug logs to the DEBUG severity logs to the default Logger.

func Debugf

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

Debugf logs to the DEBUG severity logs to the default Logger.

func Debugln

func Debugln(args ...interface{})

Debugln logs to the DEBUG severity logs to the default Logger.

func ErfError added in v1.2.0

func ErfError(arg interface{}) *erf.Erf

ErfError creates a new *erf.Erf by the given argument. It logs to the ERROR severity logs to the default Logger and returns the new *erf.Erf.

func ErfErrorf added in v1.2.0

func ErfErrorf(format string, args ...interface{}) *loggerErfResult

ErfErrorf creates a new *erf.Erf by given arguments. It logs to the ERROR severity logs to the default Logger and the result to get the new *erf.Erf.

func ErfWarning added in v1.2.0

func ErfWarning(arg interface{}) *erf.Erf

ErfWarning creates a new *erf.Erf by the given argument. It logs to the WARNING severity logs to the default Logger and returns the new *erf.Erf.

func ErfWarningf added in v1.2.0

func ErfWarningf(format string, args ...interface{}) *loggerErfResult

ErfWarningf creates a new *erf.Erf by given arguments. It logs to the WARNING severity logs to the default Logger and returns the result to get the new *erf.Erf.

func Error

func Error(args ...interface{})

Error logs to the ERROR severity logs to the default Logger.

func Errorf

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

Errorf logs to the ERROR severity logs to the default Logger.

func Errorln

func Errorln(args ...interface{})

Errorln logs to the ERROR severity logs to the default Logger.

func Fatal

func Fatal(args ...interface{})

Fatal logs to the FATAL severity logs to the default Logger, then calls os.Exit(1).

func Fatalf

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

Fatalf logs to the FATAL severity logs to the default Logger, then calls os.Exit(1).

func Fatalln

func Fatalln(args ...interface{})

Fatalln logs to the FATAL severity logs to the default Logger, then calls os.Exit(1).

func Info

func Info(args ...interface{})

Info logs to the INFO severity logs to the default Logger.

func Infof

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

Infof logs to the INFO severity logs to the default Logger.

func Infoln

func Infoln(args ...interface{})

Infoln logs to the INFO severity logs to the default Logger.

func Print added in v0.2.0

func Print(args ...interface{})

Print logs a log which has the default Logger's print severity to the default Logger.

func Printf added in v0.2.0

func Printf(format string, args ...interface{})

Printf logs a log which has the default Logger's print severity to the default Logger.

func Println added in v0.2.0

func Println(args ...interface{})

Println logs a log which has the default Logger's print severity to the default Logger.

func Reset added in v0.2.0

func Reset()

Reset resets the default Logger and the default Output.

func Warning

func Warning(args ...interface{})

Warning logs to the WARNING severity logs to the default Logger.

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs to the WARNING severity logs to the default Logger.

func Warningln

func Warningln(args ...interface{})

Warningln logs to the WARNING severity logs to the default Logger.

Types

type Field added in v0.2.0

type Field struct {
	Key   string
	Value interface{}
	// contains filtered or unexported fields
}

Field is type of field.

func (*Field) GetMark added in v1.2.1

func (f *Field) GetMark() interface{}

type FieldMarkErf added in v1.2.0

type FieldMarkErf struct {
	No    int
	Index int
}

func (*FieldMarkErf) String added in v1.2.0

func (m *FieldMarkErf) String() string

type Fields

type Fields []Field

Fields is slice of fields.

func (Fields) Duplicate added in v1.0.1

func (f Fields) Duplicate() Fields

Duplicate duplicates the Fields.

func (Fields) Len added in v0.2.0

func (f Fields) Len() int

Len is implementation of sort.Interface.

func (Fields) Less added in v0.2.0

func (f Fields) Less(i, j int) bool

Less is implementation of sort.Interface.

func (Fields) Swap added in v0.2.0

func (f Fields) Swap(i, j int)

Swap is implementation of sort.Interface.

type Flag added in v1.0.1

type Flag int

Flag holds single or multiple flags of Log. An Output instance uses these flags which are stored by Flag type.

const (
	// FlagDate prints the date in the local time zone: 2009/01/23
	FlagDate Flag = 1 << iota

	// FlagTime prints the time in the local time zone: 01:23:23
	FlagTime

	// FlagMicroseconds prints microsecond resolution: 01:23:23.123123
	FlagMicroseconds

	// FlagUTC uses UTC rather than the local time zone
	FlagUTC

	// FlagSeverity prints severity level
	FlagSeverity

	// FlagPadding prints padding with multiple lines
	FlagPadding

	// FlagLongFunc prints full package name and function name: a/b/c/d.Func1()
	FlagLongFunc

	// FlagShortFunc prints final package name and function name: d.Func1()
	FlagShortFunc

	// FlagLongFile prints full file name and line number: a/b/c/d.go:23
	FlagLongFile

	// FlagShortFile prints final file name element and line number: d.go:23
	FlagShortFile

	// FlagFields prints fields if there are
	FlagFields

	// FlagStackTrace prints the stack trace if there is
	FlagStackTrace

	// FlagErfStackTrace prints the stack trace of the erf error if there is the erf error
	FlagErfStackTrace

	// FlagErfMessage prints the message of the erf error while printing the erf stack trace
	FlagErfMessage

	// FlagErfFields prints fields of the erf error while printing the erf stack trace
	FlagErfFields

	// FlagDefault holds initial flags for the Logger
	FlagDefault = FlagDate | FlagTime | FlagSeverity | FlagPadding | FlagFields | FlagStackTrace | FlagErfStackTrace
)

type Log added in v1.0.1

type Log struct {
	Message     []byte
	Error       error
	Severity    Severity
	Verbosity   Verbose
	Time        time.Time
	Fields      Fields
	StackCaller erf.StackCaller
	StackTrace  *erf.StackTrace
	Flags       Flag
}

Log carries the log.

func (*Log) Duplicate added in v1.0.1

func (l *Log) Duplicate() *Log

Duplicate duplicates the Log.

func (*Log) Format added in v1.0.1

func (l *Log) Format(f fmt.State, verb rune)

Format is implementation of fmt.Formatter.

func (*Log) MarshalText added in v1.0.1

func (l *Log) MarshalText() (text []byte, err error)

MarshalText is implementation of encoding.TextMarshaler.

func (*Log) String added in v1.0.1

func (l *Log) String() string

String is implementation of fmt.Stringer.

type Logger

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

Logger provides a logger for leveled and structured logging.

Example
package main

import (
	"os"

	"github.com/goinsane/xlog"
)

func main() {
	logger := xlog.New(xlog.NewTextOutput(os.Stdout), xlog.SeverityInfo, 2)
	logger.SetFlags(xlog.FlagSeverity)

	logger.Info("this is info log, verbosity 0.")
	logger.V(0).Info("this is info log, verbosity 0.")
	logger.V(1).Warning("this is warning log, verbosity 1.")
	logger.V(2).Error("this is error log, verbosity 2.")
	logger.V(3).Error("this is error log, verbosity 3. it won't be shown.")
	logger.Debug("this is debug log, verbosity 0. it won't be shown.")

}
Output:

INFO - this is info log, verbosity 0.
INFO - this is info log, verbosity 0.
WARNING - this is warning log, verbosity 1.
ERROR - this is error log, verbosity 2.

func DefaultLogger added in v0.2.0

func DefaultLogger() *Logger

DefaultLogger returns the default Logger.

func New

func New(output Output, severity Severity, verbose Verbose) *Logger

New creates a new Logger. If severity is invalid, it sets SeverityInfo.

func SetFlags added in v1.0.1

func SetFlags(flags Flag) *Logger

SetFlags sets flags of Log created by the default Logger. These flags don't affect the default Logger. The Logger set them directly into the Log. It returns the default Logger. By default, FlagDefault.

Example
package main

import (
	"os"

	"github.com/goinsane/xlog"
)

// resetForTest resets xlog to run new test.
func resetForTest() {
	xlog.Reset()
	xlog.SetFlags(xlog.FlagDefault & ^xlog.FlagDate & ^xlog.FlagTime & ^xlog.FlagStackTrace)
	xlog.SetOutputWriter(os.Stdout)
}

func main() {
	resetForTest()
	xlog.SetFlags(0)
	xlog.Info("this is info log, verbosity 0.")

}
Output:

this is info log, verbosity 0.

func SetOutput

func SetOutput(output Output) *Logger

SetOutput sets the default Logger's output. It returns the default Logger. By default, the default Output.

func SetPrintSeverity added in v0.2.0

func SetPrintSeverity(printSeverity Severity) *Logger

SetPrintSeverity sets the default Logger's severity level which is using with Print methods. If printSeverity is invalid, it sets SeverityInfo. It returns the default Logger. By default, SeverityInfo.

func SetSeverity

func SetSeverity(severity Severity) *Logger

SetSeverity sets the default Logger's severity. If severity is invalid, it sets SeverityInfo. It returns the default Logger. By default, SeverityInfo.

Example
package main

import (
	"os"

	"github.com/goinsane/xlog"
)

// resetForTest resets xlog to run new test.
func resetForTest() {
	xlog.Reset()
	xlog.SetFlags(xlog.FlagDefault & ^xlog.FlagDate & ^xlog.FlagTime & ^xlog.FlagStackTrace)
	xlog.SetOutputWriter(os.Stdout)
}

func main() {
	resetForTest()
	xlog.SetSeverity(xlog.SeverityDebug)
	xlog.Debug("this is debug log, verbosity 0.")
	xlog.Info("this is info log, verbosity 0.")
	xlog.Warning("this is warning log, verbosity 0.")

}
Output:

DEBUG - this is debug log, verbosity 0.
INFO - this is info log, verbosity 0.
WARNING - this is warning log, verbosity 0.

func SetStackTraceSeverity added in v0.2.0

func SetStackTraceSeverity(stackTraceSeverity Severity) *Logger

SetStackTraceSeverity sets the default Logger's severity level which saves stack trace into Log. If stackTraceSeverity is invalid, it sets SeverityNone. It returns the default Logger. By default, SeverityNone.

func SetVerbose

func SetVerbose(verbose Verbose) *Logger

SetVerbose sets the default Logger's verbose. It returns the default Logger. By default, 0.

Example
package main

import (
	"os"

	"github.com/goinsane/xlog"
)

// resetForTest resets xlog to run new test.
func resetForTest() {
	xlog.Reset()
	xlog.SetFlags(xlog.FlagDefault & ^xlog.FlagDate & ^xlog.FlagTime & ^xlog.FlagStackTrace)
	xlog.SetOutputWriter(os.Stdout)
}

func main() {
	resetForTest()
	xlog.SetVerbose(2)
	xlog.V(0).Debug("this is debug log, verbosity 0. it won't be shown.")
	xlog.V(1).Info("this is info log, verbosity 1.")
	xlog.V(2).Warning("this is warning log, verbosity 2.")
	xlog.V(3).Error("this is error log, verbosity 3. it won't be shown.")

}
Output:

INFO - this is info log, verbosity 1.
WARNING - this is warning log, verbosity 2.

func V

func V(verbosity Verbose) *Logger

V duplicates the default Logger if the default Logger's verbose is greater or equal to given verbosity, otherwise returns nil.

func WithFieldKeyVals added in v0.2.0

func WithFieldKeyVals(kvs ...interface{}) *Logger

WithFieldKeyVals duplicates the default Logger with given key and values of Field.

func WithFields

func WithFields(fields ...Field) *Logger

WithFields duplicates the default Logger with given fields.

func WithPrefix added in v0.3.0

func WithPrefix(args ...interface{}) *Logger

WithPrefix duplicates the default Logger and adds given prefix to end of the underlying prefix.

func WithPrefixf added in v0.6.0

func WithPrefixf(format string, args ...interface{}) *Logger

WithPrefixf duplicates the default Logger and adds given prefix to end of the underlying prefix.

func WithTime

func WithTime(tm time.Time) *Logger

WithTime duplicates the default Logger with given time.

Example
package main

import (
	"os"
	"time"

	"github.com/goinsane/xlog"
)

var testTime, _ = time.ParseInLocation("2006-01-02T15:04:05", "2010-11-12T13:14:15", time.Local)

// resetForTest resets xlog to run new test.
func resetForTest() {
	xlog.Reset()
	xlog.SetFlags(xlog.FlagDefault & ^xlog.FlagDate & ^xlog.FlagTime & ^xlog.FlagStackTrace)
	xlog.SetOutputWriter(os.Stdout)
}

func main() {
	resetForTest()
	xlog.SetFlags(xlog.FlagDefault)
	xlog.WithTime(testTime).Info("this is info log, verbosity 0.")

}
Output:

2010/11/12 13:14:15 INFO - this is info log, verbosity 0.

func (*Logger) Debug

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

Debug logs to the DEBUG severity logs.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf logs to the DEBUG severity logs.

func (*Logger) Debugln

func (l *Logger) Debugln(args ...interface{})

Debugln logs to the DEBUG severity logs.

func (*Logger) Duplicate added in v1.0.1

func (l *Logger) Duplicate() *Logger

Duplicate duplicates the Logger.

func (*Logger) ErfError added in v1.2.0

func (l *Logger) ErfError(arg interface{}) *erf.Erf

ErfError creates a new *erf.Erf by the given argument. It logs to the ERROR severity logs and returns the new *erf.Erf.

func (*Logger) ErfErrorf added in v1.2.0

func (l *Logger) ErfErrorf(format string, args ...interface{}) *loggerErfResult

ErfErrorf creates a new *erf.Erf by given arguments. It logs to the ERROR severity logs and returns the result to get the new *erf.Erf.

func (*Logger) ErfWarning added in v1.2.0

func (l *Logger) ErfWarning(arg interface{}) *erf.Erf

ErfWarning creates a new *erf.Erf by the given argument. It logs to the WARNING severity logs and returns the new *erf.Erf.

func (*Logger) ErfWarningf added in v1.2.0

func (l *Logger) ErfWarningf(format string, args ...interface{}) *loggerErfResult

ErfWarningf creates a new *erf.Erf by given arguments. It logs to the WARNING severity logs and returns the result to get the new *erf.Erf.

func (*Logger) Error

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

Error logs to the ERROR severity logs.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf logs to the ERROR severity logs.

func (*Logger) Errorln

func (l *Logger) Errorln(args ...interface{})

Errorln logs to the ERROR severity logs.

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

Fatal logs to the FATAL severity logs, then calls os.Exit(1).

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

Fatalf logs to the FATAL severity logs, then calls os.Exit(1).

func (*Logger) Fatalln

func (l *Logger) Fatalln(args ...interface{})

Fatalln logs to the FATAL severity logs, then calls os.Exit(1).

func (*Logger) Info

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

Info logs to the INFO severity logs.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof logs to the INFO severity logs.

func (*Logger) Infoln

func (l *Logger) Infoln(args ...interface{})

Infoln logs to the INFO severity logs.

func (*Logger) Print added in v0.2.0

func (l *Logger) Print(args ...interface{})

Print logs a log which has the Logger's print severity.

func (*Logger) Printf added in v0.2.0

func (l *Logger) Printf(format string, args ...interface{})

Printf logs a log which has the Logger's print severity.

func (*Logger) Println added in v0.2.0

func (l *Logger) Println(args ...interface{})

Println logs a log which has the Logger's print severity.

func (*Logger) SetFlags added in v1.0.1

func (l *Logger) SetFlags(flags Flag) *Logger

SetFlags sets flags of Log created by underlying Logger. These flags don't affect underlying Logger. The Logger set them directly into the Log. It returns underlying Logger. By default, FlagDefault.

func (*Logger) SetOutput

func (l *Logger) SetOutput(output Output) *Logger

SetOutput sets the Logger's output. It returns underlying Logger.

func (*Logger) SetPrintSeverity added in v0.2.0

func (l *Logger) SetPrintSeverity(printSeverity Severity) *Logger

SetPrintSeverity sets the Logger's severity level which is using with Print methods. If printSeverity is invalid, it sets SeverityInfo. It returns underlying Logger. By default, SeverityInfo.

func (*Logger) SetSeverity

func (l *Logger) SetSeverity(severity Severity) *Logger

SetSeverity sets the Logger's severity. If severity is invalid, it sets SeverityInfo. It returns underlying Logger.

func (*Logger) SetStackTraceSeverity added in v0.2.0

func (l *Logger) SetStackTraceSeverity(stackTraceSeverity Severity) *Logger

SetStackTraceSeverity sets the Logger's severity level which saves stack trace into Log. If stackTraceSeverity is invalid, it sets SeverityNone. It returns underlying Logger. By default, SeverityNone.

func (*Logger) SetVerbose

func (l *Logger) SetVerbose(verbose Verbose) *Logger

SetVerbose sets the Logger's verbose. It returns underlying Logger.

func (*Logger) V

func (l *Logger) V(verbosity Verbose) *Logger

V duplicates the Logger if the Logger's verbose is greater or equal to given verbosity, otherwise returns nil.

func (*Logger) Warning

func (l *Logger) Warning(args ...interface{})

Warning logs to the WARNING severity logs.

func (*Logger) Warningf

func (l *Logger) Warningf(format string, args ...interface{})

Warningf logs to the WARNING severity logs.

func (*Logger) Warningln

func (l *Logger) Warningln(args ...interface{})

Warningln logs to the WARNING severity logs.

func (*Logger) WithFieldKeyVals added in v0.2.0

func (l *Logger) WithFieldKeyVals(kvs ...interface{}) *Logger

WithFieldKeyVals duplicates the Logger with given key and values of Field.

func (*Logger) WithFieldMap added in v0.2.0

func (l *Logger) WithFieldMap(fieldMap map[string]interface{}) *Logger

WithFieldMap duplicates the Logger with given fieldMap.

func (*Logger) WithFields

func (l *Logger) WithFields(fields ...Field) *Logger

WithFields duplicates the Logger with given fields.

func (*Logger) WithPrefix added in v0.3.0

func (l *Logger) WithPrefix(args ...interface{}) *Logger

WithPrefix duplicates the Logger and adds given prefix to end of the underlying prefix.

func (*Logger) WithPrefixf added in v0.6.0

func (l *Logger) WithPrefixf(format string, args ...interface{}) *Logger

WithPrefixf duplicates the Logger and adds given prefix to end of the underlying prefix.

func (*Logger) WithTime

func (l *Logger) WithTime(tm time.Time) *Logger

WithTime duplicates the Logger with given time.

type Output

type Output interface {
	Log(log *Log)
}

Output is an interface for Logger output. All the Output implementations must be safe for concurrency.

func AsyncOutput added in v0.2.0

func AsyncOutput(output Output) Output

AsyncOutput creates an output that doesn't block its logs to the provided output.

func MultiOutput added in v0.2.0

func MultiOutput(outputs ...Output) Output

MultiOutput creates an output that duplicates its logs to all the provided outputs.

type QueuedOutput added in v0.2.0

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

QueuedOutput is intermediate Output implementation between Logger and given Output. QueuedOutput has queueing for unblocking Log() method.

func NewQueuedOutput added in v0.2.0

func NewQueuedOutput(output Output, queueLen int) (q *QueuedOutput)

NewQueuedOutput creates QueuedOutput by given output.

func (*QueuedOutput) Close added in v0.2.0

func (q *QueuedOutput) Close() error

Close closed QueuedOutput. Unused QueuedOutput must be closed for freeing resources.

func (*QueuedOutput) Log added in v0.2.0

func (q *QueuedOutput) Log(log *Log)

Log is implementation of Output. If blocking is true, Log method blocks execution until underlying output has finished execution. Otherwise, Log method sends log to queue if queue is available. When queue is full, it tries to call OnQueueFull function.

func (*QueuedOutput) SetBlocking added in v0.2.0

func (q *QueuedOutput) SetBlocking(blocking bool) *QueuedOutput

SetBlocking sets QueuedOutput behavior when queue is full. It returns underlying QueuedOutput.

func (*QueuedOutput) SetOnQueueFull added in v1.0.1

func (q *QueuedOutput) SetOnQueueFull(f func()) *QueuedOutput

SetOnQueueFull sets a function to call when queue is full. It returns underlying QueuedOutput.

func (*QueuedOutput) WaitForEmpty added in v0.2.0

func (q *QueuedOutput) WaitForEmpty(ctx context.Context) error

WaitForEmpty waits until queue is empty by given context.

type Severity

type Severity int

Severity describes severity level of Log.

const (
	// SeverityNone is none or unspecified severity level
	SeverityNone Severity = iota

	// SeverityFatal is fatal severity level
	SeverityFatal

	// SeverityError is error severity level
	SeverityError

	// SeverityWarning is warning severity level
	SeverityWarning

	// SeverityInfo is info severity level
	SeverityInfo

	// SeverityDebug is debug severity level
	SeverityDebug
)

func (Severity) CheckValid added in v1.0.1

func (s Severity) CheckValid() error

CheckValid returns ErrInvalidSeverity for invalid s.

func (Severity) IsValid

func (s Severity) IsValid() bool

IsValid returns whether s is valid.

func (Severity) MarshalText added in v1.0.1

func (s Severity) MarshalText() (text []byte, err error)

MarshalText is implementation of encoding.TextMarshaler. If s is invalid, it returns nil and result of Severity.CheckValid.

func (Severity) String

func (s Severity) String() string

String is implementation of fmt.Stringer.

func (*Severity) UnmarshalText added in v1.0.1

func (s *Severity) UnmarshalText(text []byte) error

UnmarshalText is implementation of encoding.UnmarshalText. If text is unknown, it returns ErrUnknownSeverity.

type TextOutput

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

TextOutput is an implementation of Output by writing texts to io.Writer w.

func DefaultOutput added in v0.2.0

func DefaultOutput() *TextOutput

DefaultOutput returns the default Output as TextOutput type.

func NewTextOutput

func NewTextOutput(w io.Writer) *TextOutput

NewTextOutput creates a new TextOutput.

func SetOutputFlags

func SetOutputFlags(flags Flag) *TextOutput

SetOutputFlags sets the default Output's flags to override every single Log.Flags if the argument flags different from 0. It returns the default Output as TextOutput type. By default, 0.

func SetOutputWriter added in v0.2.0

func SetOutputWriter(w io.Writer) *TextOutput

SetOutputWriter sets the default Output's writer. It returns the default Output as TextOutput type. By default, os.Stderr.

func (*TextOutput) Log

func (t *TextOutput) Log(log *Log)

Log is implementation of Output.

func (*TextOutput) SetFlags

func (t *TextOutput) SetFlags(flags Flag) *TextOutput

SetFlags sets flags to override every single Log.Flags if the argument flags different from 0. It returns underlying TextOutput. By default, 0.

func (*TextOutput) SetOnError added in v1.0.1

func (t *TextOutput) SetOnError(f func(error)) *TextOutput

SetOnError sets a function to call when error occurs. It returns underlying TextOutput.

func (*TextOutput) SetWriter added in v0.2.0

func (t *TextOutput) SetWriter(w io.Writer) *TextOutput

SetWriter sets writer. It returns underlying TextOutput.

type Verbose

type Verbose int

Verbose is type of verbose level.

Directories

Path Synopsis
gelfoutput module
grpclogger module

Jump to

Keyboard shortcuts

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