GraphTraversalSource导致log4j:WARN No appenders could be found for logger(org.apache.commons.beanutils.converters.布尔转换器)

xnifntxz  于 2023-04-30  发布在  Apache
关注(0)|答案(1)|浏览(207)

问题

如何修复使用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] ::&#x09; %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] ::&#x09; %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.
oug3syen

oug3syen1#

谢谢Piotr P. Karwasz
切换出slf 4j确实解决了我的问题。

<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.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
            <version>2.20.0</version>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.slf4j</groupId>-->
<!--            <artifactId>slf4j-log4j12</artifactId>-->
<!--            <version>1.7.5</version>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-core</artifactId>
            <version>1.0.0-20230424-065649.dcd3240</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>gremlin-core</artifactId>
            <version>3.6.2</version>
        </dependency>

注意pom.xml的顺序在这里很重要;
如果Janusgraph + Tinkerpop出现在Log4j 2依赖项之前,则抛出错误。

│   pom.xml
│       
├───src
│   └───main
│       ├───java
│       │       Main.java
│       │
│       └───resources
│           │   log4j2.xml
│           │
│           └───conf
│                   remote-graph.properties
│                   remote-objects.yaml

相关问题