interagent / pliny

An opinionated toolkit for writing excellent APIs in Ruby.
MIT License
801 stars 73 forks source link

Ensure all strings with spaces are quoted in logs #332

Closed bensymonds closed 4 years ago

bensymonds commented 4 years ago

The current logic covers the case when the log data is already a String instance, but not when the data is some other object that, when interpolated into the log string, results in a string containing spaces.

The example that led me here is where an exception is logged and the exception's message contains spaces. The exception gets interpolated into the string and has to_s called on it. Exception#to_s returns the message, so the message (with its spaces) go into the log line, but it's bypassed the logic that adds quotes.

See the commits for more details. I slipped in a few cleanups and added some tests too.

bensymonds commented 4 years ago

@stevenharman Thanks for the review. FYI I amended the last commit to add a changelog entry. I'm going to go ahead and merge this. I actually have another PR I want to open, but after that I'll be bugging you for a release 😄