log4g
How To Use?
go get -u github.com/acmestack/log4g
Import
import "github.com/acmestack/log4g/log"
Log Example
log.SetLevel(log.TraceLevel)
defer log.Reset()
log.Trace("a", "=", "1")
log.Tracef("a=%d", 1)
log.Trace(func() []interface{} {
return log.T("a", "=", "1")
})
log.Tracef("a=%d", func() []interface{} {
return log.T(1)
})
...
ctx := context.WithValue(context.TODO(), traceIDKey, "0689")
log.SetLevel(log.TraceLevel)
log.SetOutput(myOutput)
defer log.Reset()
logger := log.Ctx(ctx)
logger.Trace("level:", "trace")
logger.Tracef("level:%s", "trace")
...
logger = log.Tag("__in")
logger.Ctx(ctx).Trace("level:", "trace")
logger.Ctx(ctx).Tracef("level:%s", "trace")
...
Color Example
fmt.Println(color.BgBlack.Sprint("ok"))
fmt.Println(color.BgRed.Sprint("ok"))
fmt.Println(color.BgGreen.Sprint("ok"))
fmt.Println(color.BgYellow.Sprint("ok"))
attributes := []color.Attribute{
color.Bold,
color.Italic,
color.Underline,
color.ReverseVideo,
color.CrossedOut,
color.Red,
color.BgGreen,
}
fmt.Println(color.NewText(attributes...).Sprint("ok"))
Assert Example
assert.True(t, true)
assert.Nil(t, nil)
assert.Equal(t, 0, "0")
assert.NotEqual(t, "0", 0)
assert.Same(t, 0, "0")
assert.NotSame(t, "0", "0")
assert.Panic(g, func() {}, "an error")
assert.Matches(g, "there's no error", "an error")
assert.Error(g, errors.New("there's no error"), "an error")
assert.TypeOf(g, new(int), (*int)(nil))
assert.Implements(g, errors.New("error"), (*error)(nil))