问题
如何修复使用Tinkerpop-3-Gremlin (Language)-GraphTraveralSource
时的Log4j2警告?
试过了
src/main/java/main.java
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
public class Main {
private static final Logger logger = LogManager.getLogger(Main.class);
public static void main(String[] args) throws Exception {
System.out.println("Hello world!");
logger.info("Hello world!");
GraphTraversalSource g = traversal().withRemote("conf/remote-graph.properties");
}
}
src/java/main/resources/log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp">
<Properties>
<Property name="baseDir">logs</Property>
</Properties>
<Appenders>
<RollingFile name="RollingFile" fileName="${baseDir}/${date:yyyy-MM-dd}/log-${date:yyyy-MM-dd}.log"
filePattern="logs/$${date:yyyy-MM}/app-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%d [%p] [%c{1.}.%t] ::	 %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true"/>
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
</RollingFile>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout>
<Pattern>%d [%p] [%c{1.}.%t] ::	 %m%n</Pattern>
</PatternLayout>
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
pom.xml
依赖关系:
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
预期
当我注解掉GraphTraversalSource
时,它工作得很好,但当它注解回来时失败了。
Log4j 2-logger显示“Hello world!“和系统一样。out does.
这只是从OrientDB设置中复制粘贴,而不是使用OrientGraph:
OrientGraph orientGraph = OrientGraph.open(configuration);
GraphTraversalSource g = orientGraph.traversal();
实际
Hello world!
2023-04-28 09:14:06,725 [INFO] [Main.main] :: Hello world!
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.
1条答案
按热度按时间oug3syen1#
谢谢Piotr P. Karwasz!
切换出slf 4j确实解决了我的问题。
注意
pom.xml
的顺序在这里很重要;如果Janusgraph + Tinkerpop出现在Log4j 2依赖项之前,则抛出错误。