Logger is closed before verticles

73 views
Skip to first unread message

RCoe

unread,
Feb 4, 2021, 5:18:31 PM2/4/21
to vert.x
I'm using vertx 4 and have changed from the vertx logger factory to using Log4j2 directly.  I notice that verts detects my Lo4j2 dependency and uses it:

>  /usr/bin/env /usr/lib/jvm/java-11-openjdk-amd64/bin/java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:35959 -Dvertx.disableDnsResolver=true -Dfile.encoding=UTF-8 @/tmp/cp_3cscz8ccljowbsxi0dzpl2jc5.argfile chat.MainVerticle -conf /d/cygwin64/home/rcoe/linked/conf/config.json
Using io.vertx.core.logging.Log4j2LogDelegateFactory
Using Log4J2 as the default logging framework

Notice there is no VM argument that informs vertx to use Log4j2, which is what I had been using in vertx3.

What I've noticed is that the logger statements in my verticle.stop() method doesn't write the event to the appenders.

    @Override
    public void close()
    {
        clientPool.closear -> {
            ifar.succeeded() ) {
                LOGGER.info"Closing db client pool." );
            } else {
                LOGGER.error"...failed to close the database connection pool: "ar.cause() );
            }
        } );
    }

If I run with an attached debugger on the 'closing db pool' statement, I can see the code path is executed.  However, no log message is output the my appenders.

In my main verticle that deploys my other verticles, I have defined a shutdown hook handler and see this logs to my appenders:

    private final class ShutdownHook extends Thread
    {
        @Override
        public void run()
        {
            LOGGER.info"\nShutdown hook invoked." );
        }
    }

    private void launchVerticlesString[] args )
    {
        Launcher launcher = new Launcher();

        ArrayList<StringargList = new ArrayList<>();
        argList.add"run" );
        argList.addMainVerticle.class.getName() );
        argList.addAll1Arrays.asListargs ) );
        launcher.dispatchargList.toArraynew String[0] ) );

        Runtime.getRuntime().addShutdownHooknew ShutdownHook() );
    }

but like my other verticles, this one does not log:

    @Override
    public void stop()
        throws Exception
    {
        vertx.deploymentIDs().forEachvertx::rxUndeploy );
        LOGGER.info"Shutting down {}"getClass().getSimpleName() );
    }

I added the shutdown hook and loggers to the stop() methods to better understand the shutdown flow.  So one question I have is whether I need a shutdown hook when I'm delegating to the Launcher, or is there a shutdown hook that it registers, i.e., do I need to undeploy my verticles in my main verticle?  Other question is whether I should be able to use a logger reference in my stop() methods or must I use stdout?

Thanks,
Robin

Thomas SEGISMONT

unread,
Feb 5, 2021, 3:29:13 AM2/5/21
to vert.x
Automatic logging backend selection has been added in Vert.x 4, the old sysprop is still effective if you have several of them and need to force Vert.x to use a particular one.

If you use the Vert.x Launcher to start the Java app, there is no need to create a shutdown hook, the Launcher does it.

You should be able to log in stop methods. If you can create small reproducer, I'll have a look.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/767e213a-0211-40be-a408-c7c58e6359aen%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages