Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmd/influxd): Add logging work-around for absolute file paths on Windows #21540

Merged
merged 6 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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