Skip to content

haormj/log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Log Build Status GoDoc Go Report Card

A simple go log.

Install

go get github.com/haormj/log

Usage

package main

import (
	"context"

	"github.com/haormj/log"
)

func main() {
	l := log.Logger.Clone()

	l.With("main", "I'm main")
	ctx := log.NewContext(context.Background(), l)
	hello(ctx)
	world(ctx)
	l.Info("main", "end")
}

func hello(ctx context.Context) {
	l, _ := log.FromContext(ctx)
	l.With("hello", "1")
	l.Infow("this is hello function")
}

func world(ctx context.Context) {
	l, _ := log.FromContext(ctx)
	l.With("world", 2)
	l.Infof("this is %s function", "world")
}

If pass Log through Context, pay attention to the life cycle of the Context to prevent memory increase