mirror of
https://github.com/pgsty/minio.git
synced 2026-07-22 05:30:24 +03:00
logging: Log only for unhandled errors, remove all the debug logging. (#1652)
This patch brings in the removal of debug logging altogether, instead we bring in the functionality of being able to trace the errors properly pointing back to the origination of the problem. To enable tracing you need to enable "MINIO_TRACE" set to "1" or "true" environment variable which would print back traces whenever there is an error which is unhandled or at the handler layer. By default this tracing is turned off and only user level logging is provided.
This commit is contained in:
committed by
Anand Babu (AB) Periasamy
parent
8828fd1e5c
commit
9472299308
@@ -18,8 +18,10 @@ package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/minio/minio/pkg/probe"
|
||||
)
|
||||
|
||||
type fields map[string]interface{}
|
||||
@@ -41,38 +43,37 @@ type logger struct {
|
||||
}
|
||||
|
||||
// errorIf synonymous with fatalIf but doesn't exit on error != nil
|
||||
func errorIf(err error, msg string, fields logrus.Fields) {
|
||||
func errorIf(err error, msg string, data ...interface{}) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if fields == nil {
|
||||
fields = make(logrus.Fields)
|
||||
sysInfo := probe.GetSysInfo()
|
||||
fields := logrus.Fields{
|
||||
"cause": err.Error(),
|
||||
"type": reflect.TypeOf(err),
|
||||
"sysInfo": sysInfo,
|
||||
}
|
||||
fields["Error"] = struct {
|
||||
Cause string `json:"cause,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
}{
|
||||
err.Error(),
|
||||
reflect.TypeOf(err).String(),
|
||||
if globalTrace {
|
||||
stack := debug.Stack()
|
||||
fields["stack"] = string(stack)
|
||||
}
|
||||
log.WithFields(fields).Error(msg)
|
||||
log.WithFields(fields).Errorf(msg, data...)
|
||||
}
|
||||
|
||||
// fatalIf wrapper function which takes error and prints jsonic error messages.
|
||||
func fatalIf(err error, msg string, fields logrus.Fields) {
|
||||
func fatalIf(err error, msg string, data ...interface{}) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if fields == nil {
|
||||
fields = make(logrus.Fields)
|
||||
sysInfo := probe.GetSysInfo()
|
||||
fields := logrus.Fields{
|
||||
"cause": err.Error(),
|
||||
"type": reflect.TypeOf(err),
|
||||
"sysInfo": sysInfo,
|
||||
}
|
||||
|
||||
fields["Error"] = struct {
|
||||
Cause string `json:"cause,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
}{
|
||||
err.Error(),
|
||||
reflect.TypeOf(err).String(),
|
||||
if globalTrace {
|
||||
stack := debug.Stack()
|
||||
fields["stack"] = string(stack)
|
||||
}
|
||||
log.WithFields(fields).Fatal(msg)
|
||||
log.WithFields(fields).Fatalf(msg, data...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user