Skip to content

Windows paths not supported by default file sink #621

Open
@Apeopex

Description

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:///" (golang/go#6027 (comment)) does not work as expected. (Ref: golang/go#13276 )

zap/sink.go

Line 99 in ff33455

u, err := url.Parse(rawURL)

Ref: golang/go#13276 (comment)
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")},
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions