How-To-Fix Log4j2 Warnings
When Using Tinkerpop-3-Gremlin (Language)-GraphTraveralSource
?
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:
<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>
This works fine when I comment out GraphTraversalSource
but fails when its commented back in.
The Log4j2-logger does show the "Hello world!" fine just like System.out does.
And this is just a copy-paste from an OrientDB setup that instead uses 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.
Thanks Piotr P. Karwasz!
Switching out the slf4j did fix my issue.
<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>
Note the pom.xml
order did matter here;
Throws error if Janusgraph + Tinkerpop came before Log4j2 dependencies.
│ pom.xml
│
├───src
│ └───main
│ ├───java
│ │ Main.java
│ │
│ └───resources
│ │ log4j2.xml
│ │
│ └───conf
│ remote-graph.properties
│ remote-objects.yaml