Skip to content

Commit

Permalink
switch to walltime()
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Jul 2, 2024
1 parent 955af57 commit 87f6384
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
12 changes: 4 additions & 8 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ func (l *Logger) header(level Level) *Entry {
}
switch l.TimeFormat {
case "":
sec, nsec, _ := now()
sec, nsec := walltime()
var tmp [32]byte
var buf []byte
if offset == 0 {
Expand Down Expand Up @@ -561,7 +561,7 @@ func (l *Logger) header(level Level) *Entry {
// append to e.buf
e.buf = append(e.buf, buf...)
case TimeFormatUnix:
sec, _, _ := now()
sec, _ := walltime()
// 1595759807
var tmp [10]byte
// seconds
Expand All @@ -587,7 +587,7 @@ func (l *Logger) header(level Level) *Entry {
// append to e.buf
e.buf = append(e.buf, tmp[:]...)
case TimeFormatUnixMs:
sec, nsec, _ := now()
sec, nsec := walltime()
// 1595759807105
var tmp [13]byte
// milli seconds
Expand Down Expand Up @@ -619,7 +619,7 @@ func (l *Logger) header(level Level) *Entry {
// append to e.buf
e.buf = append(e.buf, tmp[:]...)
case TimeFormatUnixWithMs:
sec, nsec, _ := now()
sec, nsec := walltime()
// 1595759807.105
var tmp [14]byte
// milli seconds
Expand Down Expand Up @@ -2362,10 +2362,6 @@ func wlprintf(w Writer, level Level, format string, args ...any) (int, error) {

func b2s(b []byte) string { return *(*string)(unsafe.Pointer(&b)) }

//go:noescape
//go:linkname now time.now
func now() (sec int64, nsec int32, mono int64)

//go:noescape
//go:linkname absDate time.absDate
func absDate(abs uint64, full bool) (year int, month time.Month, day int, yday int)
Expand Down
4 changes: 2 additions & 2 deletions tsv.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (l *TSVLogger) New() (e *TSVEntry) {
// Timestamp adds the current time as UNIX timestamp
func (e *TSVEntry) Timestamp() *TSVEntry {
var tmp [11]byte
sec, _, _ := now()
sec, _ := walltime()
// separator
tmp[10] = e.sep
// seconds
Expand Down Expand Up @@ -78,7 +78,7 @@ func (e *TSVEntry) Timestamp() *TSVEntry {
// TimestampMS adds the current time with milliseconds as UNIX timestamp
func (e *TSVEntry) TimestampMS() *TSVEntry {
var tmp [14]byte
sec, nsec, _ := now()
sec, nsec := walltime()
// separator
tmp[13] = e.sep
// milli seconds
Expand Down
2 changes: 1 addition & 1 deletion xid.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var nilXID XID

// NewXID generates a globally unique XID
func NewXID() XID {
sec, _, _ := now()
sec, _ := walltime()
return NewXIDWithTime(sec)
}

Expand Down

0 comments on commit 87f6384

Please sign in to comment.