mirror of
https://github.com/minio/minio.git
synced 2025-07-08 08:32:18 -04:00
simplify logger time and avoid possible crashes (#13986)
time.Format() is not necessary prematurely for JSON marshalling, since JSON marshalling indeed defaults to RFC3339Nano. This also ensures the 'time' is remembered until its logged and it is the same time when the 'caller' invoked 'log' functions.
This commit is contained in:
parent
5a96cbbeaa
commit
9ad6012782
@ -147,7 +147,7 @@ func GetAuditEntry(ctx context.Context) *audit.Entry {
|
||||
r = &audit.Entry{
|
||||
Version: audit.Version,
|
||||
DeploymentID: globalDeploymentID,
|
||||
Time: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
Time: time.Now().UTC(),
|
||||
}
|
||||
SetAuditEntry(ctx, r)
|
||||
return r
|
||||
|
@ -80,7 +80,7 @@ func (f fatalMsg) json(msg string, args ...interface{}) {
|
||||
logJSON, err := json.Marshal(&log.Entry{
|
||||
Level: FatalLvl.String(),
|
||||
Message: message,
|
||||
Time: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
Time: time.Now().UTC(),
|
||||
Trace: &log.Trace{Message: message, Source: []string{getSource(6)}},
|
||||
})
|
||||
if err != nil {
|
||||
@ -159,7 +159,7 @@ func (i infoMsg) json(msg string, args ...interface{}) {
|
||||
logJSON, err := json.Marshal(&log.Entry{
|
||||
Level: InformationLvl.String(),
|
||||
Message: message,
|
||||
Time: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
Time: time.Now().UTC(),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -192,7 +192,7 @@ func (i errorMsg) json(msg string, args ...interface{}) {
|
||||
logJSON, err := json.Marshal(&log.Entry{
|
||||
Level: ErrorLvl.String(),
|
||||
Message: message,
|
||||
Time: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
Time: time.Now().UTC(),
|
||||
Trace: &log.Trace{Message: message, Source: []string{getSource(6)}},
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -349,7 +349,7 @@ func logIf(ctx context.Context, err error, errKind ...interface{}) {
|
||||
Host: req.Host,
|
||||
RequestID: req.RequestID,
|
||||
UserAgent: req.UserAgent,
|
||||
Time: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
Time: time.Now().UTC(),
|
||||
API: &log.API{
|
||||
Name: API,
|
||||
Args: &log.Args{
|
||||
|
@ -33,7 +33,7 @@ const Version = "1"
|
||||
type Entry struct {
|
||||
Version string `json:"version"`
|
||||
DeploymentID string `json:"deploymentid,omitempty"`
|
||||
Time string `json:"time"`
|
||||
Time time.Time `json:"time"`
|
||||
Trigger string `json:"trigger"`
|
||||
API struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
@ -61,7 +61,7 @@ func NewEntry(deploymentID string) Entry {
|
||||
return Entry{
|
||||
Version: Version,
|
||||
DeploymentID: deploymentID,
|
||||
Time: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
Time: time.Now().UTC(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,10 @@
|
||||
|
||||
package log
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Args - defines the arguments for the API.
|
||||
type Args struct {
|
||||
@ -44,7 +47,7 @@ type Entry struct {
|
||||
DeploymentID string `json:"deploymentid,omitempty"`
|
||||
Level string `json:"level"`
|
||||
LogKind string `json:"errKind"`
|
||||
Time string `json:"time"`
|
||||
Time time.Time `json:"time"`
|
||||
API *API `json:"api,omitempty"`
|
||||
RemoteHost string `json:"remotehost,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio/internal/color"
|
||||
"github.com/minio/minio/internal/logger"
|
||||
@ -81,7 +80,9 @@ func (c *Target) Send(e interface{}, logKind string) error {
|
||||
}
|
||||
}
|
||||
|
||||
apiString := "API: " + entry.API.Name + "("
|
||||
var apiString string
|
||||
if entry.API != nil {
|
||||
apiString = "API: " + entry.API.Name + "("
|
||||
if entry.API.Args != nil && entry.API.Args.Bucket != "" {
|
||||
apiString = apiString + "bucket=" + entry.API.Args.Bucket
|
||||
}
|
||||
@ -89,7 +90,10 @@ func (c *Target) Send(e interface{}, logKind string) error {
|
||||
apiString = apiString + ", object=" + entry.API.Args.Object
|
||||
}
|
||||
apiString += ")"
|
||||
timeString := "Time: " + time.Now().Format(logger.TimeFormat)
|
||||
} else {
|
||||
apiString = "INTERNAL"
|
||||
}
|
||||
timeString := "Time: " + entry.Time.Format(logger.TimeFormat)
|
||||
|
||||
var deploymentID string
|
||||
if entry.DeploymentID != "" {
|
||||
|
Loading…
x
Reference in New Issue
Block a user