log4jdbc日志配置

2022-03-28 16:53:05 浏览数 (1)

log4jdbc 是一款java jdbc驱动程序,它能够打印sql以及jdbc调用其他jdbc驱动 的日志,日志记录使用的是SLF4J系统,下面是常见的xml配置:

代码语言:javascript复制
    <!--log4jdbc -->
    <logger name="jdbc.sqlonly" level="OFF"/>
    <logger name="jdbc.sqltiming" level="INFO"/>
    <logger name="jdbc.audit" level="OFF"/>
    <logger name="jdbc.resultset" level="OFF"/>
    <logger name="jdbc.connection" level="OFF"/>

具体这些配置可以:

代码语言:javascript复制
  // logs for sql and jdbc

  /**
   * Logger that shows all JDBC calls on INFO level (exception ResultSet calls)
   */
  private final Logger jdbcLogger = LoggerFactory.getLogger("jdbc.audit");

  /**
   * Logger that shows JDBC calls for ResultSet operations
   */
  private final Logger resultSetLogger = LoggerFactory.getLogger("jdbc.resultset");

  /**
   * Logger that shows only the SQL that is occuring
   */
  private final Logger sqlOnlyLogger = LoggerFactory.getLogger("jdbc.sqlonly");

  /**
   * Logger that shows the SQL timing, post execution
   */
  private final Logger sqlTimingLogger = LoggerFactory.getLogger("jdbc.sqltiming");

  /**
   * Logger that shows connection open and close events as well as current number
   * of open connections.
   */
  private final Logger connectionLogger = LoggerFactory.getLogger("jdbc.connection");

  // admin/setup logging for log4jdbc.

  /**
   * Logger just for debugging things within log4jdbc itself (admin, setup, etc.)
   */
  private final Logger debugLogger = LoggerFactory.getLogger("log4jdbc.debug");

0 人点赞