我通过扩展AbstractLoggingActor实现了actor。但不知何故,akka日志只被写入控制台而不是日志文件,并且不会抛出任何错误。
我在akka中尝试了各种配置,使用与实际akka版本相同版本的akka-slf4j但没有帮助。我附加了我最初使用的原始pom配置。
logback.xml
<appender name="fileAppender" class="ch.qos.logback.core.FileAppender">
<file>/opt/Corp-Async-Job-Processor/logs/corp-job-akka-framework.log</file>
<append>true</append>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level>
</filter>
<encoder>
<pattern>%date{ISO8601} - %logger -> %-5level[%thread] %logger{0} - %msg%n</pattern>
</encoder>
</appender>
<!--appender name="Sentry" class="io.sentry.logback.SentryAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
</appender-->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>debug</level>
</filter>
<encoder>
<pattern>%date{ISO8601} - %logger -> %-5level[%thread] %logger{0} - %msg%n</pattern>
</encoder>
</appender>
<logger name="akka" level="debug" />
<logger name="com.packt" level="debug"/>
<root level="TRACE">
<appender-ref ref="fileAppender"/>
<appender-ref ref="console"/>
</root>
application.conf:
akka {
loglevel = "DEBUG"
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
}
模块的pom.xml中的依赖项:
<dependencies>
<dependency>
<groupId>com.github.davidmoten</groupId>
<artifactId>rxjava-jdbc</artifactId>
<version>0.7.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.davidmoten</groupId>
<artifactId>rxjava-jdbc</artifactId>
<version>0.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.11.RELEASE</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http_${artifact.id.version}</artifactId>
<version>${akka.http.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http-jackson_${artifact.id.version}</artifactId>
<version>${akka.http.version}</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-stream_${artifact.id.version}</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf</artifactId>
<version>9.1.9</version>
</dependency>
<!--dependency>
<groupId>de.idyl</groupId>
<artifactId>winzipaes</artifactId>
<version>1.0.1</version>
</dependency-->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http-testkit_${artifact.id.version}
</artifactId>
<version>${akka.http.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.232</version>
</dependency>
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
项目的pom.xml:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<akka.version>2.5.4</akka.version>
<artifact.id.version>2.12</artifact.id.version>
<akka.http.version>10.0.10</akka.http.version>
<mysql.version>6.0.5</mysql.version>
<slf4j.version>1.6.6</slf4j.version>
<logback.version>1.0.7</logback.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_${artifact.id.version}</artifactId>
<version>${akka.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.11.RELEASE</version>
</dependency>
</dependencies>
答案 0 :(得分:0)
Logback的ThresholdFilter
拒绝级别低于配置阈值的事件。您的FileAppender
具有以下过滤条件:
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level>
</filter>
以上配置意味着TRACE和DEBUG事件被拒绝。相反,您的ConsoleAppender
的{{1}}设置为DEBUG,仅拒绝TRACE事件。因为您的Akka日志级别设置为DEBUG,所以Akka日志消息会将其发送到控制台,但永远不会将其发送到日志文件。
要将Akka日志输出到控制台和文件,请更改ThresholdFilter
中过滤器的阈值:
FileAppender