Skip to content

Logger is a logging package based on zap's SugaredLogger and lumberjack.

Notifications You must be signed in to change notification settings

ALong1997/logger

Repository files navigation

Logger

Logger is a logging package based on zap's SugaredLogger and lumberjack. It supports rolling log file, json or console encoder, console output, goroutine id, link tracing and provides some common log level functions.

Convenience functions

  • Sync

  • Debug(F)(WithContext)

  • Info(F)(WithContext)

  • Warn(F)(WithContext)

  • Error(F)(WithContext)

Getting started

Prerequisites

Getting

With Go module support, simply add the following import

import "github.com/ALong1997/logger"

Otherwise, run the following Go command to install the logger package:

$ go get -u https://github.com/ALong1997/logger

Quick Start

package main

import (
	"context"
	
	"github.com/ALong1997/logger"
)

func main() {
	config := logger.DefaultConfig()
	logger.Init(config)

	s := "Hello World!"
	logger.Debug(s)
	logger.ErrorF("%s", s)

	traceID := "123456"
	ctx := context.WithValue(context.Background(), logger.TraceIDKey, traceID)
	logger.InfoWithContext(ctx, s)
	logger.WarnFWithContext(ctx, "%v", s)

	if err := logger.Sync(); err != nil {
		logger.Error(err)
	}
}

About

Logger is a logging package based on zap's SugaredLogger and lumberjack.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages