vert-x / vertx-maven

Vert.x 2.x is deprecated - use instead
https://github.com/vert-x3/vertx-maven-starter
Other
22 stars 31 forks source link

Proper logging in vertx:runMod vs plain vertx runmod #37

Open pierrecdn opened 9 years ago

pierrecdn commented 9 years ago

Trying to normalize logs and log frameworks on my platform, I currently deploy docker images containing vert.x plus required jars and resources needed to make log4j 2.0 works.

In detail :

- jul-to-slf4j-${slf4j-version}.jar
- log4j-1.2-api-${log4j2-version}.jar
- log4-api-${log4j2-version}.jar
- log4-core-${log4j2-version}.jar
- log4-slf4j-impl-${log4j2-version}.jar
- slf4j-api-${slf4j-version}.jar
- logging.properties
- log4j2.xml

To reproduce this environment on a developer workstation I put these resource in src/main/platform_lib directory (maven project).

When I run the module using plain vertx, I pass these options and obtain good results (ie. consistent logging) :

MAIN_PATH="src/main"
PLATFORM_PATH=${MAIN_PATH}/platform_lib/"
RESOURCES_PATH=${MAIN_PATH}/resources/"
# Define VERTX and CLASSPATH env vars
VERTX_OPTS="-Dorg.vertx.logger-delegate-factory-class-name=org.vertx.java.core.logging.impl.SLF4JLogDelegateFactory"
CLASSPATH="${PLATFORM_PATH}"
for (jar in `ls -1 ${PLATFORM_PATH}/*.jar`); do 
    CLASSPATH="${CLASSPATH}:$jar";
done
# Run module
vertx runmod com.mycompany~my-module~0.1 -conf src/main/resources/my-module.json

But, trying to do the same with maven plugin via vertx:runMod, I fail in printing 95% of logs, probably because of maven embedded logger (3.0.5) or something like that :

<plugin>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-maven-plugin</artifactId>
    <version>${maven.vertx.plugin.version}</version>
    <configuration>
        <instances>1</instances>
        <configFile>src/main/resources/my-module.json</configFile>
    </configuration>
</plugin>
MAVEN_OPTS="-Dorg.vertx.logger-delegate-factory-class-name=org.vertx.java.core.logging.impl.SLF4JLogDelegateFactory"; mvn vertx:runMod 

(It seems that the "main" module could not instantiate any logging implementation and/or bridges)

Debugging the plugin result in :

Any feedbacks on this subject ?

pierrecdn commented 9 years ago

Trying maven-3.2.3, it's a little better since it implements SLF4J vs. Plexus logging API (http://maven.apache.org/maven-logging.html), and probably for this reason I've no no more complains like that :


SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

But, typically, it doesn't take in account the log4j2.xml file in the classpath, and there are still some components that don't log anything.

If I do some operations in maven directories :

It seems that maven logging configuration preempt any other given by an embedded vert.x core

May not be a bug, but any advice will be appreciated !