Skip to content

Commit c2e367a

Browse files
committed
[core] Fill out logrus fields
1 parent 42c2de7 commit c2e367a

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

common/logger/infologger/directhook.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ import (
2828
"errors"
2929
"fmt"
3030
"net"
31+
"os"
32+
"os/user"
3133
"runtime"
3234
"sort"
3335
"strconv"
3436
"strings"
37+
"time"
3538

3639
"github.com/sirupsen/logrus"
3740
)
3841

42+
func newUnixTimestamp() string {
43+
return fmt.Sprintf("%f", float64(time.Now().UnixNano())/1e9)
44+
}
3945

4046
type sender struct {
4147
stream net.Conn
@@ -133,9 +139,14 @@ func (h *DirectHook) Fire(e *logrus.Entry) error {
133139
// Severity, Level, ErrorCode, SourceFile, SourceLine,
134140
// Facility, Role, System, Detector, Partition, Run
135141
// Filled automatically by InfoLogger, do not set: PID, hostName, userName
136-
137142
payload := make(map[string]string)
138143
payload["severity"] = logrusLevelToInfoLoggerSeverity(e.Level)
144+
payload["timestamp"] = newUnixTimestamp()
145+
hostname, _ := os.Hostname()
146+
payload["hostname"] = hostname
147+
payload["pid"] = fmt.Sprintf("%d",os.Getpid())
148+
unixUser, _ := user.Current()
149+
payload["username"] = unixUser.Name
139150

140151
if e.HasCaller() {
141152
payload["errsource"] = e.Caller.File

0 commit comments

Comments
 (0)