Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][Log] Integrate slf4j and log4j2 for unified management logs #3025

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

hailin0
Copy link
Member

@hailin0 hailin0 commented Oct 8, 2022

Purpose of this pull request

proposal #2725

Change logs:

Maven dependencys:

  • Add slf4j & log4j2 provider & bridges scope into root pom.xml dependencyManagement
    • include: slf4j-api、log4j2、log4j2-slf4j-impl(slf4j provider)、xxx-to-slf4j
    • exclude(provided): logback、log4j1、commons-logging、slf4j-other-provider、log4j2-to-slf4j
  • Add slf4j & log4j2 & jcl-over-slf4j into root pom.xml dependencies
  • Exclude all logging system packages in maven-sheade-plugin

SeaTunnel engine module:

  • Enhanced logging http endpoint to dynamically change log4j2 level
  • Config hazelcast.logging.type: log4j2

SeaTunnel Dist module:

  • Use maven-assembly-plugin to copy slf4j & log4j2 & jcl-over-slf4j packages to lib/logging for use by starter shell

Engine Starter module[flink、spark]:

  • Use maven-dependency-plugin to copy slf4j & log4j2 & jcl-over-slf4j packages to target/logging-e2e for use by E2E testcase
  • Add lib/logging directory to java classpath in start shell for use by starter class
  • Add jcl-over-slf4j package into shade jar
  • Config config/log4j2-console.properties on engine-client
  • Exclude log4j & commons-logging from shade jar
  • Fix shell script tail last line text

Engine Starter module[seatunnel]:

  • Add disruptor jar and config -Dlog4j2.contextSelector to use asynchronous logger on engine-server
  • Config config/log4j2-file.properties on engine-server
  • Config config/log4j2-console.properties on engine-client
  • Add slf4j & log4j2 & jcl-over-slf4j package into starter shade jar
  • Support create new log file for submit local mode job

Connector-v1 module[seatunnel-connector-flink-clickhouse]:

  • Exclude commons-logging from shade jar

E2E:

  • Remove log4j.properties files
  • Add log4j2-test.properties output log to STDOUT or STDERR
  • Copy starter[flink、spark] target/logging-e2e into engine container
  • Copy config dir into engine container
  • Improve execute job logs

Check list

@hailin0
Copy link
Member Author

hailin0 commented Oct 8, 2022

Add notes to v1 documents:Need to add runtime jar to flink engine at runtime

image

appender.consoleWarn.filter.acceptGteWarn.type = ThresholdFilter
appender.consoleWarn.filter.acceptGteWarn.level = WARN
appender.consoleWarn.filter.acceptGteWarn.onMatch = ACCEPT
appender.consoleWarn.filter.acceptGteWarn.onMismatch = DENY
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log example: STDOUT、STDERR

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

public void handle(HttpGetCommand request) {
String uri = request.getURI();
if (uri.startsWith(HttpCommandProcessor.URI_LOG_LEVEL)) {
outputAllLoggerLevel(request);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example

image

public void handle(HttpPostCommand request) {
String uri = request.getURI();
if (uri.startsWith(HttpCommandProcessor.URI_LOG_LEVEL)) {
setLoggerLevel(request);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example

image

image

@hailin0 hailin0 force-pushed the integration_log4j2 branch 6 times, most recently from 03df195 to 6572476 Compare October 10, 2022 06:35
Comment on lines 21 to 23
property.file_split_size = 100MB
property.file_count = 100
property.file_ttl = 7d
Copy link
Member Author

@hailin0 hailin0 Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log files:
max bytes = 100MB * 100
max times = 7d

</goals>
<configuration>
<includeGroupIds>org.slf4j,org.apache.logging.log4j</includeGroupIds>
<outputDirectory>${project.build.directory}/logging-e2e</outputDirectory>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use by e2e

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

企业微信截图_c16d0688-371c-4240-a391-8fc404626ef7

Comment on lines -38 to -59
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<!-- Make sure the transitive dependencies are written to the generated pom under <dependencies> -->
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet>
<excludes>
<exclude>ch.qos.logback:*</exclude>
</excludes>
</artifactSet>
</configuration>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configuration from extends parent pom

Comment on lines 70 to 97
<configuration>
<artifactSet>
<excludes>
<!-- not excluded slf4j-api & log4j2 & bridges -->
<exclude>org.slf4j:slf4j-jdk14</exclude>
<exclude>org.slf4j:slf4j-nop</exclude>
<exclude>org.slf4j:slf4j-simple</exclude>
<exclude>org.slf4j:slf4j-reload4j</exclude>
<exclude>org.slf4j:slf4j-log4j12</exclude>
<exclude>log4j:*</exclude>
<exclude>commons-logging:*</exclude>
<exclude>ch.qos.logback:*</exclude>
<!-- -->
<exclude>org.apache.logging.log4j:log4j-to-slf4j</exclude>
</excludes>
</artifactSet>
</configuration>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Override the parent's configuration

include: slf4j-api & log4j2

fi

if [ -z $LOG4J2_CONTEXT_SELECTOR ]; then
LOG4J2_CONTEXT_SELECTOR="org.apache.logging.log4j.core.async.AsyncLoggerContextSelector"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enable async logger

Comment on lines +23 to +25
rest-api:
enabled: true
endpoint-groups:
CLUSTER_WRITE:
enabled: true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enable API: POST /hazelcast/rest/log-level

@hailin0 hailin0 force-pushed the integration_log4j2 branch 2 times, most recently from 372253f to 918c1fc Compare October 10, 2022 10:37
</goals>
<configuration>
<includeGroupIds>org.slf4j,org.apache.logging.log4j</includeGroupIds>
<outputDirectory>${project.build.directory}/logging-e2e</outputDirectory>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

企业微信截图_c16d0688-371c-4240-a391-8fc404626ef7

Comment on lines 64 to 75
<!-- not excluded: xxx-to-slf4j bridges, e.g. org.slf4j:jcl-over-slf4j -->
<exclude>org.slf4j:slf4j-api</exclude>
<exclude>org.slf4j:slf4j-jdk14</exclude>
<exclude>org.slf4j:slf4j-nop</exclude>
<exclude>org.slf4j:slf4j-simple</exclude>
<exclude>org.slf4j:slf4j-reload4j</exclude>
<exclude>org.slf4j:slf4j-log4j12</exclude>
<exclude>ch.qos.logback:*</exclude>
<exclude>log4j:*</exclude>
<exclude>org.apache.logging.log4j:*</exclude>
<exclude>commons-logging:*</exclude>
</excludes>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starter shade jar include jcl-over-slf4j

image

Comment on lines 55 to 95

<!-- Declare log4j2 asynchronous loggers provider: disruptor -->
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
</dependency>

</dependencies>

<build>
<finalName>${project.name}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<artifactSet>
<excludes>
<!-- not excluded: slf4j-api & log4j2 & xxx-to-slf4j bridges -->
<exclude>org.slf4j:slf4j-jdk14</exclude>
<exclude>org.slf4j:slf4j-nop</exclude>
<exclude>org.slf4j:slf4j-simple</exclude>
<exclude>org.slf4j:slf4j-reload4j</exclude>
<exclude>org.slf4j:slf4j-log4j12</exclude>
<exclude>log4j:*</exclude>
<exclude>commons-logging:*</exclude>
<exclude>ch.qos.logback:*</exclude>
<exclude>org.apache.logging.log4j:log4j-to-slf4j</exclude>
</excludes>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seatunnel starter shade jar include : slf4j-api、log4j-api、log4j-core、log4j-slf4j-impl、jcl-over-slf4j、disruptor

image

Comment on lines +124 to +130
<includes>
<include>org.slf4j:slf4j-api:jar</include>
<include>org.slf4j:jcl-over-slf4j:jar</include>
<include>org.apache.logging.log4j:log4j-api:jar</include>
<include>org.apache.logging.log4j:log4j-core:jar</include>
<include>org.apache.logging.log4j:log4j-slf4j-impl:jar</include>
</includes>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

企业微信截图_ffd01110-a84e-46c4-b1d8-4ab07c730025

MountableFile.forHostPath(loggingLibPath),
Paths.get(seatunnelHomeInContainer, "lib", "logging").toString());
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapping module dir to Container:

module dir:
企业微信截图_c16d0688-371c-4240-a391-8fc404626ef7

Container dir:
image

@hailin0
Copy link
Member Author

hailin0 commented Oct 10, 2022

Improve maven package:

starter[spark、flink]
change before:
starter shade jar include: slf4j、 log4j1.x
企业微信截图_bf7a05da-21c3-4fb6-996c-8cd9bb29a144

change after:
starter shade jar exclude: slf4j、 log4j1.x, include:jcl-over-slf4j
企业微信截图_f5f9b718-7404-49f1-a47c-d35d2e68c970

connector:example seatunnel-connector-flink-clickhouse
change before:
connector shade jar include: commons-logging, or other loggings
企业微信截图_574e6a49-c39a-45f7-a744-cb1fc068e6eb

change after:
connector shade jar exclude all logging packages
企业微信截图_1d2163d6-351f-480f-a02e-73660793dbc8

@EricJoy2048
Copy link
Member

Please fix CI problem.

@hailin0 hailin0 force-pushed the integration_log4j2 branch 4 times, most recently from 9617b2e to 4dec94e Compare October 11, 2022 09:14
Comment on lines +21 to +23
property.file_split_size = 100MB
property.file_count = 100
property.file_ttl = 7d
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log files:
max bytes = 100MB * 100
max times = 7d

rootLogger.appenderRef.consoleWarn.ref = consoleWarn
################################# console log #################################
################################# file log #################################
#rootLogger.appenderRef.file.ref = fileAppender
Copy link
Member Author

@hailin0 hailin0 Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable file log

Comment on lines +56 to +58
JAVA_OPTS="${JAVA_OPTS} -Dlog4j2.configurationFile=${CONF_DIR}/log4j2.properties"
JAVA_OPTS="${JAVA_OPTS} -Dseatunnel.logs.path=${APP_DIR}/logs"
JAVA_OPTS="${JAVA_OPTS} -Dseatunnel.logs.file_name=seatunnel-core-flink-sql"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add log4j2 system properties

JAVA_OPTS="${JAVA_OPTS} -Dseatunnel.logs.file_name=seatunnel-core-flink-sql"
fi

CLASS_PATH=${APP_DIR}/lib/logging/*:${APP_JAR}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add lib/logging/ into starter jar classpath

Comment on lines +69 to +70
echo "Execute SeaTunnel Flink SQL Job: $(echo "${CMD}" | tail -n 1)"
eval $(echo "${CMD}" | tail -n 1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tail last line text

Comment on lines +68 to +69
echo "Execute SeaTunnel Spark Job: $(echo "${CMD}" | tail -n 1)"
eval $(echo "${CMD}" | tail -n 1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix tail last line text: ${CMD} -> "${CMD}"

@hailin0 hailin0 changed the title [Feature][Log] Integration log4j2 [Feature][Log] Integrate slf4j and log4j2 for unified management logs Oct 11, 2022
@hailin0 hailin0 force-pushed the integration_log4j2 branch 3 times, most recently from 2189cf0 to e253812 Compare October 11, 2022 16:08
@hailin0
Copy link
Member Author

hailin0 commented Oct 12, 2022

@hailin0
Copy link
Member Author

hailin0 commented Oct 12, 2022

close #2474

@EricJoy2048
Copy link
Member

resolve conflicts please.

Copy link
Member

@ashulin ashulin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CalvinKirs CC, Does he need to resolve license conflicts?

@hailin0 hailin0 force-pushed the integration_log4j2 branch from e253812 to 60082ad Compare October 13, 2022 02:14
@hailin0 hailin0 force-pushed the integration_log4j2 branch 4 times, most recently from b1eee12 to ad9b5ea Compare October 20, 2022 11:55
@hailin0 hailin0 force-pushed the integration_log4j2 branch 5 times, most recently from 60afeb2 to 15b890d Compare October 29, 2022 14:38
Copy link
Member

@CalvinKirs CalvinKirs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
These two can be removed and we do not need to declare the standard AL2

@hailin0 hailin0 force-pushed the integration_log4j2 branch 3 times, most recently from d538c63 to a57c9b2 Compare October 31, 2022 11:10
EricJoy2048
EricJoy2048 previously approved these changes Nov 1, 2022
Copy link
Member

@EricJoy2048 EricJoy2048 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Maven dependencys:
- Add slf4j & log4j2 provider & bridges scope into root pom.xml dependencyManagement
  - include: slf4j-api、log4j2、log4j2-slf4j-impl(slf4j provider)、xxx-to-slf4j
  - exclude(provided): logback、log4j1、commons-logging、slf4j-other-provider、log4j2-to-slf4j
- Add slf4j & log4j2 & jcl-over-slf4j into root pom.xml dependencies
- Exclude all logging system packages in maven-sheade-plugin

SeaTunnel engine module:
- Enhanced logging http endpoint to dynamically change log4j2 level
- Config `hazelcast.logging.type: log4j2`

SeaTunnel Dist module:
- Use `maven-assembly-plugin` to copy slf4j & log4j2 & jcl-over-slf4j packages to `lib/logging` for use by starter shell

Engine Starter module[flink]:
- Use `maven-dependency-plugin` to copy slf4j & log4j2 & jcl-over-slf4j packages to `target/logging-e2e` for use by E2E testcase
- Add `lib/logging` directory to java classpath in start shell for use by starter class
- Add jcl-over-slf4j package into shade jar
- Config `config/log4j2-console.properties` on engine-client
- Exclude log4j1 & log4j2 & logback & commons-logging from shade jar
- Fix shell script tail last line text

Engine Starter module[spark]:
- Use `maven-dependency-plugin` to copy slf4j & log4j2 & jcl-over-slf4j packages to `target/logging-e2e` for use by E2E testcase
- Add `lib/logging` directory to java classpath in start shell for use by starter class
- Config `config/log4j2-console.properties` on engine-client
- Exclude log4j1 & log4j2 & logback & commons-logging from shade jar
- Fix shell script tail last line text

Engine Starter module[seatunnel]:
- Add `disruptor` jar and config `-Dlog4j2.contextSelector` to use asynchronous logger on engine-server
- Config `config/log4j2-file.properties` on engine-server
- Config `config/log4j2-console.properties` on engine-client
- Add slf4j & log4j2 & jcl-over-slf4j & log4j-1.2-api package into starter shade jar

Connector-v1 module[seatunnel-connector-flink-clickhouse]:
- Exclude commons-logging from shade jar

E2E:
- Remove `log4j.properties` files
- Add `log4j2-test.properties` output log to `STDOUT` or `STDERR`
- Copy starter[flink、spark] `target/logging-e2e` into engine container
- Copy config dir into engine container
- Improve execute job logs
@hailin0
Copy link
Member Author

hailin0 commented Nov 2, 2022

image

@hailin0 hailin0 requested review from ashulin, EricJoy2048 and Hisoka-X and removed request for ashulin, EricJoy2048 and Hisoka-X November 2, 2022 08:54
@Hisoka-X Hisoka-X merged commit 8241ec1 into apache:dev Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants