0
문제를 해결하는 데 도움을주십시오 .Thx! :) log4j2를 사용하여 tomcat에서 로그를 출력하고 싶다면이 로그를 kafka에 출력 할 수 있습니다. 내 log4j2.xml 바람둥이에/lib 디렉토리는 다음과 같습니다 나는 바람둥이를 실행하면 로그 log4j에 변경되지 않습니다log4j2.xml의 kafka appender가 작동하지 않습니다.
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="WARN">
<Properties>
<Property name="CATALINA_BASE_LOGPATH">../logs</Property>
<Property name="logLocalIP">10.11.12.13</Property>
</Properties>
<appenders>
<console name="CONSOLE" target="SYSTEM_OUT">
<patternLayout charset="UTF-8"
pattern="%date{yyyy-MM-dd HH:mm:ss}[%-5level]%logger[%L]-%message%n" />
</console>
<rollingFile name="CATALINA"
fileName="${CATALINA_BASE_LOGPATH}/catalina.log"
filePattern="${CATALINA_BASE_LOGPATH}/catalina.%date{yyyyMMdd}">
<patternLayout charset="UTF-8"
pattern="%date{yyyy-MM-dd HH:mm:ss}[%-5level]%logger[%L]-%message%n" />
<policies>
<timeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="100 MB"/>
</policies>
</rollingFile>
<rollingFile name="LOCALHOST"
fileName="${CATALINA_BASE_LOGPATH}/localhost.log"
filePattern="${CATALINA_BASE_LOGPATH}/localhost.%date{yyyyMMdd}">
<patternLayout charset="UTF-8"
pattern="%date{yyyy-MM-dd HH:mm:ss}[%-5level]%logger[%L]-%message%n" />
<policies>
<timeBasedTriggeringPolicy />
</policies>
</rollingFile>
<rollingFile name="MANAGER"
fileName="${CATALINA_BASE_LOGPATH}/manager.log"
filePattern="${CATALINA_BASE_LOGPATH}/manager.%date{yyyyMMdd}">
<patternLayout charset="UTF-8"
pattern="%date{yyyy-MM-dd HH:mm:ss}[%-5level]%logger[%L]-%message%n" />
<policies>
<timeBasedTriggeringPolicy />
</policies>
</rollingFile>
<rollingFile name="HOST-MANAGER"
fileName="${CATALINA_BASE_LOGPATH}/host-manager.log"
filePattern="${CATALINA_BASE_LOGPATH}/host-manager.%date{yyyyMMdd}">
<patternLayout charset="UTF-8"
pattern="%date{yyyy-MM-dd HH:mm:ss}[%-5level]%logger[%L]-%message%n" />
<policies>
<timeBasedTriggeringPolicy />
</policies>
</rollingFile>
<Kafka name="KAFKA_DEBUG" topic="kafka">
<filters>
<thresholdFilter level="DEBUG" onMatch="ACCEPT"
onMismatch="DENY" />
</filters>
<patternLayout charset="UTF-8"
pattern="%date{yyyy-MM-dd HH:mm:ss}||%-5level||%logger||Tomcat||${logLocalIP}||%mdc{logRemoteIP}||%ex{short.className}.%ex{short.methodName}[%ex{short.lineNumber}]||%message||%ex{1}%n" >
</patternLayout>
<Property name="bootstrap.servers">localhost:9092</Property>
</Kafka>
</appenders>
<loggers>
<logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost]" level="INFO">
<appender-ref ref="LOCALHOST" />
</logger>
<logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]" level="INFO" additivity="false">
<appender-ref ref="MANAGER" />
</logger>
<logger name="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]" level="INFO" additivity="false">
<appender-ref ref="HOST-MANAGER" />
</logger>
<Logger name="org.apache.kafka" level="INFO" /><!-- avoid recursive logging -->
<root level="INFO">
<appender-ref ref="CATALINA" />
<appender-ref ref="KAFKA_DEBUG" />
<appender-ref ref="CONSOLE" />
</root>
</loggers>
</configuration>
는 다음과 같습니다 나는 <Kafka>...</Kafka>
펜더를 삭제하면
十二月 29, 2017 11:18:09 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version: Apache Tomcat/8.0.48
十二月 29, 2017 11:18:09 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built: Nov 30 2017 16:26:50 UTC
十二月 29, 2017 11:18:09 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number: 8.0.48.0
十二月 29, 2017 11:18:09 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name: Linux
十二月 29, 2017 11:18:09 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version: 4.10.0-42-generic
하지만, 로그는 log4j에 변경 :
2017-12-29 11:50:29,379 main ERROR Unable to locate appender "KAFKA_DEBUG" for logger config "root"
2017-12-29 11:50:29[INFO ]org.apache.catalina.startup.VersionLoggerListener[89]-Server version: Apache Tomcat/8.0.48
2017-12-29 11:50:29[INFO ]org.apache.catalina.startup.VersionLoggerListener[91]-Server built: Nov 30 2017 16:26:50 UTC
2017-12-29 11:50:29[INFO ]org.apache.catalina.startup.VersionLoggerListener[93]-Server number: 8.0.48.0
2017-12-29 11:50:29[INFO ]org.apache.catalina.startup.VersionLoggerListener[95]-OS Name: Linux
2017-12-29 11:50:29[INFO ]org.apache.catalina.startup.VersionLoggerListener[97]-OS Version: 4.10.0-42-generic
2017-12-29 11:50:29[INFO ]org.apache.catalina.startup.VersionLoggerListener[99]-Architecture: amd64
내 pom.xml 파일 :
<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.0</modelVersion>
<groupId>kafkaweb</groupId>
<artifactId>kafkaweb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.9.2</artifactId>
<version>0.8.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>0.8.2.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-web -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka-streams -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>0.10.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-jcl -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.9.1</version>
</dependency>
</dependencies>
</project>
로그 deosn't 출력은 바람둥이 버전 카프카합니다 : 아파치 - 톰캣-8.0.48
thx !!! 그것은 작동합니다 –
@ 뭐니 洋 그럼이 대답을 승인하고 가까운 것으로 표시하십시오 – Abhimanyu