ozzo-dbx
ozzo-dbx copied to clipboard
Formatting of `[]byte` in Query.logSQL()
I'm not sure what the ins and outs are for everyone here, but a problem I'm encountering with SQL logging in ozzo is that it logs byte slices as raw bytes. For certain values, this will corrupt the terminal when I cat
the log files. By changing line 87 from
strings.Replace(string(bs), ...
to
"0x" + hex.EncodeToString(bs)
my logs are far less troublesome.
Any opinions on making this change to ozzo?
Go for it! As the comment buttresses it's only logging and one should really not parse it's outcome to an extend that depends on the content of binary fields.
@kPshi Any opinion on serialization format? I'm using hex since that's how my query tool displays binary fields. Base64 would be more compact though.
As you seem to be ambitious: how about extracting the logSQL function into an own field (maybe named SQLFormatFunc) of the Query struct? That would allow to change the format per project.
Personally I'd prefer hex as default format, though, as that makes bytes more readable (you see e.g. a zero terminated field within binary data easily). A sophisticated format might be like hexdump -C prints it with non-US-ASCII bytes replaced by periods on the right and hex on the left.
That might be left to individual formatting functions, of course.
If you're going to extract the func as a field, I'd suggest to set the default to your new format and also prepare a copy of the legacy function if anyone depends on that (what I do not expect, but "should" is none of my favourite words in IT. ;-) )
Does @qiangxue have an opinion on this?