【问题标题】:logs - How to remove database information in log fileslogs - 如何删除日志文件中的数据库信息
【发布时间】:2017-04-05 04:33:52
【问题描述】:

我正在为我的项目使用 Spring iBatis 框架。然后使用 logback 记录我。然后,在检查日志文件后,我可以看到系统正在使用的数据库...出于安全目的,我想隐藏它

这是示例日志..

12:22:59.585 [http-bio-3088-exec-1] DEBUG org.mybatis.spring.SqlSessionUtils - Creating SqlSession with JDBC Connection [jdbc:postgresql://127.0.0.1:5432/SAMPLEDB, UserName=postgres, PostgreSQL Native Driver]
12:22:59.585 [http-bio-3088-exec-1] DEBUG java.sql.Connection - ooo Connection Opened
12:22:59.585 [http-bio-3088-exec-1] DEBUG o.m.s.t.SpringManagedTransaction - JDBC Connection [jdbc:postgresql://127.0.0.1:5432/SAMPLEDB, UserName=postgres, PostgreSQL Native Driver] will not be managed by Spring
12:22:59.585 [http-bio-3088-exec-1] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@13c8ced] was not registered for synchronization because synchronization is not active
12:22:59.585 [http-bio-3088-exec-1] DEBUG java.sql.PreparedStatement - ==>  Executing: SELECT * (purposely deleted)
12:22:59.585 [http-bio-3088-exec-1] DEBUG java.sql.PreparedStatement - ==> Parameters: ADMIN(String), 0(Integer)
12:22:59.585 [http-bio-3088-exec-1] DEBUG java.sql.ResultSet - <==    Columns: (purposely deleted, list of columns)
12:22:59.585 [http-bio-3088-exec-1] DEBUG java.sql.ResultSet - <==        Row: 86, ADMIN, 1, 7, 0, ADMIN, 20170403, 135432, SCREENID, null, null, null, null, 0, null, 1
12:22:59.585 [http-bio-3088-exec-1] DEBUG org.mybatis.spring.SqlSessionUtils - Closing no transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@13c8ced]
12:22:59.585 [http-bio-3088-exec-1] DEBUG org.mybatis.spring.SqlSessionUtils - Creating SqlSession with JDBC Connection [jdbc:postgresql://127.0.0.1:5432/SAMPLEDB, UserName=postgres, PostgreSQL Native Driver]
12:22:59.585 [http-bio-3088-exec-1] DEBUG java.sql.Connection - ooo Connection Opened
12:22:59.585 [http-bio-3088-exec-1] DEBUG o.m.s.t.SpringManagedTransaction - JDBC Connection [jdbc:postgresql://127.0.0.1:5432/SAMPLEDB, UserName=postgres, PostgreSQL Native Driver] will not be managed by Spring
12:22:59.585 [http-bio-3088-exec-1] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@18bbc43] was not registered for synchronization because synchronization is not active
12:22:59.601 [http-bio-3088-exec-1] DEBUG java.sql.PreparedStatement - ==>  Executing: SELECT count(*) (purposely deleted)
12:22:59.601 [http-bio-3088-exec-1] DEBUG java.sql.PreparedStatement - ==> Parameters: 1(Integer), 7(BigDecimal), SA(String), 0(Integer), 20170404(Integer), 20170404(Integer)
12:23:00.241 [http-bio-3088-exec-1] DEBUG java.sql.ResultSet - <==    Columns: count
12:23:00.241 [http-bio-3088-exec-1] DEBUG java.sql.ResultSet - <==        Row: 7

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>


    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
        </layout>
    </appender>

    <appender name="WINFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>C:/logs/logfile.log</File>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
        </layout>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>C:/logs/logfile-%d{yyyy-MM-dd}-%i.txt</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>2MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>


    <root level="debug">
        <appender-ref ref="STDOUT" />
         <appender-ref ref="WINFILE" />
    </root>

</configuration>

我想删除 o.m.s.t.SpringManagedTransaction 部分

【问题讨论】:

    标签: java spring logging logback ibatis


    【解决方案1】:

    如果您将 root logger 更改为 levelINFO,它将应用于所有包,即 如果您想更改所有包的日志记录级别,您可以更改levelroot

    但是,如果您只想单独控制 o.m.s.t.SpringManagedTransaction 日志记录,则可以通过为该包添加 logger 来实现,如下所示:

    <!-- set this level to WARN/ERROR upto your project -->
    <logger name="o.m.s.t.SpringManagedTransaction" level="INFO" additivity="false">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="WINFILE"/>
    </logger>
    
    <!-- if you want add more loggers here for different packages -->    
    
    <!-- this is for all other packages -->
    <root level="debug">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="WINFILE" />
     </root>
    

    【讨论】:

    • 谢谢......我会试试这个......我认为 additivity="false" 是我的问题的解决方案,对吧??
    • 否,如上图为SpringManagedTransaction 添加一个新的记录器,并将级别标记为INFO
    • 我添加了上面的代码,不包括 STDOUT.. 但是我的 Eclipse 中的控制台日志也没有显示 DB 信息。我只想在日志文件中删除它。
    • STDOUT 是 CONSOLE 的,所以你不应该排除它,你需要它
    【解决方案2】:

    将您的根日志级别更改为信息。这意味着它不会打印调试日志。

    <root level="info">
            <appender-ref ref="STDOUT" />
             <appender-ref ref="WINFILE" />
        </root>
    

    【讨论】:

    • 谢谢...这会影响我将在代码中声明的 logger.debug 吗??
    【解决方案3】:
    <root level="info">
    

    或者在 logback.xml 中添加这个

    <logger name="o.m.s.t.SpringManagedTransaction" additivity="false">
      <level value="info"/>
      <appender-ref ref="STDOUT"/>
      <appender-ref ref="WINFILE"/>
    </logger>
    

    【讨论】:

      猜你喜欢
      • 2019-08-25
      • 2018-10-07
      • 2020-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多