我在我的应用程序中使用 Neo4j 服务器,使用 REST 服务器启动嵌入式图形数据库。现在,neo4j-server 工件已包含logback.xml在其中。我还使用 logback 进行日志记录 => 我明白了
16:17:13,233 |-WARN in - Resource [logback.xml] occurs multiple times on the classpath.
16:17:13,233 |-WARN in - Resource [logback.xml] occurs at [file:/D:/dev/graph-server/target/classes/logback.xml]
16:17:13,233 |-WARN in - Resource [logback.xml] occurs at [jar:file:/C:/Users/user123/.m2/repository/org/neo4j/app/neo4j-server/1.8/neo4j-server-1.8.jar!/logback.xml]
Run Code Online (Sandbox Code Playgroud)
logback.xml多次出现的警告。
我应该怎么办?我不想关闭 logback 状态日志记录,每次启动应用程序时看到此消息有点令人不安。
谢谢。
亚历克斯
PS-我的logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<Target>System.out</Target>
<encoder>
<pattern>%d{dd/MM/yyyy HH:mm:ss } [%t] %-5p %logger{32} - %m%n</pattern>
</encoder>
</appender>
<logger name="com.myapp" level="INFO"/>
<root level="WARN">
<appender-ref ref="Console"/>
</root>
</configuration>
Run Code Online (Sandbox Code Playgroud) 您好,我正在使用以下版本的 logback 和 Janino :
<dependency org="ch.qos.logback" name="logback-core" rev="1.0.11" conf="runtime"/>
<dependency org="ch.qos.logback" name="logback-classic" rev="1.0.11" conf="runtime"/>
<dependency org="org.codehaus.janino" name="janino" rev="2.6.1" conf="runtime"/>
Run Code Online (Sandbox Code Playgroud)
使用条件记录配置<if>是:
<root level="INFO">
<if condition='property("xxx").contains("dev")'>
<then>
<appender-ref ref="dev" />
</then>
</if>
</root>
Run Code Online (Sandbox Code Playgroud)
我看到的错误如下:
7:38:54,729 |-ch.qos.logback.classic.joran.action.RootLoggerAction 中的 INFO - 将 ROOT 记录器级别设置为 INFO 无法实例化 [ch.qos.logback.classic.LoggerContext] 报告异常:java.lang .NoSuchMethodError: org.codehaus.janino.ClassBodyEvaluator.setImplementedInterfaces([Ljava/lang/Class;)V 位于 ch.qos.logback.core.joran.conditional.PropertyEvalScriptBuilder.build(PropertyEvalScriptBuilder.java:48) 位于 ch.qos。 logback.core.joran.conditional.IfAction.begin(IfAction.java:67) 位于 ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:276) 位于 ch.qos.logback.core。 joran.spi.Interpreter.startElement(Interpreter.java:148) 位于 ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:130) 位于 ch.qos.logback.core.joran.spi。 EventPlayer.play(EventPlayer.java:50) 位于 ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:157) 位于 ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java: 143) 在 ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:106) 在 ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:56) 在 ch.qos.logback .classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75) 在 ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148) 在 org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java …
我有一个要求,我想将所有 logback 配置放在 war 文件之外。目前,我已将配置文件(logback.xml)放在类路径上。我正在使用 JBOSS EAP Web 应用程序服务器,请建议如何实现相同的目标。
我试图让基于正则表达式的过滤与 logback 一起使用,但失败了。根据 logback 网站上的示例,这是我的 logback 配置的相应部分,但所有日志消息似乎都被它过滤掉了:
<appender name="__CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%-5level|%d{HH:mm:ss}] %logger{15} %msg [%thread] %n</pattern>
</encoder>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator>
<matcher>
<Name>custom</Name>
<regex>.*foobar.*</regex>
</matcher>
<expression>custom.matches(formattedMessage)</expression>
</evaluator>
<OnMismatch>DENY</OnMismatch>
<OnMatch>NEUTRAL</OnMatch>
</filter>
</appender>
Run Code Online (Sandbox Code Playgroud)
当我注释掉过滤器部分时,会显示与正则表达式匹配的日志语句。我一定错过了一些明显的东西。
我将此类LoggerProducer注入到@Statelessbean 中以生成日志条目,如此处所述。
问题是,当CustomerBean调用 时(甚至没有调用logger.info),该@Produces方法(检索 bean 类名)失败并显示NullPointerException。这段代码有什么问题?
@Named
@Singleton
public class LoggerProducer {
@Produces
public Logger produceLogger(InjectionPoint injectionPoint) {
return LoggerFactory.getLogger(
injectionPoint.getBean().getBeanClass()); // <- error here
}
}
Run Code Online (Sandbox Code Playgroud)
注入记录器的bean:
import org.slf4j.Logger;
@Stateless
@LocalBean
@Named
public class CustomerBean {
@Inject
private Logger logger;
......
logger.info("some message");
Run Code Online (Sandbox Code Playgroud) 我正在尝试以 JSON 格式获取日志输出。我通过配置 logback.xml 文件来实现它。是否可以通过YML 文件实现相同的目的?
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.contrib.json.classic.JsonLayout">
<jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
<prettyPrint>true</prettyPrint>
</jsonFormatter>
<timestampFormat>yyyy-MM-dd' 'HH:mm:ss.SSS</timestampFormat>
</layout>
</appender>
Run Code Online (Sandbox Code Playgroud) 我尝试编写一个 http 服务器,并且我想按照建议进行回滚。但是,我写的verticles似乎不受我使用的logback.xml的控制。
然后我写了我能想到的最简单的 Verticle,但是我的 logback.xml 似乎完全不起作用。
这是我的示例verticle:
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.core.logging.SLF4JLogDelegateFactory;
public class SimplestVerticle extends AbstractVerticle {
private static final Logger LOGGER = LoggerFactory.getLogger(SimplestVerticle.class);
@Override
public void start(Future<Void> future) {
Future<Void> newFuture = Future.future();
LOGGER.debug("This is debug");
LOGGER.info("This is info");
LOGGER.error("This is error");
newFuture.setHandler(future);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>[xxx]</groupId>
<artifactId>[xxx]</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version> …Run Code Online (Sandbox Code Playgroud) 我使用 SpringBoot 2.1 和 来spring-boot-maven-plugin自动git-commit-id-plugin使用构建信息填充执行器信息端点。效果很好。我将值分组在 json 属性build和git.
现在我还想将这些信息包含在 json 格式的日志消息中(使用 logback logstash)。因此我尝试使用springProperty扩展,但似乎这些元素不能用作环境条目。
<springProperty scope="context" name="info_version" source="info.build.version"/>
<springProperty scope="context" name="build_version" source="build.version"/>
Run Code Online (Sandbox Code Playgroud)
我这两种情况都没有得到解决。build-info.properties我还尝试通过手动添加作为属性源
@PropertySource("classpath:META-INF/build-info.properties")
Run Code Online (Sandbox Code Playgroud)
...但这似乎也不起作用。
因此,如何在日志消息中包含信息条目中的构建版本、git-commit 或其他内容等属性?
我正在尝试按照Springboot logback 自定义说明进行操作。
我想获得基本上默认的行为(所以我可以添加它)。
那个页面说:
A typical custom logback.xml file would look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/default.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
<logger name="org.springframework.web" level="DEBUG"/>
</configuration>
Run Code Online (Sandbox Code Playgroud)
......所以我试过了,我得到了
ch.qos.logback.core.joran.action.IncludeAction 中的警告 - 找不到对应于 [org/springframework/boot/logging/logback/default.xml] 的资源
我的 build.gradle 中有很多:
dependencies {
implementation(
'org.springframework.boot:spring-boot-starter-web',
'org.springframework.boot:spring-boot-starter-logging',
Run Code Online (Sandbox Code Playgroud)
...理论上我认为 starter-web 本身就足够了?
我错过了什么?
我有基于 Spring Boot 的 Web 应用程序,它使用 logback 进行日志记录。
我还使用以下命令从 Spring Boot 继承了一些 logback 默认值:
<include resource="org/springframework/boot/logging/logback/base.xml"/>
Run Code Online (Sandbox Code Playgroud)
我想开始记录跟踪信息,所以我补充道:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
Sleuth 将跟踪信息添加到日志行,但我找不到任何%X或%mdc模式:https : //github.com/spring-projects/spring-boot/blob/2.3.x/spring-boot-project/spring-boot /src/main/resources/org/springframework/boot/logging/logback/defaults.xml
Sleuth 如何将跟踪信息添加到日志行中?
我使用spring-cloud-starter-parent Hoxton.SR9父母带来Spring Boot 2.3.5.RELEASE和spring-cloud-starter-sleuth 2.2.6.RELEASE