Skip to content

Commit

Permalink
Work on logging of NTP values
Browse files Browse the repository at this point in the history
  • Loading branch information
marcfrei committed Apr 1, 2024
1 parent a0ca886 commit cf289bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions net/ntp/logging.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package ntp

import (
"log/slog"

"go.uber.org/zap/zapcore"
)

type Time32LogValuer struct {
T Time32
}

func (v Time32LogValuer) LogValue() slog.Value {
return slog.GroupValue(
slog.Uint64("Seconds", uint64(v.T.Seconds)),
slog.Uint64("Fraction", uint64(v.T.Fraction)))
}

type Time32Marshaler struct {
T Time32
}
Expand All @@ -14,6 +26,16 @@ func (m Time32Marshaler) MarshalLogObject(enc zapcore.ObjectEncoder) error {
return nil
}

type Time64LogValuer struct {
T Time64
}

func (v Time64LogValuer) LogValue() slog.Value {
return slog.GroupValue(
slog.Uint64("Seconds", uint64(v.T.Seconds)),
slog.Uint64("Fraction", uint64(v.T.Fraction)))
}

type Time64Marshaler struct {
T Time64
}
Expand Down
8 changes: 8 additions & 0 deletions timeservicex.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
package main

import (
"context"
"log/slog"
"time"

"example.com/scion-time/driver/clock"
"example.com/scion-time/net/ntp"
)

func runX() {
Expand All @@ -18,4 +20,10 @@ func runX() {
log.Debug("local clock", slog.Time("now", clk.Now()))
clk.Step(-1 * time.Second)
log.Debug("local clock", slog.Time("now", clk.Now()))

now64 := ntp.Time64FromTime(time.Now())
log.LogAttrs(context.Background(), slog.LevelDebug, "test",
slog.Any("now", now64))
log.LogAttrs(context.Background(), slog.LevelDebug, "test",
slog.Any("now", ntp.Time64LogValuer{T: now64}))
}

0 comments on commit cf289bd

Please sign in to comment.