Skip to content

Instantly share code, notes, and snippets.

@voluntas
Created January 1, 2020 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voluntas/5b3fae58736012c5282d38ea2222fe64 to your computer and use it in GitHub Desktop.
Save voluntas/5b3fae58736012c5282d38ea2222fe64 to your computer and use it in GitHub Desktop.
package main
import (
"time"
"github.com/rs/zerolog"
"gopkg.in/natefinch/lumberjack.v2"
)
func main() {
zerolog.TimeFieldFormat = time.RFC3339Nano
writer := &lumberjack.Logger{
Filename: "test.log",
// メガバイト
MaxSize: 10,
MaxBackups: 5,
// 日
MaxAge: 1,
// デフォルトは無効
Compress: true,
}
log := zerolog.New(writer).With().Logger()
log.Log().
Timestamp().
Int("baz", 123).
Msg("hello world")
}
@voluntas
Copy link
Author

voluntas commented Jan 1, 2020

test.log にこんな感じで記録されていきます。

{"time":"2020-01-02T00:38:35.060001+09:00","baz":123,"message":"hello world"}
{"time":"2020-01-02T00:38:49.866742+09:00","baz":123,"message":"hello world"}
{"time":"2020-01-02T00:40:17.398441+09:00","baz":123,"message":"hello world"}
{"time":"2020-01-02T00:40:52.711166+09:00","baz":123,"message":"hello world"}
{"time":"2020-01-02T00:40:55.236672+09:00","baz":123,"message":"hello world"}
{"time":"2020-01-02T00:40:57.601786+09:00","baz":123,"message":"hello world"}
{"time":"2020-01-02T00:46:20.994704+09:00","baz":123,"message":"hello world"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment