Skip to content

How can I configure log4j independently(Isolate 'LoggerContext')? #3528

Closed Answered by ppkarwasz
youngledo asked this question in Q&A
Discussion options

You must be logged in to vote

I understand, we need to create a new LoggerContext ourselves

Yes, if you wish to have an entirely separate set of loggers, you need to create a new LoggerContext:

LoggerContext context = new LoggerContext("-myApp");
Configuration configuration = ...;
context.start(configuration);

The fact that LoggerContext can be used with try-with-resources is a bug: you should close the context at the appropriate moment, e.g. when your application closes.

Remarks

Hardcoded config

I would not recommend using a hardcoded configuration, since your users might want to modify that. Unless explicitly configured, each logger context looks for configuration files named log4j2-<contextName>.<extension> (see c…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ppkarwasz
Comment options

Answer selected by youngledo
@youngledo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants