Skip to content

Commit

Permalink
[#9893] Merge log4j2 configurations to a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
intr3p1d committed Apr 25, 2023
1 parent eff4b31 commit 32c0b6d
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 332 deletions.
5 changes: 4 additions & 1 deletion collector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-spring-boot</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,53 @@
<Property name="logging_dir">${sys:logging.file.path:-${default_logging_dir}}</Property>

<Property name="rolling-date-format">%d{yyyy-MM-dd}</Property>
<Property name="backupsize">1GB</Property>

<Property name="console_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %clr{%-5level} %clr{%-40.40logger{1.}}{cyan}:%3L -- %msg{nolookups}%n</Property>
<Property name="file_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %-5level %-40.40logger{1.}:%3L -- %msg{nolookups}%n</Property>
<Select>
<SpringProfile name="local">
<Property name="backupsize">1GB</Property>
<Property name="console_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %clr{%-5level} %clr{%-40.40logger{1.}}{cyan}:%3L -- %msg{nolookups}%n</Property>
<Property name="file_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %-5level %-40.40logger{1.}:%3L -- %msg{nolookups}%n</Property>
<Property name="accumulated_file_size">1GB</Property>
<Property name="accumulated_file_count">50</Property>
<Property name="logger_level">DEBUG</Property>
</SpringProfile>
<SpringProfile name="release">
<Property name="backupsize">100GB</Property>
<Property name="console_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %clr{%-5level} %clr{%-40.40logger{1.}}{cyan} : %msg{nolookups}%n</Property>
<Property name="file_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %-5level %-40.40logger{1.} : %msg{nolookups}%n</Property>
<Property name="accumulated_file_size">2000GB</Property>
<Property name="accumulated_file_count">100</Property>
<Property name="logger_level">INFO</Property>
</SpringProfile>
<DefaultArbiter>
<Property name="backupsize">1GB</Property>
<Property name="console_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %clr{%-5level} %clr{%-40.40logger{1.}}{cyan}:%3L -- %msg{nolookups}%n</Property>
<Property name="file_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %-5level %-40.40logger{1.}:%3L -- %msg{nolookups}%n</Property>
<Property name="accumulated_file_size">1GB</Property>
<Property name="accumulated_file_count">50</Property>
<Property name="logger_level">DEBUG</Property>
</DefaultArbiter>
</Select>
</Properties>

<Appenders>
<Console name="console" target="system_out">
<PatternLayout pattern="${console_message_pattern}"/>
</Console>
<Select>
<SpringProfile name="local">
<Console name="console" target="system_out">
<PatternLayout pattern="${console_message_pattern}"/>
</Console>
</SpringProfile>
<SpringProfile name="release">
<Console name="console" target="system_out">
<PatternLayout pattern="${file_message_pattern}"/>
</Console>
</SpringProfile>
<DefaultArbiter>
<Console name="console" target="system_out">
<PatternLayout pattern="${console_message_pattern}"/>
</Console>
</DefaultArbiter>
</Select>


<RollingFile name="rollingFile" filename="${logging_dir}/pinpoint-collector.log"
filepattern="${logging_dir}/pinpoint-collector-${rolling-date-format}-%i.log" >
Expand All @@ -29,8 +66,8 @@
<Delete basePath="${logging_dir}/" maxDepth="1">
<IfFileName glob="pinpoint-collector-*-*.log">
<IfAny>
<IfAccumulatedFileSize exceeds="1GB" />
<IfAccumulatedFileCount exceeds="50" />
<IfAccumulatedFileSize exceeds="${accumulated_file_size}" />
<IfAccumulatedFileCount exceeds="${accumulated_file_count}" />
</IfAny>
</IfFileName>
</Delete>
Expand All @@ -56,7 +93,7 @@
</Appenders>

<Loggers>
<Logger name="com.navercorp.pinpoint" level="DEBUG" additivity="false">
<Logger name="com.navercorp.pinpoint" level="${logger_level}" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="rollingFile"/>
</Logger>
Expand Down Expand Up @@ -90,11 +127,11 @@
<Appenderref ref="rollingFile"/>
</Logger>

<Logger name="io.grpc" level="DEBUG" additivity="false">
<Logger name="io.grpc" level="${logger_level}" additivity="false">
<AppenderRef ref="console"/>
<Appenderref ref="rollingFile"/>
</Logger>
<Logger name="io.netty" level="DEBUG" additivity="false">
<Logger name="io.netty" level="${logger_level}" additivity="false">
<AppenderRef ref="console"/>
<Appenderref ref="rollingFile"/>
</Logger>
Expand All @@ -107,7 +144,7 @@
<Logger name="com.navercorp.pinpoint.collector.StateReport" level="INFO" additivity="false">
<!-- disable : warn -->
<AppenderRef ref="stat-appender"/>
<!-- <Appender-ref ref="console"/>-->
<!--<Appender-ref ref="console"/>-->
</Logger>

<Root level="INFO">
Expand Down
103 changes: 0 additions & 103 deletions collector/src/main/resources/profiles/release/log4j2.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void processEnvironment(ConfigurableEnvironment environment) {
logger.info(String.format("%s=%s", PINPOINT_ACTIVE_PROFILE, pinpointProfile));

Pair<String, String> profile = ImmutablePair.of(PINPOINT_ACTIVE_PROFILE, pinpointProfile);
Pair<String, String> log4j2Path = log4j2Path(pinpointProfile);
Pair<String, String> log4j2Path = log4j2Path();

Properties properties = merge(profile, log4j2Path);
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
Expand Down Expand Up @@ -77,8 +77,8 @@ private String getDefaultProfile(String[] activeProfiles) {
return activeProfiles[0];
}

private Pair<String, String> log4j2Path(String pinpointActiveProfile) {
String logConfig = String.format("classpath:profiles/%s/log4j2.xml", pinpointActiveProfile);
private Pair<String, String> log4j2Path() {
String logConfig = "classpath:log4j2-spring.xml";

return ImmutablePair.of("logging.config", logConfig);
}
Expand Down
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
<embed.mongo>3.4.6</embed.mongo>

<mockito.version>4.8.1</mockito.version>
<bytebuddy.version> 1.12.18</bytebuddy.version>
<bytebuddy.version>1.12.18</bytebuddy.version>

<testcontainers.version>1.17.6</testcontainers.version>

Expand Down Expand Up @@ -815,6 +815,13 @@
</dependency>


<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-spring-boot</artifactId>
<version>${log4j2.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-spring-boot</artifactId>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
Expand Down
Loading

0 comments on commit 32c0b6d

Please # to comment.