Jakub Neruda<p>Tip 86 of <a href="https://techhub.social/tags/TuesdayCodingTips" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>TuesdayCodingTips</span></a> - Extendable logger pattern</p><p>I like my logs structured. If nothing else, I can log into a CSV file, load that CSV into Excel, turn on filters, and boom, I have a quite nice log analyzer tool. To get the maximum out of it, I need to be able to split my logs into as many columns as possible.</p><p>When creating a library where the user can provide their own logger implementation, you need to be very careful about the logger interface to minimize breaking changes in new library versions. Ideally, you want to be able to add new properties to the log without affecting existing logger implementations.</p><p>A typical interface method with one parameter per property won't do - every addition breaks the interface. What I like to do is wrap all loggable information in a struct and pass that to the logger interface instead. This allows me to add new properties with less fuss and evolve my libraries faster!</p><p><a href="https://techhub.social/tags/cleancode" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>cleancode</span></a> <a href="https://techhub.social/tags/tips" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>tips</span></a> <a href="https://techhub.social/tags/programming" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>programming</span></a></p>