Skip to content

Two question about LogManager and LoggingContext in JavaEE/JakartaEE apps #1844

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

You must be logged in to vote

@Bukama,

After upgrading the PMD analyser tools it now shows a warning that the LoggerContext should be closed after usage. This brings me to the question if we can savely do this, without loosing the set URL. For my understanding the line

LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);

gets a reference and not a copy of the context and therefore if I would close the context after I set the URL of the config file it would be lost?

Yes, loggerContext is a reference to the logger context and if you close it, it shuts down. I am not sure why the AutoCloseable interface was added to LoggerContext, since in most situation you don't want to use it in a try with res…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jvz
Comment options

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