[D] Java CRaC support on static defined Loggers [logging-log 4j2]

david-ic3 (via GitHub) <[email protected]>
Newsgroups gmane.comp.jakarta.log4j.devel
Message-ID <ghd-D_kwDOAKJSSM4Aiaem__8762.83307313628$1760346862$gmane$org@gitbox.apache.org>
GitHub user david-ic3 created a discussion: Java CRaC support on static defined Loggers

What is the best practice to support Log4J when using [CRaC](https://docs.azul.com/crac/)  ?

In our code loggers are defined statically (yes this is the problem but ideally we do not change this) : 

`public static final Logger GENERAL = Logger.getLogger("icCube.general");`

The CRaC supported by :

```
        @Override
        public void beforeCheckpoint(Context<? extends Resource> context) throws Exception
        {
            LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
            loggerContext.stop();
        }

        @Override
        public void afterRestore(Context<? extends Resource> context) throws Exception
        {
            CdLog4jUtils.configure(xml); // here we reconfigure Log4J with a conf. file, fine

            LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
            loggerContext.start();
        }
```

Running now our code : 

```
This works :  Logger.getLogger("icCube.general").info(message);
This does nothing : GENERAL.info(message);   // the static field
```

After restore the static logger are not bind to the 'new' Logger. Is there a way to rebind/reset the loggers or a best practice ?



GitHub link: https://github.com/apache/logging-log4j2/discussions/3954

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.