Do you mean something like this?

public class MainApplication {


public static void main(String[] args) throws Exception {

Logger logger = LogManager.getLogger(MainApplication.class);

// logging level is error

logger.error("msg1");

logger.info("msg2");

org.apache.logging.log4j.core.LoggerContext context =
(org.apache.logging.log4j.core.LoggerContext) LogManager

.getContext(false);

Configuration config = context.getConfiguration();

config.getRootLogger().setLevel(Level.INFO);

context.updateLoggers(config);

// now logging level is info

logger.error("msg3");

logger.info("msg4");

}


}


On Tue, Feb 20, 2018 at 12:04 AM, Arnie Morein <[email protected]> wrote:

> Hello, looking for some advice, assuming this is possible.
>
> I am working with a rather complex application and the log4j2
> configuration is also complex (12+ loggers).
>
> It is started at war deployment by a WEB-INF/classes/log4j2.xml file and
> then after the context is started, based on the host name (ie, environment:
> prod, test, dev), the logging levels are changed to desired defaults.
>
> All of this works great. But now I need to build a control panel page that
> lists each appender/logger so certain settings can be changed or the file
> rotated at run time when situations arise.
>
> I know I can get a copy of the configuration from the file, but remember
> above, those defaults have already been changed based on the host name.
>
> I need to access the CURRENT in-memory configuration, but after digging
> through the API, I cannot find the right call for this, assuming it exists.
> Is there one?
>
> My point being is that if I use the altered config default based on host
> name, change a logger level from A to B, do some work, and want to return
> to the control panel to return B to A or make some other change, I won't
> see the fact that A is already at B.
>
> Thanks!
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to