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 ¶
- Variables
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func ErfError(arg interface{}) *erf.Erf
- func ErfErrorf(format string, args ...interface{}) *loggerErfResult
- func ErfWarning(arg interface{}) *erf.Erf
- func ErfWarningf(format string, args ...interface{}) *loggerErfResult
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func Reset()
- func Warning(args ...interface{})
- func Warningf(format string, args ...interface{})
- func Warningln(args ...interface{})
- type Field
- type FieldMarkErf
- type Fields
- type Flag
- type Log
- type Logger
- func DefaultLogger() *Logger
- func New(output Output, severity Severity, verbose Verbose) *Logger
- func SetFlags(flags Flag) *Logger
- func SetOutput(output Output) *Logger
- func SetPrintSeverity(printSeverity Severity) *Logger
- func SetSeverity(severity Severity) *Logger
- func SetStackTraceSeverity(stackTraceSeverity Severity) *Logger
- func SetVerbose(verbose Verbose) *Logger
- func V(verbosity Verbose) *Logger
- func WithFieldKeyVals(kvs ...interface{}) *Logger
- func WithFields(fields ...Field) *Logger
- func WithPrefix(args ...interface{}) *Logger
- func WithPrefixf(format string, args ...interface{}) *Logger
- func WithTime(tm time.Time) *Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Debugln(args ...interface{})
- func (l *Logger) Duplicate() *Logger
- func (l *Logger) ErfError(arg interface{}) *erf.Erf
- func (l *Logger) ErfErrorf(format string, args ...interface{}) *loggerErfResult
- func (l *Logger) ErfWarning(arg interface{}) *erf.Erf
- func (l *Logger) ErfWarningf(format string, args ...interface{}) *loggerErfResult
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Errorln(args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Fatalln(args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Infoln(args ...interface{})
- func (l *Logger) Print(args ...interface{})
- func (l *Logger) Printf(format string, args ...interface{})
- func (l *Logger) Println(args ...interface{})
- func (l *Logger) SetFlags(flags Flag) *Logger
- func (l *Logger) SetOutput(output Output) *Logger
- func (l *Logger) SetPrintSeverity(printSeverity Severity) *Logger
- func (l *Logger) SetSeverity(severity Severity) *Logger
- func (l *Logger) SetStackTraceSeverity(stackTraceSeverity Severity) *Logger
- func (l *Logger) SetVerbose(verbose Verbose) *Logger
- func (l *Logger) V(verbosity Verbose) *Logger
- func (l *Logger) Warning(args ...interface{})
- func (l *Logger) Warningf(format string, args ...interface{})
- func (l *Logger) Warningln(args ...interface{})
- func (l *Logger) WithFieldKeyVals(kvs ...interface{}) *Logger
- func (l *Logger) WithFieldMap(fieldMap map[string]interface{}) *Logger
- func (l *Logger) WithFields(fields ...Field) *Logger
- func (l *Logger) WithPrefix(args ...interface{}) *Logger
- func (l *Logger) WithPrefixf(format string, args ...interface{}) *Logger
- func (l *Logger) WithTime(tm time.Time) *Logger
- type Output
- type QueuedOutput
- type Severity
- type TextOutput
- type Verbose
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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
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
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 Warning ¶
func Warning(args ...interface{})
Warning 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.
type FieldMarkErf ¶ added in v1.2.0
func (*FieldMarkErf) String ¶ added in v1.2.0
func (m *FieldMarkErf) String() string
type Fields ¶
type Fields []Field
Fields is slice of fields.
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) MarshalText ¶ added in v1.0.1
MarshalText is implementation of encoding.TextMarshaler.
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 SetFlags ¶ added in v1.0.1
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 ¶
SetOutput sets the default Logger's output. It returns the default Logger. By default, the default Output.
func SetPrintSeverity ¶ added in v0.2.0
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 ¶
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
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 ¶
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 ¶
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 ¶
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
WithPrefixf duplicates the default Logger and adds given prefix to end of the underlying prefix.
func WithTime ¶
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) Debugln ¶
func (l *Logger) Debugln(args ...interface{})
Debugln logs to the DEBUG severity logs.
func (*Logger) ErfError ¶ added in v1.2.0
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
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
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
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) 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) 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) 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) 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
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) SetPrintSeverity ¶ added in v0.2.0
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 ¶
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
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 ¶
SetVerbose sets the Logger's verbose. It returns underlying Logger.
func (*Logger) V ¶
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) Warningln ¶
func (l *Logger) Warningln(args ...interface{})
Warningln logs to the WARNING severity logs.
func (*Logger) WithFieldKeyVals ¶ added in v0.2.0
WithFieldKeyVals duplicates the Logger with given key and values of Field.
func (*Logger) WithFieldMap ¶ added in v0.2.0
WithFieldMap duplicates the Logger with given fieldMap.
func (*Logger) WithFields ¶
WithFields duplicates the Logger with given fields.
func (*Logger) WithPrefix ¶ added in v0.3.0
WithPrefix duplicates the Logger and adds given prefix to end of the underlying prefix.
func (*Logger) WithPrefixf ¶ added in v0.6.0
WithPrefixf duplicates the Logger and adds given prefix to end of the underlying prefix.
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
AsyncOutput creates an output that doesn't block its logs to the provided output.
func MultiOutput ¶ added in v0.2.0
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
CheckValid returns ErrInvalidSeverity for invalid s.
func (Severity) MarshalText ¶ added in v1.0.1
MarshalText is implementation of encoding.TextMarshaler. If s is invalid, it returns nil and result of Severity.CheckValid.
func (*Severity) UnmarshalText ¶ added in v1.0.1
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) 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.