sqlboiler icon indicating copy to clipboard operation
sqlboiler copied to clipboard

Change log writing to a single statement (don't split query/args)

Open natdm opened this issue 6 years ago • 3 comments

What version of SQLBoiler are you using (sqlboiler --version)? 3

Running sql queries concurrently log the queries and arguments in random order eg:

SELECT WHERE...
SELECT WHERE...
[1212]
[1315]
SELECT WHERE ...
[1111]

Proposal: Safer concurrent logging and don't separate the query and the args

natdm avatar Mar 20 '19 16:03 natdm

You can replace the logger with whatever you'd like so long as it conforms to the io.Writer interface in order to make it goroutine safe: https://github.com/volatiletech/sqlboiler/blob/master/boil/global.go#L25

Not separating query and args could definitely be done but it will make it harder to see. Certainly you cannot put a newline between them in a log because some people may be using structured logging adapters that may not play nice with that sort of thing. Although maybe it'd be escaped. Open to suggestions here.

aarondl avatar Mar 20 '19 20:03 aarondl

I think it might be more about the fact that they make multiple writes at the same time (and can be done safely) but then they intertwine with each-other, making the logs useless to read since you don't know what is doing what with which arguments. Maybe the solution is to do something like sarama.Logger, which can easily be replaced with log.New(), or zap.Logger.Sugar(), and then can be written to with formatted lines.

natdm avatar Apr 17 '19 14:04 natdm

@natdm Still happy to accept a PR to merge these outputs into a single call to log.

aarondl avatar May 20 '19 20:05 aarondl