On Fri, 6 May 2022 at 10:40, Nilay Prafulla Dhamecha <npraf...@tibco.com.invalid> wrote:
> The explanation about the arbitrary string identifiers is what I was > looking for, I changed the identifiers and the logging is working. > However, can you brief me on what a concrete logger is exactly and how is > it different from other logger configs? > Sorry, I must have used the wrong adjective. The choice of many identifiers in the properties format are totally arbitrary (they just can not contain a dot), but properties for the same component must use the same identifier. E.g. logger.<'$"1.name = org.apache.logging logger.<'$"1.level = INFO logger.%^&*.name = org.apache.logging.log4j logger.%^&*.level = DEBUG > And I will consider your advice of switching to a different format for > configuration file than properties. > However in our project we have 2 files present simultaneously XML and > properties and by default, log4j2 picks the properties file, can you > suggest how to turn off this default behavior programmatically? > I know we can pass a java property -Dlog4j.configuration but I want to > know if there is an alternative way to do it via code. > Logging configuration is usually performed by static initialization code (most calls to a `LogManager` method initialize a logger context), hence it will probably execute before the initialization of your application. What you can do is to programmatically reconfigure Log4j2 using `Configurator.reconfigure` ( https://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/config/Configurator.html#reconfigure-java.net.URI-). Reconfiguration is safe and does not lose messages. However I would avoid programmatic configuration (or keep it as last resort), since your users will not be able to modify it. If you don't want to use the `-D...` command line switch, there are other ways to set a Log4j2 property (cf. https://logging.apache.org/log4j/2.x/manual/configuration.html#SystemProperties), e.g. you can put it in a `log4j2.component.properties` file. Piotr