Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send timestamp in micro #23

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ go 1.19

require (
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.2.2
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
7 changes: 6 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
9 changes: 6 additions & 3 deletions hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ func TestHook_Send(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
msg := fmt.Sprintf("%s (%s)", tc.name, t.Name())
tc.logfn(msg)
time.Sleep(time.Duration(1) * time.Second)
bulk, ok := mockHTTPServerMap[t.Name()]
assert.True(t, ok, "%s key not found in mockHTTPServerMap", t.Name())

var bulk *Bulk
assert.Eventually(t, func() (ok bool) {
bulk, ok = mockHTTPServerMap[t.Name()]
return ok
}, 5*time.Second, 1*time.Second, "%s key not found in mockHTTPServerMap", t.Name())

var msgExists bool
for _, entry := range bulk.LogEntries {
Expand Down
5 changes: 2 additions & 3 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ func GetTimeSync() (bool, float64) {
}

ServerTime = ServerTime / 1e4
LocalTime := float64(time.Now().Unix() * 1e3)
TimeDelta := ServerTime - LocalTime
TimeDelta := ServerTime - float64(time.Now().UnixMilli())

return true, TimeDelta
return true, TimeDelta * 1e3 // convert to microseconds, because log timestamp is in microseconds.
}

DebugLogger.Println("Can't get server time")
Expand Down
2 changes: 1 addition & 1 deletion manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (manager *LoggerManager) AddLogLine(Severity uint, Text interface{}, Catego
}

NewLogRecord := Log{
float64(time.Now().UnixMilli()) + manager.TimeDelta,
float64(time.Now().UnixMicro()) + manager.TimeDelta,
Severity,
MessageToString(Text),
Category,
Expand Down
9 changes: 6 additions & 3 deletions slog_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ func TestSlogHandler_Send(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
msg := fmt.Sprintf("%s (%s)", tc.name, t.Name())
tc.logfn(msg, attr)
time.Sleep(1 * time.Second)
bulk, ok := mockHTTPServerMap[t.Name()]
assert.True(t, ok, "%s key not found in mockHTTPServerMap", t.Name())

var bulk *Bulk
assert.Eventually(t, func() (ok bool) {
bulk, ok = mockHTTPServerMap[t.Name()]
return ok
}, 5*time.Second, 1*time.Second, "%s key not found in mockHTTPServerMap", t.Name())

var msgExists bool
for _, entry := range bulk.LogEntries {
Expand Down
Loading