Skip to content

Commit 584cb8d

Browse files
committed
[core] Move NewUnixTimestamp to common/utils
1 parent cf3eda7 commit 584cb8d

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

common/logger/infologger/directhook.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
"sort"
3535
"strconv"
3636
"strings"
37-
"time"
3837

38+
"github.com/AliceO2Group/Control/common/utils"
3939
"github.com/sirupsen/logrus"
4040
)
4141

@@ -62,10 +62,6 @@ func init() {
6262
hostname = strings.Split(hostname, ".")[0]
6363
}
6464

65-
func newUnixTimestamp() string {
66-
return fmt.Sprintf("%f", float64(time.Now().UnixNano())/1e9)
67-
}
68-
6965
type sender struct {
7066
stream net.Conn
7167
}
@@ -164,7 +160,7 @@ func (h *DirectHook) Fire(e *logrus.Entry) error {
164160
// Filled automatically by InfoLogger, do not set: PID, hostName, userName
165161
payload := make(map[string]string)
166162
payload["severity"] = logrusLevelToInfoLoggerSeverity(e.Level)
167-
payload["timestamp"] = newUnixTimestamp()
163+
payload["timestamp"] = utils.NewUnixTimestamp()
168164
payload["hostname"] = hostname
169165
payload["pid"] = pid
170166
payload["username"] = username

common/utils/utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@
2525
package utils
2626

2727
import (
28+
"fmt"
2829
"io"
2930
"os"
3031
"strings"
32+
"time"
3133
)
3234

35+
func NewUnixTimestamp() string {
36+
// User for IL direct hook and scheduler.go
37+
return fmt.Sprintf("%f", float64(time.Now().UnixNano())/1e9)
38+
}
39+
3340
func IsDirEmpty(path string) (bool, error) {
3441
dir, err := os.Open(path)
3542
if err != nil {

0 commit comments

Comments
 (0)