How do I use a log4j 2.x lib in a log4j 1.x app - log4j

I know it is possible to use a log4x1.x based lib in a log4j2 based application. But what I need is the other way around: I have an applicaiton that is based on log4j1.x and my lib is already on log4j2. Is there any bridge out there?

Related

Is it possible to configure log4j to use a proxy are part of its connections out to Splunk, Datadog, etc?

If log4j doesn't support this then is there some drop-in replacement for log4j that does? I've gone through the docs and lots of google searches, unfortunately all search results come up with "exploit" or "vulnerability" articles.
Splunk provides a splunk-library-javalogging that has appenders for both Log4j2 Core (the reference Log4j2 API implementation) and Logback (the reference SLF4J API implementation).
The appenders use OkHttp 3.x under the hood, so they will behave as all OkHttp-based components. Since splunk-library-javalogging does not set either a proxy nor a proxySelector explicitly (cf. source code), OkHttp falls back to the system wide ProxySelector.
Without any code modification on your part you can use the JVM-wide proxy settings as in this question.
Remark: if by log4j you are referring to Log4j 1.x, you need to replace the log4j:log4j artifact with either log4j-over-slf4j (which forwards to the SLF4J API) or log4j-1.2-api (which forwards to the Log4j2 API).

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

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!

Empty PropertyConfigurator implementation in log4j-1.2-api

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.

jboss7 + same log4j configuration for different apps

I want to deploy some different applications using one jboss (jboss as 7). Can anyone make it clear for me if its possible to set one log4j configuration (log4j.xml) for multiple wars and ears or i'll have to put a copy of configuration into each archive?
Or maybe someone can suggest a differeng logging engine, more native to jboss7?
log4j configuration is always global to runtime. ie. A JBoss instance can't have multiple log4j configuration. log4j can be initialized or reinitialized with a single config file. it can be a simple properties file or a XML incompliance with log4j.dtd packaged with log4j*.jar. start the jboss instance with -Dlog4j.configuration=/anypath/log4jconfig.xml
I do not believe there is a way to configure log4j globally. JBoss AS7 uses JBoss Logging for it's log provider. You can configure the logging subsystem is in the standalone.xml or the domain.xml depending on if you're running in standalone or domain mode.
The documentation is not greatest unfortunately, but if you install the jboss-as-logging_1_1.xsd in your IDE you can get auto-complete. All the schemas are located in the docs/schema under the installed directory.

Resources