IntelliJ idea中日志打印中文乱码

Win10的 IntelliJ idea中log4j2控制台中文乱码的几种处理方法

slf4j是外层框架,具体实现靠log4j、log4j2
log4j配置文件用log4j.properties
log4j2配置文件用log4j2.xml

打开idea安装目录: /bin中的idea64.exe.vmoptions,在末尾添加-Dfile.encoding=UTF-8 重启Idea即可
IntelliJ idea中日志打印中文乱码_第1张图片

IntelliJ idea中日志打印中文乱码_第2张图片

Log4j2.xml的配置文件编码 charset=“UTF-8” 修改为: charset=“GBK”
IntelliJ idea中日志打印中文乱码_第3张图片


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>

	<groupId>org.examplegroupId>
	<artifactId>myflinkartifactId>
	<version>1.0-SNAPSHOTversion>
	<packaging>jarpackaging>

	<name>FlinkQJobname>
	<url>http://www.myorganization.orgurl>

	<properties>
		<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
		<flink.version>1.8.1flink.version>
		<java.version>1.8java.version>
		<scala.version>2.11.8scala.version>
		<scala.binary.version>2.11scala.binary.version>
		<maven.compiler.source>${java.version}maven.compiler.source>
		<maven.compiler.target>${java.version}maven.compiler.target>
	properties>

	<repositories>
		<repository>
			<id>apache.snapshotsid>
			<name>Apache Development Snapshot Repositoryname>
			<url>https://repository.apache.org/content/repositories/snapshots/url>
			<releases>
				<enabled>falseenabled>
			releases>
			<snapshots>
				<enabled>trueenabled>
			snapshots>
		repository>
	repositories>

	<dependencies>
		
		
		<dependency>
			<groupId>org.apache.flinkgroupId>
			<artifactId>flink-javaartifactId>
			<version>${flink.version}version>
		dependency>
		<dependency>
			<groupId>org.apache.flinkgroupId>
			<artifactId>flink-runtime-web_2.11artifactId>
			<version>${flink.version}version>
		dependency>
		<dependency>
			<groupId>org.apache.flinkgroupId>
			<artifactId>flink-streaming-java_${scala.binary.version}artifactId>
			<version>${flink.version}version>
		dependency>











		<dependency>
			<groupId>org.slf4jgroupId>
			<artifactId>slf4j-apiartifactId>
			<version>1.7.15version>
		dependency>

		<dependency>
			<groupId>org.apache.logging.log4jgroupId>
			<artifactId>log4j-coreartifactId>
			<version>2.11.1version>
		dependency>
		<dependency>
			<groupId>org.apache.logging.log4jgroupId>
			<artifactId>log4j-apiartifactId>
			<version>2.11.0version>
		dependency>
		<dependency>
			<groupId>org.apache.logging.log4jgroupId>
			<artifactId>log4j-slf4j-implartifactId>
			<version>2.11.1version>
		dependency>


	dependencies>

	<build>
		<plugins>

			
			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-compiler-pluginartifactId>
				<version>3.6.0version>
				<configuration>
					<source>${java.version}source>
					<target>${java.version}target>
				configuration>
			plugin>

			
			
			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-shade-pluginartifactId>
				<version>3.2.1version>
				<executions>
					<execution>
						<phase>packagephase>
						<goals>
							<goal>shadegoal>
						goals>
						<configuration>
							<relocations>
								<relocation>
									<pattern>com.google.gsonpattern>
									<shadedPattern>com.shade.gsonshadedPattern>
								relocation>
							relocations>
							<artifactSet>
								<excludes>
									<exclude>org.apache.flink:force-shadingexclude>
									<exclude>com.google.code.findbugs:jsr305exclude>
									<exclude>org.slf4j:*exclude>
									<exclude>log4j:*exclude>
									<exclude>ch.qos.logback:*exclude>
								excludes>
							artifactSet>
							<filters>
								<filter>
									<artifact>*:*artifact>
									<excludes>
										<exclude>META-INF/*.SFexclude>
										<exclude>META-INF/*.DSAexclude>
										<exclude>META-INF/*.RSAexclude>
										<exclude>org/apache/log4j/**exclude>
										<exclude>org/slf4j/**exclude>
										<exclude>org/apache/logging/log4j/**exclude>
										<exclude>ch/qos/logback/**exclude>
										<exclude>META-INF/maven/log4j/**exclude>
										<exclude>META-INF/maven/org.slf4j/**exclude>
										<exclude>META-INF/maven/ch.qos.logback/**exclude>
										<exclude>META-INF/maven/org.apache.logging.log4j/**exclude>
										<exclude>log4j.propertiesexclude>
										<exclude>logback.xmlexclude>
										<exclude>log4j2.xmlexclude>
									excludes>
								filter>
							filters>
						configuration>
					execution>
				executions>
			plugin>
		plugins>
	build>

	
	
	
	<profiles>
		<profile>
			<id>demoid>
			<activation>
				<property>
					<name>idea.versionname>
				property>
			activation>

			<dependencies>
				<dependency>
					<groupId>org.apache.flinkgroupId>
					<artifactId>flink-javaartifactId>
					<version>${flink.version}version>
					<scope>compilescope>
				dependency>
				<dependency>
					<groupId>org.apache.flinkgroupId>
					<artifactId>flink-streaming-java_${scala.binary.version}artifactId>
					<version>${flink.version}version>
					<scope>compilescope>
				dependency>
			dependencies>
		profile>
	profiles>

project>

你可能感兴趣的:(intellij-idea,log4j,java)