Skip to content

Latest commit

 

History

History
81 lines (66 loc) · 1.32 KB

File metadata and controls

81 lines (66 loc) · 1.32 KB

logc

Golang Logger Wrapper

  • Easy for change Log Library Support (zap, zerolog)
  • Simple & Easy

Install

go get github.com/dreamph/logc

Examples - Use Zap

package main

import (
	"context"
	"github.com/dreamph/logc"
	"github.com/dreamph/logc/zap"
)

func main() {
	logger := zap.NewLogger(&logc.Options{
		FilePath: "./app.log",
		Level:    "debug",
		Format:   "json",
		MaxAge:   30,
		MaxSize:  10,
	})
	defer logger.Release()

	logger.Info("Test Info")
	logger.Warn("Test Warn")

	d := map[string]interface{}{
		"requestId": "123",
	}
	log := logger.WithLogger(logc.WithValue(context.Background(), d))
	log.Info("Test")

}

Examples - Use ZeroLog

package main

import (
	"context"
	"github.com/dreamph/logc"
	"github.com/dreamph/logc/zerolog"
)

func main() {
	logger := zerolog.NewLogger(&logc.Options{
		FilePath: "./app.log",
		Level:    "debug",
		Format:   "json",
		MaxAge:   30,
		MaxSize:  10,
	})
	defer logger.Release()

	logger.Info("Test Info")
	logger.Warn("Test Warn")

	d := map[string]interface{}{
		"requestId": "123",
	}
	log := logger.WithLogger(logc.WithValue(context.Background(), d))
	log.Info("Test")
}

Buy Me a Coffee

"Buy Me A Coffee"