Documentation ¶
Overview ¶
Package logng provides structured and leveled logging.
Example ¶
// reset logng for previous changes. logng.Reset() // change writer of default output to stdout from stderr. logng.SetTextOutputWriter(os.Stdout) // log by severity and verbosity. // default Logger's severity is SeverityInfo. // default Logger's verbose is 0. logng.Debug("this is debug log. it won't be shown.") logng.Info("this is info log.") logng.Warning("this is warning log.") logng.V(1).Error("this is error log, verbosity 1. it won't be shown.") // SetSeverity() logng.SetSeverity(logng.SeverityDebug) logng.Debug("this is debug log. it will now be shown.") // SetVerbose() and V() logng.SetVerbose(1) logng.V(1).Error("this is error log, verbosity 1. it will now be shown.") logng.V(2).Warning("this is warning log, verbosity 2. it won't be shown.") // SetTextOutputFlags() // default flags is FlagDefault. logng.SetTextOutputFlags(logng.TextOutputFlagDefault | logng.TextOutputFlagShortFile) logng.Info("this is info log. you can see file name and line in this log.") // log using Print. // default print severity is SeverityInfo. logng.Print("this log will be shown as info log.") // SetPrintSeverity() logng.SetPrintSeverity(logng.SeverityWarning) logng.Print("this log will now be shown as warning log.") // SetStackTraceSeverity() // default stack trace severity is none. logng.SetStackTraceSeverity(logng.SeverityWarning) logng.Warning("this is warning log. you can see stack trace end of this log.") logng.Error("this is error log. you can still see stack trace end of this log.") logng.Info("this is info log. stack trace won't be shown end of this log.") // WithTime() logng.WithTime(testTime).Info("this is info log with custom time.") // WithPrefix() logng.WithPrefix("prefix1").Warning("this is warning log with prefix 'prefix1'.") logng.WithPrefix("prefix1").WithPrefix("prefix2").Error("this is error log with both of prefixes 'prefix1' and 'prefix2'.") // WithFieldKeyVals() logng.WithFieldKeyVals("key1", "val1", "key2", "val2", "key3", "val3", "key1", "val1-2", "key2", "val2-2").Info("this is info log with several fields.") // SetTextOutputFlags() // default flags is TextOutputFlagDefault. logng.SetTextOutputFlags(logng.TextOutputFlagDefault | logng.TextOutputFlagShortFile) logng.Info("this is info log. you can see file name and line in this log.") // multi-line logs logng.Info("this is\nmulti-line log with file name") logng.Info("this is\nmulti-line log") logng.WithFieldKeyVals("key1", "val1").Info("this is\nmulti-line log with key vals")
Output:
Example (Test1) ¶
// reset logng for previous changes. logng.Reset() // change writer of default output to stdout from stderr. logng.SetTextOutputWriter(os.Stdout) // just show severity. logng.SetTextOutputFlags(logng.TextOutputFlagSeverity) logng.Debug("this is debug log, verbosity 0. it will not be shown.") logng.Info("this is info log, verbosity 0.") logng.Warning("this is warning log, verbosity 0.") logng.Error("this is error log, verbosity 0.") logng.Print("this is info log, verbosity 0 caused by Print().") logng.V(1).Info("this is info log, verbosity 1. it will not be shown.") logng.SetSeverity(logng.SeverityDebug) logng.Debug("this is debug log, verbosity 0.") logng.SetVerbose(1) logng.V(0).Info("this is info log, verbosity 0.") logng.V(1).Info("this is info log, verbosity 1.") logng.V(2).Info("this is info log, verbosity 2. it will not be shown.") logng.SetPrintSeverity(logng.SeverityWarning) logng.Print("this is warning log, verbosity 0 caused by Print().") logng.Warning("this is warning log, verbosity 0.\nwithout padding.") logng.SetTextOutputFlags(logng.TextOutputFlagSeverity | logng.TextOutputFlagPadding) logng.Warning("this is warning log, verbosity 0.\nwith padding.") logng.SetTextOutputFlags(logng.TextOutputFlagDefault) tm, _ := time.ParseInLocation("2006-01-02T15:04:05", "2019-11-13T21:56:24", time.Local) logng.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 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 Fields
- type JSONOutput
- type JSONOutputFlag
- type Log
- type Logger
- func Clone() *Logger
- func DefaultLogger() *Logger
- func NewLogger(output Output, severity Severity, verbose Verbose) *Logger
- func SetOutput(output Output) *Logger
- func SetPrintSeverity(printSeverity Severity) *Logger
- func SetSeverity(severity Severity) *Logger
- func SetStackTraceSeverity(stackTraceSeverity Severity) *Logger
- func SetStackTraceSize(stackTraceSize int) *Logger
- func SetVerbose(verbose Verbose) *Logger
- func V(verbosity Verbose) *Logger
- func WithCtxErrVerbosity(verbosity Verbose) *Logger
- func WithFieldKeyVals(kvs ...interface{}) *Logger
- func WithFieldMap(fieldMap map[string]interface{}) *Logger
- func WithFields(fields ...Field) *Logger
- func WithPrefix(args ...interface{}) *Logger
- func WithPrefixf(format string, args ...interface{}) *Logger
- func WithSuffix(args ...interface{}) *Logger
- func WithSuffixf(format string, args ...interface{}) *Logger
- func WithTime(tm time.Time) *Logger
- func WithVerbosity(verbosity Verbose) *Logger
- func WithoutTime() *Logger
- func (l *Logger) Clone() *Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Debugln(args ...interface{})
- 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) 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) SetStackTraceSize(stackTraceSize int) *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) WithCtxErrVerbosity(verbosity Verbose) *Logger
- 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) WithSuffix(args ...interface{}) *Logger
- func (l *Logger) WithSuffixf(format string, args ...interface{}) *Logger
- func (l *Logger) WithTime(tm time.Time) *Logger
- func (l *Logger) WithVerbosity(verbosity Verbose) *Logger
- func (l *Logger) WithoutTime() *Logger
- type Output
- type QueuedOutput
- type Severity
- type StackCaller
- type StackTrace
- func (t *StackTrace) Caller(index int) StackCaller
- func (t *StackTrace) Callers() []StackCaller
- func (t *StackTrace) Clone() *StackTrace
- func (t *StackTrace) Format(f fmt.State, verb rune)
- func (t *StackTrace) ProgramCounter(index int) uintptr
- func (t *StackTrace) ProgramCounters() []uintptr
- func (t *StackTrace) SizeOfCallers() int
- func (t *StackTrace) SizeOfProgramCounters() int
- func (t *StackTrace) String() string
- type TextOutput
- type TextOutputFlag
- 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 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 ¶
func Print(args ...interface{})
Print logs a log which has the default Logger's print severity to the default Logger.
func Printf ¶
func Printf(format string, args ...interface{})
Printf logs a log which has the default Logger's print severity to the default Logger.
func Println ¶
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 JSONOutput ¶
type JSONOutput struct {
// contains filtered or unexported fields
}
JSONOutput is an implementation of Output by writing json to io.Writer w.
func NewJSONOutput ¶
func NewJSONOutput(w io.Writer, flags JSONOutputFlag) *JSONOutput
NewJSONOutput creates a new JSONOutput.
func (*JSONOutput) SetFlags ¶
func (o *JSONOutput) SetFlags(flags JSONOutputFlag) *JSONOutput
SetFlags sets flags to override every single Log.Flags if the argument flags different from 0. It returns the underlying JSONOutput.
func (*JSONOutput) SetOnError ¶
func (o *JSONOutput) SetOnError(f func(error)) *JSONOutput
SetOnError sets a function to call when error occurs. It returns the underlying JSONOutput.
func (*JSONOutput) SetTimeLayout ¶
func (o *JSONOutput) SetTimeLayout(timeLayout string) *JSONOutput
SetTimeLayout sets a time layout to format time field. It returns the underlying JSONOutput.
func (*JSONOutput) SetWriter ¶
func (o *JSONOutput) SetWriter(w io.Writer) *JSONOutput
SetWriter sets writer. It returns the underlying JSONOutput.
type JSONOutputFlag ¶
type JSONOutputFlag int
JSONOutputFlag holds single or multiple flags of JSONOutput. A JSONOutput instance uses these flags which are stored by JSONOutputFlag type.
const ( // JSONOutputFlagSeverity prints the string value of severity into severity field. JSONOutputFlagSeverity JSONOutputFlag = 1 << iota // JSONOutputFlagTime prints the time in the given time zone into time field. JSONOutputFlagTime // JSONOutputFlagLocalTZ uses the local time zone rather than the given time zone if JSONOutputFlagTime is set. JSONOutputFlagLocalTZ // JSONOutputFlagUTC uses UTC rather than the given or local time zone if JSONOutputFlagTime is set. JSONOutputFlagUTC // JSONOutputFlagTimestamp prints the unix timestamp into timestamp field. JSONOutputFlagTimestamp // JSONOutputFlagTimestampMicro prints the unix timestamp with microsecond resolution into timestamp field. // assumes JSONOutputFlagTimestamp. JSONOutputFlagTimestampMicro // JSONOutputFlagSeverityLevel prints the numeric value of severity into severity_level field. JSONOutputFlagSeverityLevel // JSONOutputFlagVerbosity prints verbosity field. JSONOutputFlagVerbosity // JSONOutputFlagLongFunc prints full package name and function name into func field : a/b/c/d.Func1(). JSONOutputFlagLongFunc // JSONOutputFlagShortFunc prints final package name and function name into func field: d.Func1(). // overrides JSONOutputFlagLongFunc. JSONOutputFlagShortFunc // JSONOutputFlagLongFile prints full file name and line number into file field: a/b/c/d.go:23. JSONOutputFlagLongFile // JSONOutputFlagShortFile prints final file name element and line number into file field: d.go:23. // overrides JSONOutputFlagLongFile. JSONOutputFlagShortFile // JSONOutputFlagStackTrace prints stack_trace field if the stack trace is given. JSONOutputFlagStackTrace // JSONOutputFlagStackTraceShortFile prints with file name element only. // assumes JSONOutputFlagStackTrace. JSONOutputFlagStackTraceShortFile // JSONOutputFlagFields prints additional fields if given. JSONOutputFlagFields // JSONOutputFlagDefault holds predefined default flags. JSONOutputFlagDefault = JSONOutputFlagSeverity | JSONOutputFlagTime | JSONOutputFlagLocalTZ | JSONOutputFlagLongFunc | JSONOutputFlagShortFile | JSONOutputFlagStackTraceShortFile | JSONOutputFlagFields )
type Log ¶
type Log struct { Message []byte Error error Severity Severity Verbosity Verbose Time time.Time Fields Fields StackCaller StackCaller StackTrace *StackTrace }
Log carries the log.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger provides a logger for leveled and structured logging.
Example ¶
logger := logng.NewLogger(logng.NewTextOutput(os.Stdout, logng.TextOutputFlagSeverity), logng.SeverityInfo, 2) logger.Debug("this is debug log, verbosity 0. it won't be shown.") logger.Info("this is info log, verbosity 0.") logger.V(0).Debug("this is debug log, verbosity 0. it won't be shown.") logger.V(1).Info("this is info log, verbosity 1.") logger.V(2).Warning("this is warning log, verbosity 2.") logger.V(3).Error("this is error log, verbosity 3. it won't be shown.")
Output: INFO - this is info log, verbosity 0. INFO - this is info log, verbosity 1. WARNING - this is warning log, verbosity 2.
func SetOutput ¶
SetOutput sets the default Logger's output. It returns the default Logger. By default, the default TextOutput.
func SetPrintSeverity ¶
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.
Example ¶
// set logng for this example. logng.Reset() logng.SetTextOutputWriter(os.Stdout) logng.SetTextOutputFlags(logng.TextOutputFlagSeverity) logng.SetPrintSeverity(logng.SeverityWarning) logng.Print("this is the log.")
Output: WARNING - this is the log.
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 ¶
// set logng for this example. logng.Reset() logng.SetTextOutputWriter(os.Stdout) logng.SetTextOutputFlags(logng.TextOutputFlagSeverity) logng.SetSeverity(logng.SeverityWarning) logng.Debug("this is debug log. it won't be shown.") logng.Info("this is info log. it won't be shown.") logng.Warning("this is warning log.") logng.Error("this is error log.")
Output: WARNING - this is warning log. ERROR - this is error log.
func SetStackTraceSeverity ¶
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 SetStackTraceSize ¶
SetStackTraceSize sets the maximum program counter size of the stack trace for the default Logger. If stackTraceSize is out of range, it sets 64. The range is 1 to 16384 each included. It returns the default Logger. By default, 64.
func SetVerbose ¶
SetVerbose sets the default Logger's verbose. It returns the default Logger. By default, 0.
Example ¶
// set logng for this example. logng.Reset() logng.SetTextOutputWriter(os.Stdout) logng.SetTextOutputFlags(logng.TextOutputFlagSeverity) logng.SetVerbose(1) logng.V(0).Info("this is info log, verbosity 0.") logng.V(1).Info("this is info log, verbosity 1.") logng.V(2).Info("this is info log, verbosity 2. it won't be shown.") logng.V(3).Info("this is info log, verbosity 3. it won't be shown.")
Output: INFO - this is info log, verbosity 0. INFO - this is info log, verbosity 1.
func V ¶
V clones the default Logger with the given verbosity if the default Logger's verbose is greater or equal to the given verbosity, otherwise returns nil.
func WithCtxErrVerbosity ¶
WithCtxErrVerbosity clones the default Logger with context error verbosity. If the log has an error and the error is an context error, the given value is used as verbosity.
func WithFieldKeyVals ¶
func WithFieldKeyVals(kvs ...interface{}) *Logger
WithFieldKeyVals clones the default Logger with given keys and values of Field.
func WithFieldMap ¶
WithFieldMap clones the default Logger with the given field map.
func WithFields ¶
WithFields clones the default Logger with given fields.
func WithPrefix ¶
func WithPrefix(args ...interface{}) *Logger
WithPrefix clones the default Logger and adds the given prefix to the end of the underlying prefix.
Example ¶
// set logng for this example. logng.Reset() logng.SetTextOutputWriter(os.Stdout) logng.SetTextOutputFlags(logng.TextOutputFlagSeverity) logng.WithPrefix("prefix1: ").WithPrefix("prefix2: ").Info("this is info log.")
Output: INFO - prefix1: prefix2: this is info log.
func WithPrefixf ¶
WithPrefixf clones the default Logger and adds the given prefix to the end of the underlying prefix.
func WithSuffix ¶
func WithSuffix(args ...interface{}) *Logger
WithSuffix clones the default Logger and adds the given suffix to the beginning of the underlying suffix.
Example ¶
// set logng for this example. logng.Reset() logng.SetTextOutputWriter(os.Stdout) logng.SetTextOutputFlags(logng.TextOutputFlagSeverity) logng.WithSuffix(" :suffix1").WithSuffix(" :suffix2").Info("this is info log.")
Output: INFO - this is info log. :suffix2 :suffix1
func WithSuffixf ¶
WithSuffixf clones the default Logger and adds the given suffix to the beginning of the underlying suffix.
func WithTime ¶
WithTime clones the default Logger with the given time.
Example ¶
// set logng for this example. logng.Reset() logng.SetTextOutputWriter(os.Stdout) logng.SetTextOutputFlags(logng.TextOutputFlagDefault) logng.WithTime(testTime).Info("this is info log with the given time.")
Output: 2010/11/12 13:14:15 INFO - this is info log with the given time.
func WithVerbosity ¶
WithVerbosity clones the default Logger with the given verbosity.
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) 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 ¶
func (l *Logger) Print(args ...interface{})
Print logs a log which has the underlying Logger's print severity.
func (*Logger) Println ¶
func (l *Logger) Println(args ...interface{})
Println logs a log which has the underlying Logger's print severity.
func (*Logger) SetOutput ¶
SetOutput sets the underlying Logger's output. It returns the underlying Logger.
func (*Logger) SetPrintSeverity ¶
SetPrintSeverity sets the underlying Logger's severity level which is using with Print methods. If printSeverity is invalid or, less or equal than SeverityFatal; it sets SeverityInfo. It returns the underlying Logger. By default, SeverityInfo.
func (*Logger) SetSeverity ¶
SetSeverity sets the underlying Logger's severity. If severity is invalid, it sets SeverityInfo. It returns the underlying Logger.
func (*Logger) SetStackTraceSeverity ¶
SetStackTraceSeverity sets the underlying Logger's severity level which saves stack trace into Log. If stackTraceSeverity is invalid, it sets SeverityNone. It returns the underlying Logger. By default, SeverityNone.
func (*Logger) SetStackTraceSize ¶
SetStackTraceSize sets the maximum program counter size of the stack trace for the underlying Logger. If stackTraceSize is out of range, it sets 64. The range is 1 to 16384 each included. It returns the underlying Logger. By default, 64.
func (*Logger) SetVerbose ¶
SetVerbose sets the underlying Logger's verbose. It returns the underlying Logger.
func (*Logger) V ¶
V clones the underlying Logger with the given verbosity if the underlying Logger's verbose is greater or equal to the 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) WithCtxErrVerbosity ¶
WithCtxErrVerbosity clones the underlying Logger with context error verbosity. If the log has an error and the error is an context error, the given value is used as verbosity.
func (*Logger) WithFieldKeyVals ¶
WithFieldKeyVals clones the underlying Logger with given keys and values of Field.
func (*Logger) WithFieldMap ¶
WithFieldMap clones the underlying Logger with the given field map.
func (*Logger) WithFields ¶
WithFields clones the underlying Logger with given fields.
func (*Logger) WithPrefix ¶
WithPrefix clones the underlying Logger and adds the given prefix to the end of the underlying prefix.
func (*Logger) WithPrefixf ¶
WithPrefixf clones the underlying Logger and adds the given prefix to the end of the underlying prefix.
func (*Logger) WithSuffix ¶
WithSuffix clones the underlying Logger and adds the given suffix to the beginning of the underlying suffix.
func (*Logger) WithSuffixf ¶
WithSuffixf clones the underlying Logger and adds the given suffix to the beginning of the underlying suffix.
func (*Logger) WithVerbosity ¶
WithVerbosity clones the underlying Logger with the given verbosity.
func (*Logger) WithoutTime ¶
WithoutTime clones the underlying Logger without time.
type Output ¶
type Output interface {
Log(log *Log)
}
Output is an interface for Logger output. All of Output implementations must be safe for concurrency.
func MultiOutput ¶
MultiOutput creates an output that clones its logs to all the provided outputs.
type QueuedOutput ¶
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 ¶
func NewQueuedOutput(output Output, queueLen int) (o *QueuedOutput)
NewQueuedOutput creates a new QueuedOutput by the given output.
func (*QueuedOutput) Close ¶
func (o *QueuedOutput) Close() error
Close stops accepting new logs to the underlying QueuedOutput and waits for the queue to empty. Unused QueuedOutput must be closed for freeing resources.
func (*QueuedOutput) Log ¶
func (o *QueuedOutput) Log(log *Log)
Log is the implementation of Output. If blocking is true, Log method blocks execution until the underlying output has finished execution. Otherwise, Log method sends the log to the queue if the queue is available. When the queue is full, it tries to call OnQueueFull function.
func (*QueuedOutput) SetBlocking ¶
func (o *QueuedOutput) SetBlocking(blocking bool) *QueuedOutput
SetBlocking sets QueuedOutput behavior when the queue is full. It returns the underlying QueuedOutput.
func (*QueuedOutput) SetOnQueueFull ¶
func (o *QueuedOutput) SetOnQueueFull(f func()) *QueuedOutput
SetOnQueueFull sets a function to call when the queue is full. It returns the underlying QueuedOutput.
type Severity ¶
type Severity int
Severity describes the severity level of Log.
const ( // SeverityNone is none or unspecified severity level. SeverityNone Severity = iota // SeverityFatal is the fatal severity level. SeverityFatal // SeverityError is the error severity level. SeverityError // SeverityWarning is the warning severity level. SeverityWarning // SeverityInfo is the info severity level. SeverityInfo // SeverityDebug is the debug severity level. SeverityDebug )
func (Severity) CheckValid ¶
CheckValid returns ErrInvalidSeverity for invalid s.
func (Severity) MarshalText ¶
MarshalText is the implementation of encoding.TextMarshaler. If s is invalid, it returns the error from Severity.CheckValid.
func (*Severity) UnmarshalText ¶
UnmarshalText is the implementation of encoding.TextUnmarshaler. If text is unknown, it returns ErrUnknownSeverity.
type StackCaller ¶
StackCaller stores the information of the stack caller. StackCaller can format the given information as string by using String or Format methods.
func (StackCaller) Format ¶
func (c StackCaller) Format(f fmt.State, verb rune)
Format is the implementation of fmt.Formatter.
For '%s' (also '%v'):
%s just show function and entry without padding and indent. %+s show file path, line and program counter. padding char '\t', default padding 0, default indent 1. % s show file path, line and program counter. padding char ' ', default padding 0, default indent 2. %+ s exact with '% s'. %#s same with '%+s', use file name as file path. %+#s exact with '%#s'. % #s same with '% s', use file name as file path. %+4s same with '%+s', padding 4, indent 1 by default. %+.3s same with '%+s', padding 0 by default, indent 3. %+4.3s same with '%+s', padding 4, indent 3. %+4.s same with '%+s', padding 4, indent 0. % 4s same with '% s', padding 4, indent 2 by default. % .3s same with '% s', padding 0 by default, indent 3. % 4.3s same with '% s', padding 4, indent 3. % 4.s same with '% s', padding 4, indent 0. %#4.3s same with '%#s', padding 4, indent 3. % #4.3s same with '% #s', padding 4, indent 3.
func (StackCaller) String ¶
func (c StackCaller) String() string
String is the implementation of fmt.Stringer. It is synonym with fmt.Sprintf("%s", c).
type StackTrace ¶
type StackTrace struct {
// contains filtered or unexported fields
}
StackTrace stores the information of the stack trace.
func CurrentStackTrace ¶
func CurrentStackTrace(size, skip int) *StackTrace
CurrentStackTrace creates a new StackTrace at this point. size limits maximum program counter size. It uses runtime.Callers and uses skip argument as is. So you should increase skip argument by 1.
func NewStackTrace ¶
func NewStackTrace(programCounters []uintptr) *StackTrace
NewStackTrace creates a new StackTrace from program counters.
func (*StackTrace) Caller ¶
func (t *StackTrace) Caller(index int) StackCaller
Caller returns a caller on the given index. It panics if index is out of range.
func (*StackTrace) Callers ¶
func (t *StackTrace) Callers() []StackCaller
Callers returns StackCaller's.
func (*StackTrace) Clone ¶
func (t *StackTrace) Clone() *StackTrace
Clone clones the underlying StackTrace.
func (*StackTrace) Format ¶
func (t *StackTrace) Format(f fmt.State, verb rune)
Format is the implementation of fmt.Formatter. Format lists all StackCaller's in the underlying StackTrace line by line with the given format.
func (*StackTrace) ProgramCounter ¶
func (t *StackTrace) ProgramCounter(index int) uintptr
ProgramCounter returns a program counter on the given index. It panics if index is out of range.
func (*StackTrace) ProgramCounters ¶
func (t *StackTrace) ProgramCounters() []uintptr
ProgramCounters returns program counters.
func (*StackTrace) SizeOfCallers ¶
func (t *StackTrace) SizeOfCallers() int
SizeOfCallers returns the size of StackCaller's.
func (*StackTrace) SizeOfProgramCounters ¶
func (t *StackTrace) SizeOfProgramCounters() int
SizeOfProgramCounters returns the size of program counters.
func (*StackTrace) String ¶
func (t *StackTrace) String() string
String is the implementation of fmt.Stringer. It is synonym with fmt.Sprintf("%s", t).
type TextOutput ¶
type TextOutput struct {
// contains filtered or unexported fields
}
TextOutput is an implementation of Output by writing texts to io.Writer w.
func DefaultTextOutput ¶
func DefaultTextOutput() *TextOutput
DefaultTextOutput returns the default TextOutput.
func NewTextOutput ¶
func NewTextOutput(w io.Writer, flags TextOutputFlag) *TextOutput
NewTextOutput creates a new TextOutput.
func SetTextOutputFlags ¶
func SetTextOutputFlags(flags TextOutputFlag) *TextOutput
SetTextOutputFlags sets the default TextOutput's flags. It returns the default TextOutput. By default, TextOutputFlagDefault.
func SetTextOutputWriter ¶
func SetTextOutputWriter(w io.Writer) *TextOutput
SetTextOutputWriter sets the default TextOutput's writer. It returns the default TextOutput. By default, os.Stderr.
func (*TextOutput) SetFlags ¶
func (o *TextOutput) SetFlags(flags TextOutputFlag) *TextOutput
SetFlags sets flags to override every single Log.Flags if argument flags is different from 0. It returns the underlying TextOutput.
func (*TextOutput) SetOnError ¶
func (o *TextOutput) SetOnError(f func(error)) *TextOutput
SetOnError sets a function to call when error occurs. It returns the underlying TextOutput.
func (*TextOutput) SetWriter ¶
func (o *TextOutput) SetWriter(w io.Writer) *TextOutput
SetWriter sets writer. It returns the underlying TextOutput.
type TextOutputFlag ¶
type TextOutputFlag int
TextOutputFlag holds single or multiple flags of TextOutput. A TextOutput instance uses these flags which are stored by TextOutputFlag type.
const ( // TextOutputFlagDate prints the date in the local time zone: 2009/01/23. TextOutputFlagDate TextOutputFlag = 1 << iota // TextOutputFlagTime prints the time in the local time zone: 01:23:23. TextOutputFlagTime // TextOutputFlagMicroseconds prints microsecond resolution: 01:23:23.123123. // assumes TextOutputFlagTime. TextOutputFlagMicroseconds // TextOutputFlagUTC uses UTC rather than the local time zone if TextOutputFlagDate or TextOutputFlagTime is set. TextOutputFlagUTC // TextOutputFlagSeverity prints the severity. TextOutputFlagSeverity // TextOutputFlagPadding prints padding with multiple lines. TextOutputFlagPadding // TextOutputFlagLongFunc prints full package name and function name: a/b/c/d.Func1(). TextOutputFlagLongFunc // TextOutputFlagShortFunc prints final package name and function name: d.Func1(). // overrides TextOutputFlagLongFunc. TextOutputFlagShortFunc // TextOutputFlagLongFile prints full file name and line number: a/b/c/d.go:23. TextOutputFlagLongFile // TextOutputFlagShortFile prints final file name element and line number: d.go:23. // overrides TextOutputFlagLongFile. TextOutputFlagShortFile // TextOutputFlagFields prints fields if given. TextOutputFlagFields // TextOutputFlagStackTrace prints the stack trace if given. TextOutputFlagStackTrace // TextOutputFlagStackTraceShortFile prints with file name element only. // assumes TextOutputFlagStackTrace. TextOutputFlagStackTraceShortFile // TextOutputFlagDefault holds predefined default flags. // it used by the default Logger. TextOutputFlagDefault = TextOutputFlagDate | TextOutputFlagTime | TextOutputFlagSeverity | TextOutputFlagPadding | TextOutputFlagFields | TextOutputFlagStackTraceShortFile )