Skip to content

Commit

Permalink
fix: 修复事件日志不输出的问题 (#154)
Browse files Browse the repository at this point in the history
* fix: optimize the discovery inject logic and fix nacos config not working issue

* feat: 删除无用的导入

* feat: 增加actuator到demo中

* fix: add lossless healthcheck for example

* fix: add configuration comments

* fix: 修复事件日志不输出的问题
  • Loading branch information
andrewshan authored Apr 15, 2024
1 parent 7bc4c23 commit 5bafa35
Show file tree
Hide file tree
Showing 4 changed files with 402 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private static void runConfigModifiers(Environment environment) throws IOExcepti
logConfig = Holder.class.getClassLoader().getResource("polaris-log4j.xml").getFile();
}
}
System.setProperty(LoggingConsts.LOGGING_CONFIG_PROPERTY, logConfig);
System.setProperty(LoggingConsts.LOGGING_CONFIG_PROPERTY, "jar:" + logConfig);

if (StringUtils.isBlank(polarisContextProperties.getLocalIpAddress())) {
polarisContextProperties.setLocalIpAddress(environment.getProperty("spring.cloud.client.ip-address"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="POLARIS_LOG_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${polaris.log.home}/polaris.log"/>
<param name="Append" value="true"/>
<param name="MaxBackupIndex" value="10"/>
<param name="MaxFileSize" value="10MB"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%-5p] [method:%l]%n%m%n%n"/>
</layout>
</appender>
<appender name="POLARIS_UPDATE_EVENT_LOG_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${polaris.log.home}/polaris-update-event.log"/>
<param name="Append" value="true"/>
<param name="MaxBackupIndex" value="10"/>
<param name="MaxFileSize" value="10MB"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%-5p] [method:%l]%n%m%n%n"/>
</layout>
</appender>
<appender name="POLARIS_UPDATE_EVENT_LOG_FILE_ASYNC" class="org.apache.log4j.AsyncAppender">
<param name="BufferSize" value="512"/>
<param name="Blocking" value="false"/>
<appender-ref ref="POLARIS_UPDATE_EVENT_LOG_FILE"/>
</appender>

<logger name="com.tencent.polaris" additivity="false">
<level value="INFO"/>
<appender-ref ref="POLARIS_LOG_FILE"/>
</logger>
<logger name="polaris-update-event" additivity="false">
<level value="INFO"/>
<appender-ref ref="POLARIS_UPDATE_EVENT_LOG_FILE"/>
</logger>
<logger name="polaris-update-event-async" additivity="false">
<level value="INFO"/>
<appender-ref ref="POLARIS_UPDATE_EVENT_LOG_FILE_ASYNC"/>
</logger>
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="POLARIS_LOG_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${polaris.log.home}/polaris.log"/>
<param name="Append" value="true"/>
<param name="MaxBackupIndex" value="10"/>
<param name="MaxFileSize" value="10MB"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%-5p] [method:%l]%n%m%n%n"/>
</layout>
</appender>
<appender name="POLARIS_UPDATE_EVENT_LOG_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${polaris.log.home}/polaris-update-event.log"/>
<param name="Append" value="true"/>
<param name="MaxBackupIndex" value="10"/>
<param name="MaxFileSize" value="10MB"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%-5p] [method:%l]%n%m%n%n"/>
</layout>
</appender>
<appender name="POLARIS_UPDATE_EVENT_LOG_FILE_ASYNC" class="org.apache.log4j.AsyncAppender">
<param name="BufferSize" value="512"/>
<param name="Blocking" value="false"/>
<appender-ref ref="POLARIS_UPDATE_EVENT_LOG_FILE"/>
</appender>
<appender name="POLARIS_CIRCUIT_BREAKER_EVENT_LOG_FILE"
class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${polaris.log.home}/polaris-circuitbreaker-event.log"/>
<param name="Append" value="true"/>
<param name="MaxBackupIndex" value="10"/>
<param name="MaxFileSize" value="10MB"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%-5p] [method:%l]%n%m%n%n"/>
</layout>
</appender>
<appender name="POLARIS_HEALTH_CHECK_EVENT_LOG_FILE"
class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${polaris.log.home}/polaris-healthcheck-event.log"/>
<param name="Append" value="true"/>
<param name="MaxBackupIndex" value="10"/>
<param name="MaxFileSize" value="10MB"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%-5p] [method:%l]%n%m%n%n"/>
</layout>
</appender>
<appender name="POLARIS_LOSSLESS_EVENT_LOG_FILE"
class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${polaris.log.home}/polaris-lossless-event.log"/>
<param name="Append" value="true"/>
<param name="MaxBackupIndex" value="10"/>
<param name="MaxFileSize" value="10MB"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%m|[%d{yyyy-MM-dd HH:mm:ss:SSS}]%n"/>
</layout>
</appender>
<appender name="POLARIS_INSTANCE_HEARTBEAT_LOG_FILE"
class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${polaris.log.home}/polaris-instance-heartbeat.log"/>
<param name="Append" value="true"/>
<param name="MaxBackupIndex" value="10"/>
<param name="MaxFileSize" value="10MB"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%m|[%d{yyyy-MM-dd HH:mm:ss:SSS}]%n"/>
</layout>
</appender>

<logger name="com.tencent.polaris" additivity="false">
<level value="INFO"/>
<appender-ref ref="POLARIS_LOG_FILE"/>
</logger>
<logger name="polaris-update-event" additivity="false">
<level value="INFO"/>
<appender-ref ref="POLARIS_UPDATE_EVENT_LOG_FILE"/>
</logger>
<logger name="polaris-update-event-async" additivity="false">
<level value="INFO"/>
<appender-ref ref="POLARIS_UPDATE_EVENT_LOG_FILE_ASYNC"/>
</logger>
<logger name="polaris-circuitbreaker-event" additivity="false">
<level value="INFO"/>
<appender-ref ref="POLARIS_CIRCUIT_BREAKER_EVENT_LOG_FILE"/>
</logger>
<logger name="polaris-healthcheck-event" additivity="false">
<level value="INFO"/>
<appender-ref ref="POLARIS_HEALTH_CHECK_EVENT_LOG_FILE"/>
</logger>
<logger name="polaris-lossless-event" additivity="false">
<level value="INFO"/>
<appender-ref ref="POLARIS_LOSSLESS_EVENT_LOG_FILE"/>
</logger>
<logger name="polaris-instance-heartbeat" additivity="false">
<level value="INFO"/>
<appender-ref ref="POLARIS_INSTANCE_HEARTBEAT_LOG_FILE"/>
</logger>
</log4j:configuration>
Original file line number Diff line number Diff line change
@@ -1,52 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>

<Configuration status="WARN">
<Appenders>
<RollingFile name="POLARIS_LOG_FILE" fileName="${sys:polaris.log.home}/polaris.log"
filePattern="${sys:polaris.log.home}/polaris.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
</PatternLayout>

<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="${sys:polaris.log.file.size:-10MB}"/>
</Policies>

<DefaultRolloverStrategy max="${sys:polaris.log.retain.count:-7}"/>
</RollingFile>

<RollingFile name="POLARIS_UPDATE_EVENT_LOG_FILE"
fileName="${sys:polaris.log.home}/polaris-update-event.log"
filePattern="${sys:polaris.log.home}/polaris-update-event.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
</PatternLayout>

<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="${sys:polaris-update-event.log.file.size:-10MB}"/>
</Policies>

<DefaultRolloverStrategy max="${sys:polaris-update-event.log.retain.count:-7}"/>
</RollingFile>
</Appenders>

<Loggers>
<Logger name="com.tencent.polaris"
level="${sys:polaris.log.level:-info}"
additivity="false">
<AppenderRef ref="POLARIS_LOG_FILE"/>
</Logger>
<Logger name="polaris-update-event-async"
level="${sys:polaris-update-event.log.level:-info}"
additivity="false">
<AppenderRef ref="POLARIS_UPDATE_EVENT_LOG_FILE"/>
</Logger>
<!-- <AsyncLogger name="polaris-update-event-async"-->
<!-- level="${sys:polaris-update-event.log.level:-info}"-->
<!-- additivity="false">-->
<!-- <AppenderRef ref="POLARIS_UPDATE_EVENT_LOG_FILE"/>-->
<!-- </AsyncLogger>-->
</Loggers>
</Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<RollingFile name="POLARIS_LOG_FILE" fileName="${sys:polaris.log.home}/polaris.log"
filePattern="${sys:polaris.log.home}/polaris.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
</PatternLayout>

<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="${sys:polaris.log.file.size:-10MB}"/>
</Policies>

<DefaultRolloverStrategy max="${sys:polaris.log.retain.count:-7}"/>
</RollingFile>

<RollingFile name="POLARIS_UPDATE_EVENT_LOG_FILE"
fileName="${sys:polaris.log.home}/polaris-update-event.log"
filePattern="${sys:polaris.log.home}/polaris-update-event.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
</PatternLayout>

<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="${sys:polaris.update.event.log.file.size:-10MB}"/>
</Policies>

<DefaultRolloverStrategy max="${sys:polaris.update.event.log.retain.count:-7}"/>
</RollingFile>

<RollingFile name="POLARIS_CIRCUIT_BREAKER_EVENT_LOG_FILE"
fileName="${sys:polaris.log.home}/polaris-circuitbreaker-event.log"
filePattern="${sys:polaris.log.home}/polaris-circuitbreaker-event.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
</PatternLayout>

<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy
size="${sys:polaris.circuitbreaker.event.log.file.size:-10MB}"/>
</Policies>

<DefaultRolloverStrategy max="${sys:polaris.circuitbreaker.event.log.retain.count:-7}"/>
</RollingFile>

<RollingFile name="POLARIS_HEALTH_CHECK_EVENT_LOG_FILE"
fileName="${sys:polaris.log.home}/polaris-healthcheck-event"
filePattern="${sys:polaris.log.home}/polaris-healthcheck-event.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
</PatternLayout>

<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy
size="${sys:polaris.healthcheck.event.log.file.size:-10MB}"/>
</Policies>

<DefaultRolloverStrategy max="${sys:polaris.healthcheck.event.log.retain.count:-7}"/>
</RollingFile>

<RollingFile name="POLARIS_LOSSLESS_EVENT_LOG_FILE"
fileName="${sys:polaris.log.home}/polaris-lossless-event"
filePattern="${sys:polaris.log.home}/polaris-lossless-event.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%m|%d{yyyy-MM-dd HH:mm:ss.SSS}%n</Pattern>
</PatternLayout>

<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy
size="${sys:polaris.lossless.event.log.file.size:-10MB}"/>
</Policies>

<DefaultRolloverStrategy max="${sys:polaris.lossless.event.log.retain.count:-7}"/>
</RollingFile>

<RollingFile name="POLARIS_INSTANCE_HEARTBEAT_LOG_FILE"
fileName="${sys:polaris.log.home}/polaris-instance-heartbeat"
filePattern="${sys:polaris.log.home}/polaris-instance-heartbeat.log.%d{yyyy-MM-dd}.%i">
<PatternLayout>
<Pattern>%m|%d{yyyy-MM-dd HH:mm:ss.SSS}%n</Pattern>
</PatternLayout>

<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy
size="${sys:polaris.instance.heartbeat.log.file.size:-10MB}"/>
</Policies>

<DefaultRolloverStrategy max="${sys:polaris.instance.heartbeat.log.retain.count:-7}"/>
</RollingFile>
</Appenders>

<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
<Logger name="com.tencent.polaris"
level="${sys:polaris.log.level:-info}"
additivity="false">
<AppenderRef ref="POLARIS_LOG_FILE"/>
</Logger>
<Logger name="polaris-update-event-async"
level="${sys:polaris.update.event.log.level:-info}"
additivity="false">
<AppenderRef ref="POLARIS_UPDATE_EVENT_LOG_FILE"/>
</Logger>
<Logger name="polaris-circuitbreaker-event"
level="${sys:polaris.circuitbreaker.event.log.level:-info}"
additivity="false">
<AppenderRef ref="POLARIS_CIRCUIT_BREAKER_EVENT_LOG_FILE"/>
</Logger>
<Logger name="polaris-healthcheck-event"
level="${sys:polaris.healthcheck.event.log.level:-info}"
additivity="false">
<AppenderRef ref="POLARIS_HEALTH_CHECK_EVENT_LOG_FILE"/>
</Logger>
<!-- <AsyncLogger name="polaris-update-event-async"-->
<!-- level="${sys:polaris-update-event.log.level:-info}"-->
<!-- additivity="false">-->
<!-- <AppenderRef ref="POLARIS_UPDATE_EVENT_LOG_FILE"/>-->
<!-- </AsyncLogger>-->
<Logger name="polaris-lossless-event"
level="${sys:polaris.lossless.event.log.level:-info}"
additivity="false">
<AppenderRef ref="POLARIS_LOSSLESS_EVENT_LOG_FILE"/>
</Logger>
<Logger name="polaris-instance-heartbeat"
level="${sys:polaris.instance.heartbeat.log.level:-info}"
additivity="false">
<AppenderRef ref="POLARIS_INSTANCE_HEARTBEAT_LOG_FILE"/>
</Logger>
</Loggers>
</Configuration>
Loading

0 comments on commit 5bafa35

Please sign in to comment.