Back

with-logging (clj)

(source)

function

(with-logging connectable sql-logger & [result-logger])
Given a connectable/transactable object and a sql/params logging function and an optional result logging function that should be used on all operations on that object, return a new wrapper object that can be used in its place. The sql/params logging function will be called with two arguments: * a symbol indicating which operation is being performed: * `next.jdbc/plan`, `next.jdbc/execute-one!`, `next.jdbc/execute!`, or `next.jdbc/prepare` * the vector containing the SQL string and its parameters Whatever the sql/params logging function returns will be passed as a `state` argument to the optional result logging function. This means you can use this mechanism to provide some timing information, since your sql/params logging function can return the current system time, and your result logging function can then calculate the elapsed time. There is an example of this in the Naive Logging with Timing section of Getting Started. The result logging function, if provided, will be called with the same symbol passed to the sql/params logging function, the `state` returned by the sql/params logging function, and either the result of the `execute!` or `execute-one!` call or an exception if the call failed. The result logging function is not called for the `plan` or `prepare` call (since they do not produce result sets directly). Bear in mind that `get-datasource`, `get-connection`, and `with-transaction` return plain Java objects, so if you call any of those on this wrapped object, you'll need to re-wrap the Java object `with-logging` again. See the Datasources, Connections & Transactions section of Getting Started for more details, and some examples of use with these functions.

Examples