/loggo

Primary LanguageGoMIT LicenseMIT

loggo

quick start

  1. install
go get github.com/xiao-ren-wu/loggo
  1. create loggo
	logger, err := loggo.NewLogger()
	if err != nil {
		panic(err)
	}
	logger.Info("hello world")
  1. create with ops
import (
	"context"
	"github.com/xiao-ren-wu/loggo"
	"sync"
)

var l *loggo.Loggers
var once sync.Once

func Logs() *loggo.Loggers {
	once.Do(func() {
		logger, err := loggo.NewLogger(
			loggo.WithReportCaller(),
			loggo.WithCtxValue(func(ctx context.Context) map[string]interface{} {
				return map[string]interface{}{
					"logid": ctx.Value("logid"),
				}
			}),
			loggo.WithRotateLogs(&loggo.RotateLogsConfig{
				LogFilePrefix: "logfile/loggo",
				RotationSize:  2000,
			}),
		)
		if err != nil {
			panic(err)
		}
		l = logger
	})
	return l
}