Pathoschild / SMAPI

The modding API for Stardew Valley.
https://smapi.io/
GNU Lesser General Public License v3.0
1.71k stars 258 forks source link

Implement the InterpolatedStringHandler pattern for verbose logging #914

Closed atravita-mods closed 6 months ago

atravita-mods commented 9 months ago

Hi Pathos!

This is just a quick little pull request that implements the new-to-net-6 InterpolatedStringHandler pattern for verbose logging. This way, .Monitor.VerboseLog($"any string interpolation {whatever}"} won't have the string interpolation evaluated UNLESS verbose logging is enabled.

It's fully backwards compatible and will require no changes from mod authors. If a mod isn't recompiled for this change, it'll just use the string overload, and if the mod is recompiled, it'll automatically switch over to using the InterpolatedStringHandler version.

One possible downside: this technically changes the behavior when a log message also has mutation built into it. (ie .Monitor.VerboseLog($"why {i++}") will no longer see i increment.)

Example log: https://smapi.io/log/4cf6b096effc4d10ae629124b42da742?Levels=trace%7Edebug%7Einfo%7Ewarn%7Eerror%7Ealert%7Ecritical&Page=2&PerPage=1000

Pathoschild commented 6 months ago

Merged into alpha for the upcoming SMAPI 4.0.0. Thanks for the help!