https://github.com/openpitrix/logger
Standard logger for OpenPitrix
https://github.com/openpitrix/logger
logger openpitrix
Last synced: 5 months ago
JSON representation
Standard logger for OpenPitrix
- Host: GitHub
- URL: https://github.com/openpitrix/logger
- Owner: openpitrix
- License: apache-2.0
- Created: 2018-10-17T08:29:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-20T05:33:40.000Z (over 7 years ago)
- Last Synced: 2024-10-28T17:37:46.778Z (over 1 year ago)
- Topics: logger, openpitrix
- Language: Go
- Homepage: https://godoc.org/openpitrix.io/logger
- Size: 34.2 KB
- Stars: 2
- Watchers: 10
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# logger for OpenPitrix
[](https://travis-ci.org/openpitrix/logger)
[](https://goreportcard.com/report/openpitrix.io/logger)
[](https://godoc.org/openpitrix.io/logger)
[](https://github.com/openpitrix/logger/blob/master/LICENSE)
## Install
1. Install Go1.11+
1. set `GO111MODULE=on`
1. `go get openpitrix.io/logger`
1. `go run hello.go`
## Example
```go
package main
import (
"bytes"
"context"
"fmt"
"openpitrix.io/logger"
"openpitrix.io/logger/ctxutil"
)
func main() {
logger.Infof(nil, "hello1 openpitrix")
logger.HideCallstack()
logger.Infof(nil, "hello2 openpitrix")
logger.ShowCallstack()
logger.Infof(nil, "hello3 openpitrix")
{
var buf bytes.Buffer
logger := logger.New().SetOutput(&buf)
logger.Infof(nil, "hello4 openpitrix")
logger.Infof(nil, "hello5 openpitrix\nlogger")
logger.Infof(nil, "")
fmt.Print(buf.String())
}
ctx := context.Background()
ctx = ctxutil.SetRequestId(ctx, "req-id-001")
logger.Infof(ctx, "hello context1")
ctx = ctxutil.SetMessageId(ctx, "msg-001", "msg-002")
logger.Infof(ctx, "hello context2")
ctx = ctxutil.ClearRequestId(ctx)
logger.Infof(ctx, "hello context3")
}
```
output:
```
2018-10-20 07:43:31.70066 -INFO- hello1 openpitrix (hello.go:19)
2018-10-20 07:43:31.70085 -INFO- hello2 openpitrix
2018-10-20 07:43:31.70086 -INFO- hello3 openpitrix (hello.go:25)
2018-10-20 07:43:31.70089 -INFO- hello4 openpitrix (hello.go:31)
2018-10-20 07:43:31.70091 -INFO- hello5 openpitrix\nlogger (hello.go:32)
2018-10-20 07:43:31.70093 -INFO- (hello.go:33)
2018-10-20 07:43:31.70096 -INFO- hello context1 (hello.go:41){@req-id-001}
2018-10-20 07:43:31.70099 -INFO- hello context2 (hello.go:44){msg-001|msg-002@req-id-001}
2018-10-20 07:43:31.70101 -INFO- hello context3 (hello.go:47){msg-001|msg-002@}
```