https://github.com/uptutu/log
Uber-go/Zap wrapper , make log easily.
https://github.com/uptutu/log
go log
Last synced: about 1 year ago
JSON representation
Uber-go/Zap wrapper , make log easily.
- Host: GitHub
- URL: https://github.com/uptutu/log
- Owner: uptutu
- Created: 2021-07-02T09:37:08.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-08T10:23:09.000Z (almost 5 years ago)
- Last Synced: 2025-04-04T18:47:36.935Z (over 1 year ago)
- Topics: go, log
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Log
## Introduction
Wrap Uber-go /Zap make log easily.
## Installation
```shell
go get github.com/uptutu/log
```
## Usage
Easy way to use. This `New()` will set working directory as default config to this `logger` save log info.
```go
import (
"github.uptutu/log"
)
func main() {
log.New()
log.Info("xxxxx")
log.Debug("xxxxx")
}
```
Edit the config as you want, `Config` field is `uber-go/Zap` config, ArchConf as you want, if set `nil` to this field
then
`logger` disable archive.
```go
import (
"github.uptutu/log"
)
func main() {
conf := log.NewDefaultConfig()
conf.ArchConf = nil
log.NewLogger(conf)
log.Info("xxxxx")
log.Debug("xxxxx")
}
```
default config info:
```go
zap.Config{
Level: NewAtomicLevelAt(DebugLevel),
Development: true,
Encoding: "console",
EncoderConfig: NewDevelopmentEncoderConfig(),
OutputPaths: []string{"stderr"},
ErrorOutputPaths: []string{"stderr"},
}
zapcore.EncoderConfig{
TimeKey: "timestamp",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
FunctionKey: zapcore.OmitKey,
MessageKey: "content",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
}
ArchiveConfig{
LogFileDir: "", // Default will change this "" to Working directory
ErrorFileName: "error.log",
WarnFileName: "warn.log",
InfoFileName: "info.log",
DebugFileName: "debug.log",
MaxSize: 11,
MaxBackups: 10,
MaxAge: 30,
Compress: false,
}
```
When you already `New()` that config was build a `logger` register to `Zap`
you can use `zap.L()` get this `logger` by `zap` or get this by this package `log.Get()`
```go
import (
"github.uptutu/log"
)
func main() {
conf := log.NewDefaultConfig()
conf.ArchConf = nil
log.NewLogger(conf)
log.Get().Info("xxxxx")
log.Get().Debug("xxxxx)
}
```