Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1236

Logger is set to OFF after thread.join()

    XMLWordPrintableJSON

Details

    • Question
    • Status: Resolved
    • Minor
    • Resolution: Incomplete
    • 2.5
    • 2.5
    • API
    • None

    Description

      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()?

      Attachments

        Activity

          People

            Unassigned Unassigned
            snowwolf007cn@gmail.com Mike Zhang Zhi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: