code.vegaprotocol.io/vega@v0.79.0/libs/zap/config_windows.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 //go:build windows 17 18 package zap 19 20 import ( 21 "fmt" 22 "net/url" 23 "os" 24 25 "go.uber.org/zap" 26 ) 27 28 func init() { 29 if err := zap.RegisterSink("winfile", newWinFileSink); err != nil { 30 panic(fmt.Errorf("couldn't register the windows file sink: %w", err)) 31 } 32 } 33 34 func toOSFilePath(logPath string) string { 35 return "winfile:///" + logPath 36 } 37 38 // newWinFileSink creates a log sink on Windows machines as zap, by default, 39 // doesn't support Windows paths. A workaround is to create a fake winfile 40 // scheme and register it with zap instead. This workaround is taken from 41 // the GitHub issue at https://github.com/uber-go/zap/issues/621. 42 func newWinFileSink(u *url.URL) (zap.Sink, error) { 43 // Remove leading slash left by url.Parse(). 44 return os.OpenFile(u.Path[1:], os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o644) //nolint:gomnd 45 }