Browse Source

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

Closes #6146
pull/6181/head
mergify[bot] 4 years ago
committed by GitHub
parent
commit
28ce355656
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 6 deletions
  1. +2
    -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

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -22,6 +22,8 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
### IMPROVEMENTS ### IMPROVEMENTS
- [libs/log] \#6174 Include timestamp (`ts` field; `time.RFC3339Nano` format) in JSON logger output (@melekes)
### BUG FIXES ### BUG FIXES
- [ABCI] \#6124 Fixes a panic condition during callback execution in `ReCheckTx` during high tx load. (@alexanderbez) - [ABCI] \#6124 Fixes a panic condition during callback execution in `ReCheckTx` during high tx load. (@alexanderbez)

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

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


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

@ -58,7 +58,7 @@ func TestVariousLevels(t *testing.T) {
tc := tc tc := tc
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
var buf bytes.Buffer 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.Debug("here", "this is", "debug log")
logger.Info("here", "this is", "info log") logger.Info("here", "this is", "info log")
@ -74,7 +74,7 @@ func TestVariousLevels(t *testing.T) {
func TestLevelContext(t *testing.T) { func TestLevelContext(t *testing.T) {
var buf bytes.Buffer var buf bytes.Buffer
logger := log.NewTMJSONLogger(&buf)
logger := log.NewTMJSONLoggerNoTS(&buf)
logger = log.NewFilter(logger, log.AllowError()) logger = log.NewFilter(logger, log.AllowError())
logger = logger.With("context", "value") logger = logger.With("context", "value")
@ -96,7 +96,7 @@ func TestLevelContext(t *testing.T) {
func TestVariousAllowWith(t *testing.T) { func TestVariousAllowWith(t *testing.T) {
var buf bytes.Buffer var buf bytes.Buffer
logger := log.NewTMJSONLogger(&buf)
logger := log.NewTMJSONLoggerNoTS(&buf)
logger1 := log.NewFilter(logger, log.AllowError(), log.AllowInfoWith("context", "value")) logger1 := log.NewFilter(logger, log.AllowError(), log.AllowInfoWith("context", "value"))
logger1.With("context", "value").Info("foo", "bar", "baz") 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 // w.Write. The passed Writer must be safe for concurrent use by multiple
// goroutines if the returned Logger will be used concurrently. // goroutines if the returned Logger will be used concurrently.
func NewTMJSONLogger(w io.Writer) Logger { 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) { func TestTracingLogger(t *testing.T) {
var buf bytes.Buffer var buf bytes.Buffer
logger := log.NewTMJSONLogger(&buf)
logger := log.NewTMJSONLoggerNoTS(&buf)
logger1 := log.NewTracingLogger(logger) logger1 := log.NewTracingLogger(logger)
err1 := errors.New("courage is grace under pressure") err1 := errors.New("courage is grace under pressure")


Loading…
Cancel
Save