Mike Zhang Zhi created LOG4J2-1236:
--------------------------------------

             Summary: Logger is set to OFF after thread.join()
                 Key: LOG4J2-1236
                 URL: https://issues.apache.org/jira/browse/LOG4J2-1236
             Project: Log4j 2
          Issue Type: Question
          Components: API
    Affects Versions: 2.5
            Reporter: Mike Zhang Zhi
            Priority: Minor


I have a launcher class with shutdownHook thread in main method:

Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    try {
                        logger.info("transefer server is stopping");
                        controller.stop();
                    } catch (Throwable e) {
                        logger.warn("something goes wrong when stopping 
transfer Server:\n{}",
                                Throwables.getStackTraceAsString(e));
                    } finally {
                        logger.info("transfer server is down.");
                    }
                }

            });

In controller to stop the server, I did things below:
    public void stop() {
        if (transferServer.isStart()) {
            transferServer.stop();
        }
        logger.info("Server is down");
    }

and in server, I stop instances like this:
   public void stop() {
        if (isStart()) {
            running = false;

            for (Map.Entry<String, TransferInstanceInterface> entry : 
transferInstances.entrySet()) {
                TransferInstanceInterface instance = entry.getValue();
                if (instance.isStart()) {
                    instance.stop();
                }
            }
            logger.info("Transfer server stopped");
        }
    }

and in instance I stop two thread:
    public void stop() {
        logger.info("Transfer instance[" + name + "] is stopping...");

        if (messageListener.isStart()) {
            messageListener.stop();
        }

        if (messageProcessor.isStart()) {
            messageProcessor.stop();
        }

        running = false;
        logger.info("Transfer instance[" + name + "] is down.");
    }

for messageListener, I stopped is like this:
    public void stop() {
        logger.info("Message listener for topic[" + topic + "] is stopping...");

        try {
            if (running) {
                running = false;
                if (null != consumer) {
                    consumer.close();
                }
                thread.join();
                logger.info("Message listener for topic[" + topic + "] is 
down.");
            }
        } catch (InterruptedException e) {
            logger.error(e.getMessage());
        }
    }

seems that after thread.join(), all the loggers are set to level off, and won't 
produce any log.
What the right way to make logger produce log entries after thread.join()?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to