我发现了一个登录 clojure api 的问题。
我尝试为 API 请求和 SQL 语句实现日志记录机制。
项目.clj
(defproject clojure-dauble-business-api "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:ring {:handler clojure-dauble-business-api.routes/app}
:dependencies [[org.clojure/clojure "1.8.0"]
[metosin/compojure-api "1.1.10"]
[ring/ring-core "1.4.0"]
[ring/ring-jetty-adapter "1.4.0"]
[ring/ring-defaults "0.2.0"]
[org.clojure/java.jdbc "0.6.1"]
[yesql/yesql "0.5.3"]
[org.postgresql/postgresql "9.4.1212"]
[org.clojure/data.json "0.2.6"]
[cheshire "5.7.1"]
[com.googlecode.log4jdbc/log4jdbc "1.2"]
[org.slf4j/slf4j-simple "1.7.12"]
[org.clojure/tools.logging "0.3.1"]
[log4j/log4j "1.2.17" :exclusions [javax.mail/mail
javax.jms/jms
com.sun.jmdk/jmxtools
com.sun.jmx/jmxri]]]
:profiles {:dev {:resource-paths ["resources"]}}
:plugins [[lein-ring "0.12.0"]]
:main clojure-dauble-business-api.routes)
和
log4j.properties
# Application Logging
log4j.rootLogger=INFO, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./log/app.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%d][%p][%c] %m%n
# # the appender used for the JDBC API layer call logging above, sql only
log4j.appender.sql=org.apache.log4j.RollingFileAppender
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=INFO,sql
log4j.additivity.jdbc.audit=false
#
# # Log only JDBC calls to ResultSet objects
log4j.logger.jdbc.resultset=INFO,sql
log4j.additivity.jdbc.resultset=false
#
# # Log only the SQL that is executed.
log4j.logger.jdbc.sqlonly=INFO,sql
log4j.additivity.jdbc.sqlonly=false
#
# # Log timing information about the SQL that is executed.
log4j.logger.jdbc.sqltiming=INFO,sql
log4j.additivity.jdbc.sqltiming=false
#
# # Log connection open/close events and connection number dump
log4j.logger.jdbc.connection=INFO,sql
log4j.additivity.jdbc.connection=false
这里
[com.googlecode.log4jdbc/log4jdbc "1.2"]
[org.slf4j/slf4j-simple "1.7.12"]
覆盖日志记录机制。意味着,日志显示在控制台上,而不是创建 app.log 文件(根据 log4j.properties 配置)。
只有 API 请求日志显示在控制台上,并且不显示 SQL 日志。
为什么日志会显示在控制台上?以及如何在文件中记录 SQL 日志?