Skip to content

Commit

Permalink
fix(cmd/influxd): Add logging work-around for absolute file paths on …
Browse files Browse the repository at this point in the history
…Windows (#21540)
  • Loading branch information
danxmoran authored May 24, 2021
1 parent 251f43a commit b1e1125
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cmd/influxd/upgrade/logging_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build !windows

package upgrade

// Zap only has problems with Windows paths, so this is a no-op on Unix systems.
func (o *logOptions) zapSafeLogPath() (string, error) {
return o.logPath, nil
}
30 changes: 30 additions & 0 deletions cmd/influxd/upgrade/logging_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package upgrade

import (
"net/url"
"os"
"path/filepath"

"go.uber.org/zap"
)

// Work around a bug in zap's handling of absolute paths on Windows.
// See https://github.com/uber-go/zap/issues/621

const FakeWindowsScheme = "winfile"

func init() {
newWinFileSink := 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)
}
zap.RegisterSink(FakeWindowsScheme, newWinFileSink)
}

func (o *logOptions) zapSafeLogPath() (string, error) {
logPath, err := filepath.Abs(o.logPath)
if err != nil {
return "", err
}
return FakeWindowsScheme + ":///" + logPath, nil
}
8 changes: 6 additions & 2 deletions cmd/influxd/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,13 @@ func buildLogger(options *logOptions, verbose bool) (*zap.Logger, error) {
if verbose {
config.Level.SetLevel(zap.DebugLevel)
}
logPath, err := options.zapSafeLogPath()
if err != nil {
return nil, err
}

config.OutputPaths = append(config.OutputPaths, options.logPath)
config.ErrorOutputPaths = append(config.ErrorOutputPaths, options.logPath)
config.OutputPaths = append(config.OutputPaths, logPath)
config.ErrorOutputPaths = append(config.ErrorOutputPaths, logPath)

log, err := config.Build()
if err != nil {
Expand Down

0 comments on commit b1e1125

Please sign in to comment.