Skip to content

busimus/gocutelog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gocutelog – bridge between Go logging libraries and cutelog

godoc license

This Go package makes it possible to send log records from Go logging libraries to a cutelog instance without having to manually manage a socket connection.

Function NewWriter returns a struct that implements io.Writer interface so it can be used as output by libraries like zerolog, zap, onelog, logrus, etc.

Just like cutelog itself, this package is meant to be used only during development, so performance or reliability are not the focus here.

Usage

zerolog

package main

import (
    "github.com/busimus/gocutelog"
    "github.com/rs/zerolog"
)

func main() {
	w := gocutelog.NewWriter("localhost:19996", "json")
	l := zerolog.New(w)
	l.Info().Msg("Hello world from zerolog!")
}

onelog

package main

import (
    "github.com/busimus/gocutelog"
    "github.com/francoispqt/onelog"
)

func main() {
	w := gocutelog.NewWriter("localhost:19996", "json")
	l := onelog.New(w, onelog.ALL)
	l.Info("Hello world from onelog!")
}

logrus

package main

import (
    "github.com/busimus/gocutelog"
    "github.com/sirupsen/logrus"
)

func main() {
	w := gocutelog.NewWriter("localhost:19996", "json")
	l := logrus.New()
	l.Out = w
	l.Formatter = new(logrus.JSONFormatter)
	l.Info("Hello world from logrus!")
}

zap

package main

import (
    "github.com/busimus/gocutelog"
	"go.uber.org/zap"
   	"go.uber.org/zap/zapcore"
)

func main() {
	w := gocutelog.NewWriter("localhost:19996", "json")
	conf := zapcore.EncoderConfig{
		TimeKey:        "time",
		LevelKey:       "level",
		NameKey:        "name",
		CallerKey:      "caller",
		MessageKey:     "msg",
		StacktraceKey:  "exc_info",
		LineEnding:     "",
		EncodeLevel:    zapcore.CapitalLevelEncoder,
		EncodeTime:     zapcore.EpochTimeEncoder,
		EncodeDuration: zapcore.SecondsDurationEncoder,
		EncodeCaller:   zapcore.ShortCallerEncoder,
	}
	enc := zapcore.NewJSONEncoder(conf)
	priority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
		return true
	})
	core := zapcore.NewCore(enc, w, priority)
	l := zap.New(core)
	l.Info("Hello world from zap!")
}

License

Released under the MIT license.

About

Bridge between Go logging libraries and cutelog

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages