Documentation
¶
Overview ¶
Example ¶
package main
import (
"errors"
"github.com/streamwest-1629/errlog"
)
func StacktraceTestA() error {
return errlog.Stamp(errlog.Container{
Type: errlog.LogError,
Message: "call in stack",
With: []errlog.Pair{errlog.QuotedString("func", "StacktraceTestA")},
})
}
func StacktraceTestB() error {
if err := StacktraceTestA(); err != nil {
return errlog.Stamp(errlog.Container{
Type: errlog.LogError,
Message: "call in stack",
With: []errlog.Pair{errlog.QuotedString("func", "StacktraceTestB")},
Internal: err,
})
}
return nil
}
func main() {
errlog.Default.Message(errlog.LogInfo, nil, "hello, world errlog!")
errlog.Default.Log(errlog.Stamp(
errlog.Container{
Type: errlog.LogInfo,
Message: "errlog was created with consideration for its compatibility with errors in Go language",
Description: "the objects issued for each logging can be treated as error types." +
" Therefore, you can choose whether to output the created logs as \"output as 'logged message'\"" +
" or \"delegate the processing to the caller as an 'error'\".",
}))
errlog.Default.Message(errlog.LogInfo, nil, "it supports errors.Unwrap(), errors.Is() function in errors package")
errlog.Default.Message(errlog.LogInfo, errors.New("example error"), "of course, it also supports the normal errors.New() function")
errlog.Default.Message(errlog.LogFixed, StacktraceTestB(), "it supports stacktrace")
}
Index ¶
Examples ¶
Constants ¶
View Source
const ( LogDebug LogType = 1 << iota LogInfo LogFixed LogWarn LogError LogFatal UnknownLog LogType = 0 LogDebugExpr = "DEBUG" LogInfoExpr = "INFO" LogFixedExpr = "FIXED" LogWarnExpr = "WARN" LogErrorExpr = "ERROR" LogFatalExpr = "FATAL" LogUnknownExpr = "UNKNOWN" )
Variables ¶
View Source
var Default interface { Message(level LogType, err error, msg string, with ...Pair) Log(content Container) } = DefaultLoggers.CommandLine
View Source
var DefaultLoggers = struct { CommandLine CommandLineLogger }{ CommandLine: CommandLineLogger{ Color: true, Dest: os.Stdout, }, }
View Source
var DefaultStamp = LogStampConfig{ EnableTimestamp: true, TimestampFormat: time.RFC3339, EnableStackTraceTypes: LogFixed | LogError | LogFatal, StackTraceFactory: func(programCounters []uintptr, dest []string) int { dest = dest[:0] frames := runtime.CallersFrames(programCounters) for { frame, more := frames.Next() funcName := filepath.Base(frame.Func.Name()) funcName = funcName[strings.IndexByte(funcName, '.')+1:] dest = append(dest, frame.File+":"+strconv.Itoa(frame.Line)+" "+funcName) if !more { return len(dest) } } }, }
View Source
var LoggingTypes = LogWarn | LogError | LogFatal
Functions ¶
This section is empty.
Types ¶
type CommandLineLogger ¶
type CommandLineLogger struct {
Color bool
Dest io.Writer
DefaultStamp *LogStampConfig
}
func (CommandLineLogger) Log ¶
func (cl CommandLineLogger) Log(content Container)
type Container ¶
type Container struct {
Type LogType
Message string
Description string
Internal error
With []Pair
// contains filtered or unexported fields
}
func StampDetail ¶
func (Container) StackTrace ¶
func (Container) WalkErrorstack ¶
type LogStampConfig ¶
type LogStampConfig struct {
EnableTimestamp bool
TimestampFormat string
EnableStackTraceTypes LogType
StackTraceFactory func(programCounters []uintptr, dest []string) int
}
func (*LogStampConfig) Stamp ¶
func (conf *LogStampConfig) Stamp(container Container) Container
func (*LogStampConfig) StampDetail ¶
func (conf *LogStampConfig) StampDetail(container Container, traceSkip int) Container
type Pair ¶
type Pair struct {
Key string
// contains filtered or unexported fields
}
func QuotedString ¶
Click to show internal directories.
Click to hide internal directories.