Skip to content
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

Formatting of []byte in Query.logSQL() #61

Open
BourgeoisBear opened this issue Mar 22, 2018 · 5 comments
Open

Formatting of []byte in Query.logSQL() #61

BourgeoisBear opened this issue Mar 22, 2018 · 5 comments

Comments

@BourgeoisBear
Copy link

BourgeoisBear commented Mar 22, 2018

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?

@kPshi
Copy link

kPshi commented Aug 1, 2018

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.

@BourgeoisBear
Copy link
Author

@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.

@kPshi
Copy link

kPshi commented Aug 1, 2018

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.

@kPshi
Copy link

kPshi commented Aug 1, 2018

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. ;-) )

@BourgeoisBear
Copy link
Author

Does @qiangxue have an opinion on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants