Allow logging targets to be configured to receive minio (#8347)

specific errors, `application` errors or `all` by default.

console logging on server by default lists all logs -
enhance admin console API to accept `type` as query parameter to
subscribe to application/minio logs.
This commit is contained in:
poornas
2019-10-11 18:50:54 -07:00
committed by Harshavardhana
parent 8964ef821f
commit d7060c4c32
28 changed files with 116 additions and 72 deletions

View File

@@ -273,36 +273,53 @@ func hashString(input string) string {
return hex.EncodeToString(checksum)
}
// Kind specifies the kind of error log
type Kind string
const (
// Minio errors
Minio Kind = "MINIO"
// Application errors
Application Kind = "APPLICATION"
// All errors
All Kind = "ALL"
)
// LogAlwaysIf prints a detailed error message during
// the execution of the server.
func LogAlwaysIf(ctx context.Context, err error) {
func LogAlwaysIf(ctx context.Context, err error, errKind ...interface{}) {
if err == nil {
return
}
logIf(ctx, err)
logIf(ctx, err, errKind...)
}
// LogIf prints a detailed error message during
// the execution of the server, if it is not an
// ignored error.
func LogIf(ctx context.Context, err error) {
func LogIf(ctx context.Context, err error, errKind ...interface{}) {
if err == nil {
return
}
if err.Error() != diskNotFoundError {
logIf(ctx, err)
logIf(ctx, err, errKind...)
}
}
// logIf prints a detailed error message during
// the execution of the server.
func logIf(ctx context.Context, err error) {
func logIf(ctx context.Context, err error, errKind ...interface{}) {
if Disable {
return
}
logKind := string(Minio)
if len(errKind) > 0 {
if ek, ok := errKind[0].(Kind); ok {
logKind = string(ek)
}
}
req := GetReqInfo(ctx)
if req == nil {
@@ -330,6 +347,7 @@ func logIf(ctx context.Context, err error) {
entry := log.Entry{
DeploymentID: req.DeploymentID,
Level: ErrorLvl.String(),
LogKind: logKind,
RemoteHost: req.RemoteHost,
Host: req.Host,
RequestID: req.RequestID,
@@ -359,7 +377,7 @@ func logIf(ctx context.Context, err error) {
// Iterate over all logger targets to send the log entry
for _, t := range Targets {
t.Send(entry)
t.Send(entry, entry.LogKind)
}
}
@@ -368,9 +386,9 @@ var ErrCritical struct{}
// CriticalIf logs the provided error on the console. It fails the
// current go-routine by causing a `panic(ErrCritical)`.
func CriticalIf(ctx context.Context, err error) {
func CriticalIf(ctx context.Context, err error, errKind ...interface{}) {
if err != nil {
LogIf(ctx, err)
LogIf(ctx, err, errKind...)
panic(ErrCritical)
}
}