go>> log>> 返回
项目作者: haormj

项目描述 :
A simple go log
高级语言: Go
项目地址: git://github.com/haormj/log.git
创建时间: 2018-05-08T08:44:02Z
项目社区:https://github.com/haormj/log

开源协议:Apache License 2.0

下载


Log Build Status GoDoc Go Report Card

A simple go log.

Install

  1. go get github.com/haormj/log

Usage

  1. package main
  2. import (
  3. "context"
  4. "github.com/haormj/log"
  5. )
  6. func main() {
  7. l := log.Logger.Clone()
  8. l.With("main", "I'm main")
  9. ctx := log.NewContext(context.Background(), l)
  10. hello(ctx)
  11. world(ctx)
  12. l.Info("main", "end")
  13. }
  14. func hello(ctx context.Context) {
  15. l, _ := log.FromContext(ctx)
  16. l.With("hello", "1")
  17. l.Infow("this is hello function")
  18. }
  19. func world(ctx context.Context) {
  20. l, _ := log.FromContext(ctx)
  21. l.With("world", 2)
  22. l.Infof("this is %s function", "world")
  23. }

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