当前位置:   article > 正文

记录一个druid与log4j2的坑,目前还没找到解决方法_error statusconsolelistener unable to locate appen

error statusconsolelistener unable to locate appender "logstash" for logger

每次项目部署完之后的info日志都打印正常,第二天日志压缩之后,重新生成新的info日志文件,项目的日志就打印不出来

都是打印的druid的异常,项目其他的一切正常

druid的异常:该url(172.28.186.170)是我本机的,已经被我注释掉了,换成了测试环境对应的地址,依然每隔45秒出现一次,部署完第二天项目的接口调用的都正常,但是接口调用的日志打印不出来

  1. 22:54:47.762 [Druid-ConnectionPool-Create-1889457907] ERROR com.alibaba.druid.pool.DruidDataSource - create connection error, url: jdbc:sqlserver://172.28.186.170;DatabaseName=testsqlserver, errorCode 0, state 08S01
  2. com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 172.28.186.170, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
  3. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:234) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  4. at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:285) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  5. at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2431) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  6. at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:656) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  7. at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2472) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  8. at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2142) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  9. at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1993) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  10. at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1164) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  11. at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:760) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  12. at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1408) ~[druid-1.0.18.jar:1.0.18]
  13. at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1464) ~[druid-1.0.18.jar:1.0.18]
  14. at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1969) [druid-1.0.18.jar:1.0.18]
  15. 22:55:32.764 [Druid-ConnectionPool-Create-1889457907] ERROR com.alibaba.druid.pool.DruidDataSource - create connection error, url: jdbc:sqlserver://172.28.186.170;DatabaseName=testsqlserver, errorCode 0, state 08S01
  16. com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 172.28.186.170, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
  17. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:234) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  18. at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:285) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  19. at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2431) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  20. at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:656) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  21. at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2472) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  22. at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2142) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  23. at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1993) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  24. at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1164) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  25. at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:760) ~[mssql-jdbc-7.4.1.jre8.jar:?]
  26. at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1408) ~[druid-1.0.18.jar:1.0.18]
  27. at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1464) ~[druid-1.0.18.jar:1.0.18]
  28. at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1969) [druid-1.0.18.jar:1.0.18]

相关依赖

  1. <dependency>
  2. <groupId>com.alibaba</groupId>
  3. <artifactId>druid-spring-boot-starter</artifactId>
  4. <version>1.1.10</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.microsoft.sqlserver</groupId>
  8. <artifactId>mssql-jdbc</artifactId>
  9. <scope>runtime</scope>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.springframework.boot</groupId>
  13. <artifactId>spring-boot-starter-log4j2</artifactId>
  14. </dependency>
  15. <dependency>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-starter-web</artifactId>
  18. <exclusions><!-- 去掉springboot默认配置 -->
  19. <exclusion>
  20. <groupId>org.springframework.boot</groupId>
  21. <artifactId>spring-boot-starter-logging</artifactId>
  22. </exclusion>
  23. </exclusions>
  24. </dependency>

配置文件配置

log4j2.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--Configuration后面的status,这个用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,你会看到log4j2内部各种详细输出-->
  3. <!--monitorInterval:Log4j能够自动检测修改配置 文件和重新配置本身,设置间隔秒数-->
  4. <configuration monitorInterval="5">
  5. <!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
  6. <!--变量配置-->
  7. <Properties>
  8. <!-- 格式化输出:%date表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度 %msg:日志消息,%n是换行符-->
  9. <!-- %logger{36} 表示 Logger 名字最长36个字符 -->
  10. <property name="LOG_PATTERN" value="%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
  11. <!-- 定义日志存储的路径 -->
  12. <property name="FILE_PATH" value="log/logs" />
  13. <property name="FILE_NAME" value="CtripBusiness" />
  14. <property name="FILE_SIZE" value="50 MB" />
  15. </Properties>
  16. <appenders>
  17. <console name="Console" target="SYSTEM_OUT">
  18. <!--输出日志的格式-->
  19. <PatternLayout pattern="${LOG_PATTERN}"/>
  20. <!--控制台只输出level及其以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
  21. <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
  22. </console>
  23. <!--文件会打印出所有信息,这个log每次运行程序会自动清空,由append属性决定,适合临时测试用-->
  24. <!--<File name="Filelog" fileName="${FILE_PATH}/test.log" append="false">-->
  25. <!--<PatternLayout pattern="${LOG_PATTERN}"/>-->
  26. <!--</File>-->
  27. <!-- 这个会打印出所有的info及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
  28. <RollingFile name="RollingFileInfo"
  29. fileName="${FILE_PATH}/info.log"
  30. filePattern="${FILE_PATH}/${FILE_NAME}-INFO-%d{yyyy-MM-dd}_%i.log.gz">
  31. <!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
  32. <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
  33. <PatternLayout pattern="${LOG_PATTERN}"/>
  34. <Policies>
  35. <!--interval属性用来指定多久滚动一次,默认是1 hour-->
  36. <TimeBasedTriggeringPolicy interval="1"/>
  37. <SizeBasedTriggeringPolicy size="${FILE_SIZE}"/>
  38. </Policies>
  39. <!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
  40. <DefaultRolloverStrategy max="15"/>
  41. </RollingFile>
  42. <!-- 这个会打印出所有的warn及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
  43. <RollingFile name="RollingFileWarn" fileName="${FILE_PATH}/warn.log" filePattern="${FILE_PATH}/${FILE_NAME}-WARN-%d{yyyy-MM-dd}_%i.log.gz">
  44. <!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
  45. <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
  46. <PatternLayout pattern="${LOG_PATTERN}"/>
  47. <Policies>
  48. <!--interval属性用来指定多久滚动一次,默认是1 hour-->
  49. <TimeBasedTriggeringPolicy interval="1"/>
  50. <SizeBasedTriggeringPolicy size="${FILE_SIZE}"/>
  51. </Policies>
  52. <!-- DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖-->
  53. <DefaultRolloverStrategy max="15"/>
  54. </RollingFile>
  55. <!-- 这个会打印出所有的error及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
  56. <!--<RollingFile name="RollingFileError" fileName="${FILE_PATH}/error.log" filePattern="${FILE_PATH}/${FILE_NAME}-ERROR-%d{yyyy-MM-dd}_%i.log.gz">-->
  57. <!--&lt;!&ndash;控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)&ndash;&gt;-->
  58. <!--<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>-->
  59. <!--<PatternLayout pattern="${LOG_PATTERN}"/>-->
  60. <!--<Policies>-->
  61. <!--&lt;!&ndash;interval属性用来指定多久滚动一次,默认是1 hour&ndash;&gt;-->
  62. <!--<TimeBasedTriggeringPolicy interval="1"/>-->
  63. <!--<SizeBasedTriggeringPolicy size="${FILE_SIZE}"/>-->
  64. <!--</Policies>-->
  65. <!--&lt;!&ndash; DefaultRolloverStrategy属性如不设置,则默认为最多同一文件夹下7个文件开始覆盖&ndash;&gt;-->
  66. <!--<DefaultRolloverStrategy max="15"/>-->
  67. <!--</RollingFile>-->
  68. <!--druid的日志记录追加器-->
  69. <RollingFile name="druidSqlRollingFile" fileName="${FILE_PATH}/druid-sql.log"
  70. filePattern="logs/$${date:yyyy-MM}/api-%d{yyyy-MM-dd}-%i.log.gz">
  71. <PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss}] %-5level %L %M - %msg%xEx%n"/>
  72. <Policies>
  73. <SizeBasedTriggeringPolicy size="500 MB"/>
  74. <TimeBasedTriggeringPolicy/>
  75. </Policies>
  76. </RollingFile>
  77. </appenders>
  78. <!--Logger节点用来单独指定日志的形式,比如要为指定包下的class指定不同的日志级别等。-->
  79. <!--然后定义loggers,只有定义了logger并引入的appender,appender才会生效-->
  80. <loggers>
  81. <!-- 设置对打印sql语句的支持 -->
  82. <logger name="java.sql" level="debug" additivity="false">
  83. <appender-ref ref="Console"/>
  84. </logger>
  85. <!--过滤掉spring和mybatis的一些无用的DEBUG信息-->
  86. <logger name="org.mybatis" level="info" additivity="false">
  87. <AppenderRef ref="Console"/>
  88. </logger>
  89. <!--监控系统信息-->
  90. <!--若是additivity设为false,则 子Logger 只会在自己的appender里输出,而不会在 父Logger 的appender里输出。-->
  91. <Logger name="org.springframework" level="info" additivity="false">
  92. <AppenderRef ref="Console"/>
  93. </Logger>
  94. <root level="info">
  95. <appender-ref ref="Console"/>
  96. <!--<appender-ref ref="Filelog"/>-->
  97. <appender-ref ref="RollingFileInfo" level="info"/>
  98. <appender-ref ref="RollingFileWarn" level="warn"/>
  99. <!--<appender-ref ref="RollingFileError"/>-->
  100. </root>
  101. <!--记录druid-sql的记录-->
  102. <logger name="druid.sql.Statement" level="warn" additivity="false">
  103. <appender-ref ref="druidSqlRollingFile"/>
  104. </logger>
  105. <logger name="druid.sql.Statement" level="warn" additivity="false">
  106. <appender-ref ref="druidSqlRollingFile"/>
  107. </logger>
  108. <!--spring日志-->
  109. <Logger name="org.springframework" level="info"/>
  110. <!--druid数据源日志-->
  111. <!--<Logger name="druid.sql.Statement" level="warn"/>-->
  112. <!-- mybatis日志 -->
  113. <Logger name="com.mybatis" level="warn"/>
  114. <!--<Logger name="org.hibernate" level="warn"/>-->
  115. <!--<Logger name="com.zaxxer.hikari" level="info"/>-->
  116. <Logger name="org.quartz" level="info"/>
  117. <!--<Logger name="com.andya.demo" level="debug"/>-->
  118. </loggers>
  119. </configuration>

最后我的解决方法是又增加了一个warn的日志文件,所有的项目日志信息都输出到info和warn两个文件,目前warn的日志正常,但是info的日志依然和之前一样

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/666663
推荐阅读
相关标签
  

闽ICP备14008679号