Skip to content

Commit

Permalink
Add JDBC logging to monitor activities
Browse files Browse the repository at this point in the history
  • Loading branch information
adomokos committed Nov 2, 2015
1 parent debc055 commit 81d40aa
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@ pom.xml.asc
/.nrepl-port
.hgignore
.hg/
!/lib/slf4j-simple-1.7.12.jar
Binary file added lib/slf4j-simple-1.7.12.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion project.clj
Expand Up @@ -8,10 +8,12 @@
[yesql "0.5.1"]
[compojure "1.4.0"]
[ring/ring-defaults "0.1.5"]
[cheshire "5.5.0"]]
[cheshire "5.5.0"]
[com.googlecode.log4jdbc/log4jdbc "1.2"]]
:clj-sql-up {:database "jdbc:postgresql://kashmir_user:password@localhost:5432/kashmir"
:deps [[org.postgresql/postgresql "9.4-1201-jdbc41"]]}
:ring {:handler kashmir.handler/app}
:resource-paths ["lib/slf4j-simple-1.7.12.jar"]
:plugins [[clj-sql-up "0.3.7"]
[lein-ring "0.9.7"]]
:main ^:skip-aot kashmir.core
Expand Down
33 changes: 33 additions & 0 deletions resources/log4j.properties
@@ -0,0 +1,33 @@
# the appender used for the JDBC API layer call logging above, sql only
log4j.appender.sql=org.apache.log4j.ConsoleAppender
log4j.appender.sql.Target=System.out
log4j.appender.sql.layout=org.apache.log4j.PatternLayout
log4j.appender.sql.layout.ConversionPattern= \u001b[0;31m (SQL)\u001b[m %d{yyyy-MM-dd HH:mm:ss.SSS} \u001b[0;32m %m \u001b[m %n

# ==============================================================================
# JDBC API layer call logging :
# INFO shows logging, DEBUG also shows where in code the jdbc calls were made,
# setting DEBUG to true might cause minor slow-down in some environments.
# If you experience too much slowness, use INFO instead.

log4jdbc.drivers=org.postgresql.Driver

# Log all JDBC calls except for ResultSet calls
log4j.logger.jdbc.audit=FATAL,sql
log4j.additivity.jdbc.audit=false

# Log only JDBC calls to ResultSet objects
log4j.logger.jdbc.resultset=FATAL,sql
log4j.additivity.jdbc.resultset=false

# Log only the SQL that is executed.
log4j.logger.jdbc.sqlonly=FATAL,sql
log4j.additivity.jdbc.sqlonly=false

# Log timing information about the SQL that is executed.
log4j.logger.jdbc.sqltiming=FATAL,sql
log4j.additivity.jdbc.sqltiming=false

# Log connection open/close events and connection number dump
log4j.logger.jdbc.connection=FATAL,sql
log4j.additivity.jdbc.connection=false
5 changes: 3 additions & 2 deletions src/kashmir/data.clj
Expand Up @@ -2,8 +2,9 @@
(:require [yesql.core :refer [defqueries]]
[clojure.java.jdbc :as jdbc]))

(def db-spec {:classname "org.postgresql.Driver"
:subprotocol "postgresql"
(def db-spec {:classname "net.sf.log4jdbc.DriverSpy"
:subprotocol "log4jdbc:postgresql"
;:subprotocol "postgresql"
:subname "//localhost:5432/kashmir"
:user "kashmir_user"
:password "password1"})
Expand Down

0 comments on commit 81d40aa

Please sign in to comment.