You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Mike Zhang Zhi (JIRA)" <ji...@apache.org> on 2016/01/11 07:22:39 UTC
[jira] [Resolved] (LOG4J2-1236) Logger is set to OFF after
thread.join()
[ https://issues.apache.org/jira/browse/LOG4J2-1236?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mike Zhang Zhi resolved LOG4J2-1236.
------------------------------------
Resolution: Incomplete
Fix Version/s: 2.5
Thanks for your comment. I try to set shutdownHook to false in log4j2.xml, and it works as expected now. It's because of concurrency execution in shutdown hook.
BTW. If I disable shutdownHook in log4j2.xml, do I need to finished the logger by myself? If so, how? I don't find any documentation about this.
> 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
> Fix For: 2.5
>
>
> 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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org