Appending custom formatted sql logs and using async #195
Replies: 1 comment
-
There appear to be 2 requirements here:
For Note though that just about every version of rails returns the bind values differently, so custom handling is implemented for every supported version of Rails. For Alternatively, to keep it as a custom implementation, add a filter to the logger that is used here: The filter proc will receive the entire log structure, can modify it as needed, or in this case just return false to not log anything. Without running the actual code, it would be something like: RailsSemanticLogger::ActiveRecord::LogSubscriber.logger.filter = -> log { ! log.payload[:sql].start_with?('SELECT', 'BEGIN', 'COMMIT', 'SHOW') } To build out the proc, display the log struct contents to help build out what the code should look like. Also add handling for the case where the payload[:sql] is nil. It is also possible to modify the log struct inside the filter to break apart the binds, although this would be a useful feature for all users of Rails Semantic Logger. |
Beta Was this translation helpful? Give feedback.
-
We don't need the SELECT logs so we're excluding them and also format active_record sql logs as JSON like this:
than we add it to the logger like this:
The main problem is that we are forced to use "sync!" mode which slows down the application using this approach. Since threads are different when using the default async mode, AR sql logs that we formatted and stored inside Thread.current is empty when log is processed.
Do you have any idea on how to pass those AR sql logs to the logger, but keeping async mode activated?
Beta Was this translation helpful? Give feedback.
All reactions