Browse Source

libs/log: [JSON format] include timestamp (#6174)

Closes #6146
pull/6180/head
Anton Kaliaev 4 years ago
committed by GitHub
parent
commit
fc5a108d53
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 6 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +1
    -1
      libs/cli/flags/log_level_test.go
  3. +3
    -3
      libs/log/filter_test.go
  4. +10
    -1
      libs/log/tm_json_logger.go
  5. +1
    -1
      libs/log/tracing_logger_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -71,6 +71,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- [rpc/client/http] \#6163 Do not drop events even if the `out` channel is full (@melekes)
- [node] \#6059 Validate and complete genesis doc before saving to state store (@silasdavis)
- [state] \#6067 Batch save state data (@githubsands & @cmwaters)
- [libs/log] \#6174 Include timestamp (`ts` field; `time.RFC3339Nano` format) in JSON logger output (@melekes)
### BUG FIXES


+ 1
- 1
libs/cli/flags/log_level_test.go View File

@ -15,7 +15,7 @@ const (
func TestParseLogLevel(t *testing.T) {
var buf bytes.Buffer
jsonLogger := log.NewTMJSONLogger(&buf)
jsonLogger := log.NewTMJSONLoggerNoTS(&buf)
correctLogLevels := []struct {
lvl string


+ 3
- 3
libs/log/filter_test.go View File

@ -58,7 +58,7 @@ func TestVariousLevels(t *testing.T) {
tc := tc
t.Run(tc.name, func(t *testing.T) {
var buf bytes.Buffer
logger := log.NewFilter(log.NewTMJSONLogger(&buf), tc.allowed)
logger := log.NewFilter(log.NewTMJSONLoggerNoTS(&buf), tc.allowed)
logger.Debug("here", "this is", "debug log")
logger.Info("here", "this is", "info log")
@ -74,7 +74,7 @@ func TestVariousLevels(t *testing.T) {
func TestLevelContext(t *testing.T) {
var buf bytes.Buffer
logger := log.NewTMJSONLogger(&buf)
logger := log.NewTMJSONLoggerNoTS(&buf)
logger = log.NewFilter(logger, log.AllowError())
logger = logger.With("context", "value")
@ -96,7 +96,7 @@ func TestLevelContext(t *testing.T) {
func TestVariousAllowWith(t *testing.T) {
var buf bytes.Buffer
logger := log.NewTMJSONLogger(&buf)
logger := log.NewTMJSONLoggerNoTS(&buf)
logger1 := log.NewFilter(logger, log.AllowError(), log.AllowInfoWith("context", "value"))
logger1.With("context", "value").Info("foo", "bar", "baz")


+ 10
- 1
libs/log/tm_json_logger.go View File

@ -11,5 +11,14 @@ import (
// w.Write. The passed Writer must be safe for concurrent use by multiple
// goroutines if the returned Logger will be used concurrently.
func NewTMJSONLogger(w io.Writer) Logger {
return &tmLogger{kitlog.NewJSONLogger(w)}
logger := kitlog.NewJSONLogger(w)
logger = kitlog.With(logger, "ts", kitlog.DefaultTimestampUTC)
return &tmLogger{logger}
}
// NewTMJSONLoggerNoTS is the same as NewTMJSONLogger, but without the
// timestamp.
func NewTMJSONLoggerNoTS(w io.Writer) Logger {
logger := kitlog.NewJSONLogger(w)
return &tmLogger{logger}
}

+ 1
- 1
libs/log/tracing_logger_test.go View File

@ -15,7 +15,7 @@ import (
func TestTracingLogger(t *testing.T) {
var buf bytes.Buffer
logger := log.NewTMJSONLogger(&buf)
logger := log.NewTMJSONLoggerNoTS(&buf)
logger1 := log.NewTracingLogger(logger)
err1 := errors.New("courage is grace under pressure")


Loading…
Cancel
Save