mirror of
https://github.com/minio/minio.git
synced 2025-11-29 05:19:03 -05:00
Refactor logger (#3924)
This patch fixes below * Previously fatalIf() never writes log other than first logging target. * quiet flag is not honored to show progress messages other than startup messages. * Removes console package usage for progress messages.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Minio Cloud Storage (C) 2015 Minio, Inc.
|
||||
* Minio Cloud Storage (C) 2015, 2016, 2017 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,48 +17,15 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Tests callerSource.
|
||||
func TestCallerSource(t *testing.T) {
|
||||
currentSource := func() string { return callerSource() }
|
||||
// Tests getSource().
|
||||
func TestGetSource(t *testing.T) {
|
||||
currentSource := func() string { return getSource() }
|
||||
gotSource := currentSource()
|
||||
expectedSource := "[logger_test.go:31:TestCallerSource()]"
|
||||
expectedSource := "[logger_test.go:26:TestGetSource()]"
|
||||
if gotSource != expectedSource {
|
||||
t.Errorf("expected : %s, got : %s", expectedSource, gotSource)
|
||||
}
|
||||
}
|
||||
|
||||
// Tests error logger.
|
||||
func TestLogger(t *testing.T) {
|
||||
var buffer bytes.Buffer
|
||||
var fields logrus.Fields
|
||||
testLog := logrus.New()
|
||||
testLog.Out = &buffer
|
||||
testLog.Formatter = new(logrus.JSONFormatter)
|
||||
log.mu.Lock()
|
||||
log.loggers = append(log.loggers, testLog)
|
||||
log.mu.Unlock()
|
||||
|
||||
errorIf(errors.New("Fake error"), "Failed with error.")
|
||||
err := json.Unmarshal(buffer.Bytes(), &fields)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if fields["level"] != "error" {
|
||||
t.Fatalf("Expected error, got %s", fields["level"])
|
||||
}
|
||||
msg, ok := fields["cause"]
|
||||
if !ok {
|
||||
t.Fatal("Cause field missing")
|
||||
}
|
||||
if msg != "Fake error" {
|
||||
t.Fatal("Cause field has unexpected message", msg)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user