volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.66k stars 539 forks source link

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

Open natdm opened 5 years ago

natdm commented 5 years ago

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

aarondl commented 5 years ago

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.

natdm commented 5 years ago

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(), orzap.Logger.Sugar(), and then can be written to with formatted lines.

aarondl commented 5 years ago

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