Empty PropertyConfigurator implementation in log4j-1.2-api - log4j

I'm upgrading Log4j-1.2.17 to Log4j2-2.12.2 in my project.
To do that I'm using the log4j-1.2 bridge.
In old version I use property file to configure log4j.
After upgrade everything looks ok, no errors, no warnings. But logs don't appear in file pointed in properties file.
I realized that PropertyConfigurator.class exists in log4j-1.2-api.jar, but methods don't have implementation.
empty PropertyConfigurator.configure(Properties properties)
Can you explain me that?
Which configuration syntax is correct when I use log4j-1.2-api.jar? log4j or log4j2?

Prior to Log4j 2.13.0 log4j-1.2-api only provides compatibility for applications that used the log4j 1.x API for logging. The Log4j 2 configuration is still used as all logging calls are redirected to Log4j 2. So only the Log4j 2 configuration syntax would be valid.
Many of the old log4j 1.x internal classes are also present because many applications were using them in an attempt manually manipulate logging, much of which probably isn't necessary with Log4j 2.
In Log4j 2.13.0 the log4j-1.2-api was extended to provide experimental support for Log4j 1.x configuration files. You would have to compare your log4j 1 configurations with the documentation to determine if that support will work for you. However, the Log4j 1.x PropertyConfigurator still will be a no-op even with the compatibility support.

Related

Do I need to update log4j.properties file if I use the Log4j 1.x bridge (log4j-1.2-api)

I've followed the doc here : https://logging.apache.org/log4j/2.x/manual/migration.html
Also looked at https://logging.apache.org/log4j/2.x/manual/configuration.html#Properties
My existing log4j.properties only uses DailyRollingFileAppender, ConsoleAppender, both of which are under the 'Supported Components', so I shouldn't be forced to convert my log4j.properties file into log4j2.properties format. I'm not accessing methods and classes internal to the Log4j 1.x implementation, as suggested by the document.
For using the bridge, I previously was using both log4j1.compatibility and log4j.configuration, but the document suggests using 'any one' (tried using just one, doesn't work)
I can build my application successfully, however, my application no longer logs anything. What am I missing?
You may want to consider reload4j as a drop-in replacement for log4j 1.x. Initiated by Ceki Gülcü, the original author of Apache log4j 1.x, the reload4j project is a fork of Apache log4j version 1.2.17 with the goal of fixing pressing security issues.
The reload4j project offers a clear and easy migration path for the users who have an urgent need to fix vulnerabilities in log4j 1.2.17.
You don't need to update your properties file.
You can add a log4j2.component.properties file on the class path (in my case, in the same directory as my log4j.properties file) to set the log4j1.compatibility property, like this:
log4j1.compatibility=true
In our case, it only required setting the compatibility property and then it automatically picked up the log4j.properties file that was available on the class path.
Figured it out.
The answer lied in the Automatic Configuration section

What is Log4j 1.x's 'log4j.rootCategory'?

I've been struggling for weeks to upgrade Log4j from 1.x to 2.x. By far the biggest difficulty is converting the configuration, which the Log4j authors changed completely between versions without fully documenting how to migrate.
For example, my application currently uses Log4j 1.x with a log4j.properties file that starts with the following line:
log4j.rootCategory=WARN, CONSOLE
In order to convert this to Log4j 2.x configuration syntax, I have to first understand its meaning within the context of Log4j 1.x configuration syntax. This does not appear to be possible.
The Log4j 2.x Configuration Guide does not contain a reference to log4j.rootCategory or any other information that helps me understand its meaning.
The Log4j Migration Guide from 1.x to 2.x does not contain a reference to log4j.rootCategory or any other information that helps me understand its meaning.
I've searched for Log4j 1.x configuration documentation for two days now, and I've found nothing useful. I performed web searches for "log4j convert syntax", "log4j 1.x config documentation", "log4j.rootCategory documentation", "log4j rootCategory configuration" and more. None of these returned anything other than the above links or other pages that do not contain a reference to log4j.rootCategory or any other information that helps me understand its meaning.
This Stack Overflow question question states that "The actual Documentation for the LOG4J version 1.x is offline." This appears to be largely true, although #Tobias Otto provides a link to the Log4j 1.x manual at logging.apache.org/log4j/1.2/manual.html. This page does have a perfunctory "Configuration" section, but it does not contain a reference to log4j.rootCategory or any other information that helps me understand its meaning.
I'm out of ideas. What does setting log4j.rootCategory accomplish in the context of Log4j 1.x configuration syntax? How is this goal accomplished in the context of Log4j 2.x configuration syntax? Is there any meaningful documenation available for Log4j 1.x configuration directives?

Utility to convert log4j.xml to log4j2.xml

I am looking for the utility to convert log4j.xml to log4j2.xml syntax is there any utility available
At first I was going to respond that this cannot be done but it might be somewhat possible.
Log4j 2.13.0 added experimental support for using Log4j 1.x configuration files. If your configuration is compatible, in theory you could start up an application using a Log4j 1.x configuration and then call getRootNode() on the AbstractConfiguration. The root node is very similar to a DOM tree so walking it and converting it to XML wouldn't be too hard. However, Log4j doesn't have a tool provided to do this. Contributions are welcome!

How to Upgrade to log4j 2.x without changing any import statements

What is the best way to upgrade from log4j 1.x to 2.x
I have an ANT project. I just deleted the old jar and replaced it with the new log4j is that enough ?
Log4j 2 does not use the same configuration file format. However, Log4j 2.13.0 introduced experimental support for some Log4j 1 configuration files. So you have two choices:
Follow the steps outlined at Migrating from Log4j 1.x which involves including the log4j-1.2-api jar and converting your configuration files to Log4j 2 format or
Include the log4j-1.2-api jar but instead of converting your configuration files follow the steps at Log4j 2 Compatibility with Log4j 1
Note that since option 2 is experimental you may have configurations that Log4j 2 cannot handle. If that happens the Log4j 2 team welcomes you to report a Jira issue to determine how the support can be improved.

Where can I find the source code for log4j's ZeroConfSocketHubAppender?

I'm looking for a way to make log4net support zeroconf to publish logs to Apache Chainsaw (see here: Does log4net support zeroconf?). Apparently log4j can already do this using a ZeroConfSocketHubAppender.
Where might I be able to view the source for the java ZeroConfSocketHubAppender? I've looked both in the Apache Chainsaw and in the Log4j repositories but was unsuccessful.
ZeroConf is a log4j 'companion', but ZeroConfSocketHubAppender (and this companion) is no longer necessary due to the fact that most network-based appenders in log4j have ZeroConf support built-in as of log4j 1.2.16.
All you need to do to enable ZeroConf is add jmdns.jar to your classpath and set the 'advertiseViaMulticastDNS' param to 'true' in the appender configuration.
Here's the commit & log info describing the changes which improved ZeroConf support in the appenders (and receivers):
http://svn.apache.org/viewvc?view=revision&revision=924176
Here is a link to the ZeroConf page if you still want to use that
http://logging.apache.org/log4j/companions/zeroconf/source-repository.html
By the way, the svn HEAD revision of Chainsaw (which should be released soon) includes support for using the advertised ZeroConf appender information to automatically create receivers.

Resources