This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-06
Channels
- # announcements (12)
- # babashka (34)
- # beginners (85)
- # calva (76)
- # cider (14)
- # clj-kondo (49)
- # cljs-dev (32)
- # clojure (418)
- # clojure-europe (3)
- # clojure-france (4)
- # clojure-italy (17)
- # clojure-losangeles (8)
- # clojure-nl (5)
- # clojure-norway (2)
- # clojure-spec (2)
- # clojure-uk (88)
- # clojuredesign-podcast (4)
- # clojurescript (49)
- # clojurex (75)
- # clr (2)
- # core-async (13)
- # cursive (6)
- # datomic (57)
- # duct (31)
- # emacs (6)
- # fulcro (25)
- # graalvm (67)
- # graphql (13)
- # hoplon (1)
- # java (6)
- # juxt (11)
- # kaocha (5)
- # keechma (2)
- # leiningen (16)
- # mount (1)
- # off-topic (19)
- # pathom (2)
- # pedestal (1)
- # re-frame (11)
- # reagent (21)
- # reitit (22)
- # rewrite-clj (1)
- # shadow-cljs (98)
- # spacemacs (5)
- # sql (16)
- # tools-deps (8)
- # vim (28)
- # xtdb (4)
@seancorfield what's the recommended way to log next.jdbc queries (in dev/debug)? i'd want to log every single query, one log line per query.
(defn select
[sql]
(log/debugf "Executing JDBC [%s]." sql)
(try
(let [results (jdbc/execute-one! @datasource sql {:builder-fn rs/as-unqualified-lower-maps})]
(when (seq results)
(log/debugf "JDBC Results [%s]." results))
results)
(catch Exception e (log/error e))))
it'd be nice if i didn't have to write this (and also query time measurement) myself
I haven't used it with clojure but you could take a look at https://github.com/p6spy/p6spy
Some jdbc drivers may also support logging via system props/config (see https://stackoverflow.com/questions/27060563/enable-logging-for-sql-statements-when-using-jdbc)
If you are happy to do a bit of hacking you can write a general facility that wraps jdbc queries using var rebinding, with-redefs or alter-var-root
I think if its just for testing / debugging that sort of approach is fine. you can write a (dev/sql-logging true) style function that toggles on/off without having to change any of your 'real' code.
I have also used driver level query logging as well and that can work well, but typically you will need to reprovision your connection pool or datasource so may be less handy at the REPL.
i've tried that too, but sadly the driver-level logging for mysql isn't exactly smart so i was looking for alternatives
In development, I just turn on SQL statement logging on the database server itself.
i can't seem to get the jdbc driver to log slow queries... with hikari-cp and
:log-slow-queries true
:slow-query-threshold-millis 1
(i'm testing it with select sleep(1)
)Given that results can be arbitrarily large, logging the entire result set seems very problematic. Logging the SQL and parameters would be OK but what about sensitive data ending up in your log files?