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.
This commit is contained in:
Waldemar Zimpel 2024-10-25 04:20:22 +02:00
parent 0e0ca8721e
commit 028ff82683
2 changed files with 17 additions and 2 deletions

View file

@ -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())

View file

@ -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