google / fscrypt

Go tool for managing Linux filesystem encryption
Apache License 2.0
900 stars 98 forks source link

`log` usages complicates using as a library #302

Open directionless opened 3 years ago

directionless commented 3 years ago

Hi! In the vein of #175 I was playing with fscrypt as a library to get information about a directory. One thing I noticed, is a bunch of debugging oriented logging. To disable it, I ended up wrapping my calls to fscrypt with:

    origLog := log.Writer()
    defer func() {
        log.SetOutput(origLog)
    }()

But that feels a bit messy? I'm not sure if y'all have any thoughts about this, but I wanted to mention it as a small annoyance.

josephlr commented 3 years ago

Ughhhhhh, I hate that Go's builtin logging doesn't have proper FATAL/ERROR/WARNING/INFO/DEBUG leveled logging.

Maybe we could switch to a better framework, unfortunately there seem to be multiple.

josephlr commented 3 years ago

So the options are:

directionless commented 3 years ago

It's the globals part that's so painful...

For what it's worth, I use github.com/go-kit/kit/log. The general pattern I have is that my New methods either take a logger, or I embed one in the context. Then all the library functions can call that, and the main routine can initialize it however it likes.

I'm curious about go.uber.org/zap, I see that in a couple of places.