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]

Reply via email to