diff --git a/CHANGELOG.md b/CHANGELOG.md index 420f74c..6f50623 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ Please choose versions by [Semantic Versioning](http://semver.org/). * MINOR version when you add functionality in a backwards-compatible manner, and * PATCH version when you make backwards-compatible bug fixes. +## Unreleased + +- fix: `memoryMonitor.LogMemoryUsage`, `logLevelSetter.Set` and `logLevelSetter.resetLogLevel` now use `libtime` instead of stdlib `time`, matching the convention `log_sampler-time.go` already documents ("uses github.com/bborbe/time for consistent time handling across the library"). All three drive time-threshold logic — log-if-interval-elapsed and auto-reset-after-duration — which could not be exercised deterministically against a frozen clock. The reset check uses `libtime.Now().Sub(lastSetTime)` rather than `time.Since(lastSetTime)`, so both the write and the read of `lastSetTime` come from the same clock. + ## v1.6.20 - update Go to 1.26.5 and update dependencies diff --git a/log_memory-monitor.go b/log_memory-monitor.go index 1c27f1d..597665f 100644 --- a/log_memory-monitor.go +++ b/log_memory-monitor.go @@ -10,6 +10,7 @@ import ( "sync" "time" + libtime "github.com/bborbe/time" "github.com/golang/glog" ) @@ -43,7 +44,7 @@ func (m *memoryMonitor) LogMemoryUsage(name string) { m.mutex.Lock() defer m.mutex.Unlock() - now := time.Now() + now := libtime.Now() // Check if enough time has passed since last log if m.lastLogTime.IsZero() || now.Sub(m.lastLogTime) >= m.logInterval { diff --git a/log_set-loglevel-setter.go b/log_set-loglevel-setter.go index 4b69352..2004752 100644 --- a/log_set-loglevel-setter.go +++ b/log_set-loglevel-setter.go @@ -11,6 +11,7 @@ import ( "sync" "time" + libtime "github.com/bborbe/time" "github.com/golang/glog" ) @@ -69,7 +70,7 @@ func (l *logLevelSetter) Set(ctx context.Context, logLevel glog.Level) error { l.mux.Lock() defer l.mux.Unlock() - l.lastSetTime = time.Now() + l.lastSetTime = libtime.Now() l.currentLogLevel = logLevel _ = flag.Set("v", strconv.Itoa(int(logLevel))) @@ -90,7 +91,7 @@ func (l *logLevelSetter) resetLogLevel() { l.mux.Lock() defer l.mux.Unlock() - if time.Since(l.lastSetTime) <= l.autoResetDuration { + if libtime.Now().Sub(l.lastSetTime) <= l.autoResetDuration { glog.V(l.defaultLoglevel).Infof("time since lastSet is too short => skip reset loglevel") return }