zap: Windows paths not supported by default file sink

When using absolute Windows paths, url.Parse does not retreieve the “file” scheme.

panic: couldn't open sink "C:\\Users\\...\\AppData\\Roaming\\...\\info.log.json": no sink found for scheme "c"

Appending, “file:///” (https://github.com/golang/go/issues/6027#issuecomment-66083310) does not work as expected. (Ref: https://github.com/golang/go/issues/13276 )

https://github.com/uber-go/zap/blob/ff33455a0e382e8a81d14dd7c922020b6b5e7982/sink.go#L99

Ref: https://github.com/golang/go/issues/13276#issuecomment-157074191 Changed by PR: #606

Temporary workaround:

func newWinFileSink(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("winfile", newWinFileSink)
zap.Config{
    OutputPaths: []string{"stdout", "winfile:///" + filepath.Join(GlobalConfigDir.Path, "info.log.json")},
}

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 25
  • Comments: 15

Commits related to this issue

Most upvoted comments

@Mario-Hofstaetter Unfortunately, this has been a pretty low priority issue because we don’t use Windows at work, and none of the active maintainers have Windows machines at home to be able to debug and fix this.

My feeling is that is that some mix of filepath.ToSlash/FromSlash will help solve this (I made an attempt in #999 last year), but the edit-test-debug loop was slow enough that I stopped trying.

@Mario-Hofstaetter Unfortunately, this has been a pretty low priority issue because we don’t use Windows at work, and none of the active maintainers have Windows machines at home to be able to debug and fix this.

My feeling is that is that some mix of filepath.ToSlash/FromSlash will help solve this (I made an attempt in #999 last year), but the edit-test-debug loop was slow enough that I stopped trying.

I understand that this issue is low-priority since you never use Windows at work. Golang is shipped with cross-platform ability, this issue really make users exhausted.

Dear maintainers, 3 years later this issue is still open and is breaking logging in https://github.com/open-telemetry/opentelemetry-collector

Is there any workaround yet that does not involve source changes? (which is not possible because we use otelcol release)

PR #624 was unfortunately never finished.