-
Notifications
You must be signed in to change notification settings - Fork 572
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
Add base64 helper methods #613
base: master
Are you sure you want to change the base?
Conversation
Just realized there's the whole CBOR part of zerolog and it's behind a build flag. I tried adding support to that side, but not sure if it's correct. Apparently CBOR only has tags for standard padded base64 and unpadded url-safe base64, so maybe I should also drop the Custom method and just have standard and raw url methods |
I have an alternative proposal. As base64 does not make sense in cbor and we currently have a I don't really see a need for multiple types of encoding in structured logs in the same app and this would avoid cluttering the API. |
Hmm yeah that makes sense, will add that instead |
So I did that (#615), but while writing the test I realized that the default implementation actually checks that the input is valid unicode and replaces invalid runes with |
I can't remember doing that and it is certainly not expected. We may just go back to a basic hex encoding. |
Seems like |
It feels like a bad and confusing choice I did originally. I wonder if anyone is actually using this purposefully as I can't think about a use-case. |
I just noticed that I'm using it for stack traces in panic handlers like Anyway, I don't have strong opinions on how the API should be designed (and I'm not too attached to using |
I still prefer the parameter to setup the behavior or |
I often find myself wanting to output bytes as base64 instead of hex because base64 is more compact, and the
base64
cli command is easier to use thanxxd
. Having to write.Str("foo", base64.StdEncoding.EncodeToString(data))
isn't very nice though and it's not as efficient as encoding directly into the buffer.This PR adds
.Base64
and.Base64Custom
helper methods. The former just takes bytes and appends with standard padded base64, while the latter additionally takes abase64.Encoding
instance to allow all the other kinds (urlsafe and/or unpadded base64). I'm not completely sure if the Custom method is a good idea, so I can change that if needed. It might make sense to have an url-safe method instead, or just not have any other options than standard.