From 0ccae6b061d84759216715c645f448476a4fe16a Mon Sep 17 00:00:00 2001 From: Michal Niewrzal Date: Tue, 10 Sep 2019 02:35:59 -0700 Subject: [PATCH] cmd: windows log file workaround (#2979) --- pkg/process/logging.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/process/logging.go b/pkg/process/logging.go index 911d18156..634085677 100644 --- a/pkg/process/logging.go +++ b/pkg/process/logging.go @@ -5,6 +5,7 @@ package process import ( "flag" + "net/url" "os" "runtime" @@ -32,6 +33,17 @@ var ( logOutput = flag.String("log.output", "stderr", "can be stdout, stderr, or a filename") ) +func init() { + winFileSink := func(u *url.URL) (zap.Sink, error) { + // Remove leading slash left by url.Parse() + return os.OpenFile(u.Path[1:], os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) + } + err := zap.RegisterSink("winfile", winFileSink) + if err != nil { + panic("Unable to register winfile sink: " + err.Error()) + } +} + func isDev() bool { return cfgstruct.DefaultsType() != "release" } func newLogger() (*zap.Logger, error) {