Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/haormj/log
A simple go log
https://github.com/haormj/log
go-log log zap
Last synced: 6 days ago
JSON representation
A simple go log
- Host: GitHub
- URL: https://github.com/haormj/log
- Owner: haormj
- License: apache-2.0
- Created: 2018-05-08T08:44:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-25T23:31:30.000Z (over 4 years ago)
- Last Synced: 2024-06-20T07:56:13.073Z (5 months ago)
- Topics: go-log, log, zap
- Language: Go
- Homepage:
- Size: 114 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Log [![Build Status](https://travis-ci.org/haormj/log.svg?branch=master)](https://travis-ci.org/haormj/log) [![GoDoc](https://godoc.org/github.com/haormj/log?status.svg)](https://godoc.org/github.com/haormj/log) [![Go Report Card](https://goreportcard.com/badge/github.com/haormj/log)](https://goreportcard.com/report/github.com/haormj/log)
A simple go log.
## Install
```shell
go get github.com/haormj/log
```## Usage
```go
package mainimport (
"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