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
- fix for windows paths https://github.com/uber-go/zap/issues/621 — committed to awillis/sluus by awillis 5 years ago
- Fix panic on windows due to https://github.com/uber-go/zap/issues/621 — committed to giwty/switch-library-manager by deleted user 4 years ago
- Wrap Open error and update TestOpen to check for fs.ErrNotExist This is a prefactor for Windows support (#621). `TestOpen` currently relies on a hardcoded error "no such file or directory" if a file... — committed to prashantv/zap by prashantv 2 years ago
- Open: expose error cause, test for fs.ErrNotExist (#1149) This is a prefactor for Windows support (#621). TestOpen currently relies on a hardcoded error "no such file or directory" if a file is not... — committed to uber-go/zap by prashantv 2 years ago
@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 have pull a request in https://github.com/uber-go/zap/pull/624
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.