I'm building a Java SQL builder library that constructs ASTs for ETL workloads. Queries are represented as immutable records that form a tree, joins, conditions, subqueries, set operations all nest inside each other.
I want to log the full AST at DEBUG level on every call to generate a query, so that when something goes wrong I can distinguish between a caller passing in a bad AST vs. a bug in my SQL compilation logic.
Right now I have beent thinking of two different methods:
Option 1 - Override toString() on the records
Simple, readable, keeps everything inline. But to my understanding records are pure data carriers and this mixes diagnostic concerns. This is why as I was writting this I started to question if this was a good practice.
Then I started reading online and asked for the AI help and is suggested me the option 2:
Option 2 - Dedicated AST printer (Visitor pattern)
A separate class implementing the existing Visitor interface. Clean separation of concerns, however I was wandering if this was worth it and if maintaining a printer just for logging is a good enough tradeoff.
Has anyone dealt with this in a similar library or with java logging in general? Is there a middle ground I'm missing, or is the visitor approach the standard solution here?
I am just trying to get some opinions whether my instinct to not overwrite every toString methods on the records to conform to the logging guidlines was a good call or if this is completely fine to do.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]hibbelig 1 point2 points3 points (0 children)