aka sklog is a wrapper for go-kit/log package that adds some shorthands, loggers and context packages so its easier to start:
package main
import (
"github.com/piotrkowalczuk/sklog"
"github.com/go-kit/kit/log"
"io"
)
var (
writer io.Writer
)
func main() {
// allocate writer
logger := log.NewJSONLogger(writer)
sklog.Info(logger, "just an info", "key", "val")
sklog.Debug(logger, "some debug information", "key", "value")
sklog.Error(logger, errors.New("example: fake error"), "key", "value")
// sklog.Fatal(logger, errors.New("example: fake error that exits"), "key", "value")
// sklog.Panic(logger, errors.New("example: fake error that panics"), "key", "value")
}
- Info - logs message with
level=info
,msg=msg
and given keyval's. - Debug - same like info but with debug level.
- Error - logs message with
level=error
,msg=error.Error()
and it tries to create a context from given error usingNewContextErrorGeneric
. It can be changed usingSetContextErrorFunc
. - Fatal - same like error but also exits with code 1.
- Panic - same like error but also panics.
Each package provide logic necessary to get information from error
objects.
- ctxjson - encoding/json
- ctxpq - lib/pq
- ctxmgo - gopkg.in/mgo.v2
Logger that prints easy to read (for humans) output, usefull for development. Inspired by Sirupsen/logrus. It can be used with DefaultHTTPFormatter
that recognize such keys:
timestamp
level
subsystem
http_method
http_path
http_status
msg
[2015-10-25T13:16:09+01:00] [debug] [api-server] [post] [/login] [200] - request processed username=email@example.com
Logger that wraps *testing.T
object. It is using only msg
key value.
Logger that provides API expected grpc.Logger interface.
Logger that aggregates multiple loggers into one.