amberframework / granite

ORM Model with Adapters for mysql, pg, sqlite in the Crystal Language.
MIT License
296 stars 87 forks source link

Fix logging of query durations, which were off by 10x for µs precision #506

Open mloughran opened 3 weeks ago

mloughran commented 3 weeks ago

Has been broken since it was originally implemented in 3d73a5de.

Noticed while implementing a similar method in our own code. @Blacksmoke16 is something of this ilk (more readable short span printing) a candidate for stdlib do you think?

Blacksmoke16 commented 3 weeks ago

Dunno, are free to make an issue/thread suggesting it and see what others think.

robacarp commented 3 weeks ago

@mloughran @Blacksmoke16 I have the same code and bug in mosquito -- I'm sure I copied this stanza from Granite to Mosquito, or the reverse depending on the day.

mloughran commented 3 weeks ago

@robacarp ha, well that does support my case. There's some similar code in Clear (and I'm sure all sorts of other places), but thankfully this wasn't a copy-paste 😄

Given that the common use case seems to be logging, maybe there is an argument for handling Time::Span in log metadata. This however then raises the question of how the JSON logger should serialise spans (see https://github.com/crystal-lang/crystal/issues/11942). In any case this is all rather off-topic for this PR! I will consider some more and may open a crystal issue.