From 028ff82683ec0b99c71da0e7a9cd42eb82c838a7 Mon Sep 17 00:00:00 2001 From: Waldemar Zimpel Date: Fri, 25 Oct 2024 04:20:22 +0200 Subject: [PATCH] Optionally enable local time for logging Introduces the option `-log-local-time` which switches to local time for logging instead of using UTC. Also if this option is applied, a message is being output to the log on startup about the usage of local time to draw attention, so the user/operator can take care of anonymity in case the logs are going to be shared. --- proxy/lib/pt_event_logger.go | 9 ++++++++- proxy/main.go | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/proxy/lib/pt_event_logger.go b/proxy/lib/pt_event_logger.go index 04c71ba..a661234 100644 --- a/proxy/lib/pt_event_logger.go +++ b/proxy/lib/pt_event_logger.go @@ -10,7 +10,7 @@ import ( ) func NewProxyEventLogger(output io.Writer, disableStats bool) event.SnowflakeEventReceiver { - logger := log.New(output, "", log.LstdFlags|log.LUTC) + logger := log.New(output, "", log.Flags()) return &proxyEventLogger{logger: logger, disableStats: disableStats} } @@ -21,6 +21,13 @@ type proxyEventLogger struct { func (p *proxyEventLogger) OnNewSnowflakeEvent(e event.SnowflakeEvent) { switch e.(type) { + case event.EventOnProxyStarting: + p.logger.Println(e.String()) + + if p.logger.Flags()&log.LUTC == 0 { + p.logger.Println("Local time is being used for logging. If you want to " + + "share your log, consider to modify the date/time for more anonymity.") + } case event.EventOnProxyStats: if !p.disableStats { p.logger.Println(e.String()) diff --git a/proxy/main.go b/proxy/main.go index 2b08b8b..12093da 100644 --- a/proxy/main.go +++ b/proxy/main.go @@ -27,6 +27,7 @@ func main() { logFilename := flag.String("log", "", "log `filename`. If not specified, logs will be output to stderr (console).") rawBrokerURL := flag.String("broker", sf.DefaultBrokerURL, "The `URL` of the broker server that the proxy will be using to find clients") unsafeLogging := flag.Bool("unsafe-logging", false, "keep IP addresses and other sensitive info in the logs") + logLocalTime := flag.Bool("log-local-time", false, "Use local time for logging (default: UTC)") keepLocalAddresses := flag.Bool("keep-local-addresses", false, "keep local LAN address ICE candidates.\nThis is usually pointless because Snowflake clients don't usually reside on the same local network as the proxy.") defaultRelayURL := flag.String("relay", sf.DefaultRelayURL, "The default `URL` of the server (relay) that this proxy will forward client connections to, in case the broker itself did not specify the said URL") probeURL := flag.String("nat-probe-server", sf.DefaultNATProbeURL, "The `URL` of the server that this proxy will use to check its network NAT type.\nDetermining NAT type helps to understand whether this proxy is compatible with certain clients' NAT") @@ -115,7 +116,14 @@ func main() { var logOutput = io.Discard var eventlogOutput io.Writer = os.Stderr - log.SetFlags(log.LstdFlags | log.LUTC) + + loggerFlags := log.LstdFlags + + if !*logLocalTime { + loggerFlags |= log.LUTC + } + + log.SetFlags(loggerFlags) if *verboseLogging { logOutput = os.Stderr