You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Pablo Rogina <pa...@gmail.com> on 2022/03/29 17:58:35 UTC

Log4j 1.2.x Customer Appender not used as "Plugin" by Log4j 1.2 Bridge

Hi,

I have an old application using Log4j 1.2.x and we're using Log4j 1.2
Bridge from Log4j 2.17.2 to mitigate some vulnerabilities while
minimizing source code changes.
The application uses Log4j v1 properties file for configuration.

We developed a custom appender by extending RollingFileAppender and
it's contained in its own JAR file.
With all components in place (log4j-api.jar, log4j-1.2-api.jar,
log4j-core.api, custom-appender.jar) most of the properties are
processed and appenders, layouts are created.
However this warning appears (application launched with -Dlog4j2.debug=true):
WARN StatusLogger Unable to load plugin class name
com.mycompany.log4j.CustomAppender with key
com.mycompany.log4j.customappender

And then the maxFileSize for log files and backup index files are messed up.

I found the "packages" attribute from Configuration but I was not able
to make it work:
1. given that we're not using an XML or JSON configuration file I
don't know how to set the "packages" property for Configuration in a
log4j v1 properties file
2. tried system variable
-Dlog4j.plugin.packages=com.mycompany.log4j.CustomAppender

Thank you.

Pablo Rogina

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j 1.2.x Customer Appender not used as "Plugin" by Log4j 1.2 Bridge

Posted by Ralph Goers <ra...@dslextreme.com>.
Comments below.

> On Mar 29, 2022, at 3:01 PM, Pablo Rogina <pa...@gmail.com> wrote:
> 
> Ralph, thank you for your reply.
> 
>> To be usable in your configuration a Log4j 1.2 Appender cannot be a Log4j2 plugin.
> Ok. It is not, as my CustomAppender extends RollingFileAppender (from
> Log4j v 1.2.x)
> 
>> You would configure it exactly as you do in log4j 1.x, via its class name.
> Ok. I think it's what I'm doing.
> This is the properties I'm using to configure my app logging:
> log4j.appender.MYAPPLOGFILE=com.mycompany.log4j.CustomAppender
> log4j.appender.MYAPPLOGFILE.Append=false
> log4j.appender.MYAPPLOGFILE.SpecialValue=ABC
> log4j.appender.MYAPPLOGFILE.HeaderVersion=1
> log4j.appender.MYAPPLOGFILE.File=logs/MyApp.log
> log4j.appender.MYAPPLOGFILE.MaxBackupIndex=19
> log4j.appender.MYAPPLOGFILE.MaxFileSize=2000KB
> log4j.appender.MYAPPLOGFILE.layout=org.apache.log4j.PatternLayout
> log4j.appender.MYAPPLOGFILE.layout.ConversionPattern=%d{[dd MMM yyyy
> HH\:mm\:ss,SSS]}[%t]\:%-5p\:%l -->%m%n
> log4j.rootLogger=INFO, MYAPPLOGFILE


For this can you run your application with -Dlog4j2.debug=true? I’d like to see what is happening.

> 
>> That said, Do you really need your custom RollingFileAppender? The RollingFileAppender
>> in Log4j 2 has many more options than Log4j 1 did.
> 
> Well, I also have a CustomAppender for Log4j 2 that resembles a
> RollingFileAppender, defined like this:
> 
> @Plugin(name = CustomAppender.PLUGIN_NAME, category =
> Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject =
> true)
> public final class CustomAppender extends
> AbstractOutputStreamAppender<RollingFileManager> {
> ...
> 
> however I also got the "Unable to load plugin class name ..." issue if
> using the CustomAppender v2.
> And I also find difficult to configure it via Properties using the
> Log4j 1.2 Bridge

Yes, that is understandable. The problem is that the Log4j 1 support cannot directly deal with 
a Log4j 2 Appender. It has to wrap it to make it look like a Log4j 1 Appender. So you could 
either create your own Builder that is similar to the other AppenderBuilders or you can define 
your custom Log4j.2 Appender in its own Log4j 2 configuration file and then merge it with your 
Log4j 1 configuration as a composite configuration - see https://logging.apache.org/log4j/2.x/manual/configuration.html#CompositeConfiguration <https://logging.apache.org/log4j/2.x/manual/configuration.html#CompositeConfiguration>.

Ralph


Re: Log4j 1.2.x Customer Appender not used as "Plugin" by Log4j 1.2 Bridge

Posted by Pablo Rogina <pa...@gmail.com>.
Ralph, thank you for your reply.

> To be usable in your configuration a Log4j 1.2 Appender cannot be a Log4j2 plugin.
Ok. It is not, as my CustomAppender extends RollingFileAppender (from
Log4j v 1.2.x)

> You would configure it exactly as you do in log4j 1.x, via its class name.
Ok. I think it's what I'm doing.
This is the properties I'm using to configure my app logging:
log4j.appender.MYAPPLOGFILE=com.mycompany.log4j.CustomAppender
log4j.appender.MYAPPLOGFILE.Append=false
log4j.appender.MYAPPLOGFILE.SpecialValue=ABC
log4j.appender.MYAPPLOGFILE.HeaderVersion=1
log4j.appender.MYAPPLOGFILE.File=logs/MyApp.log
log4j.appender.MYAPPLOGFILE.MaxBackupIndex=19
log4j.appender.MYAPPLOGFILE.MaxFileSize=2000KB
log4j.appender.MYAPPLOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.MYAPPLOGFILE.layout.ConversionPattern=%d{[dd MMM yyyy
HH\:mm\:ss,SSS]}[%t]\:%-5p\:%l -->%m%n
log4j.rootLogger=INFO, MYAPPLOGFILE

> That said, Do you really need your custom RollingFileAppender? The RollingFileAppender
> in Log4j 2 has many more options than Log4j 1 did.

Well, I also have a CustomAppender for Log4j 2 that resembles a
RollingFileAppender, defined like this:

@Plugin(name = CustomAppender.PLUGIN_NAME, category =
Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject =
true)
public final class CustomAppender extends
AbstractOutputStreamAppender<RollingFileManager> {
...

however I also got the "Unable to load plugin class name ..." issue if
using the CustomAppender v2.
And I also find difficult to configure it via Properties using the
Log4j 1.2 Bridge

Regards. Pablo

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j 1.2.x Customer Appender not used as "Plugin" by Log4j 1.2 Bridge

Posted by Ralph Goers <ra...@dslextreme.com>.
To be usable in your configuration a Log4j 1.2 Appender cannot be a Log4j2 plugin.
You would configure it exactly as you do in log4j 1.x, via its class name.

That said, Do you really need your custom RollingFileAppender? The RollingFileAppender 
in Log4j 2 has many more options than Log4j 1 did. 

Ralph

> On Mar 29, 2022, at 10:58 AM, Pablo Rogina <pa...@gmail.com> wrote:
> 
> Hi,
> 
> I have an old application using Log4j 1.2.x and we're using Log4j 1.2
> Bridge from Log4j 2.17.2 to mitigate some vulnerabilities while
> minimizing source code changes.
> The application uses Log4j v1 properties file for configuration.
> 
> We developed a custom appender by extending RollingFileAppender and
> it's contained in its own JAR file.
> With all components in place (log4j-api.jar, log4j-1.2-api.jar,
> log4j-core.api, custom-appender.jar) most of the properties are
> processed and appenders, layouts are created.
> However this warning appears (application launched with -Dlog4j2.debug=true):
> WARN StatusLogger Unable to load plugin class name
> com.mycompany.log4j.CustomAppender with key
> com.mycompany.log4j.customappender
> 
> And then the maxFileSize for log files and backup index files are messed up.
> 
> I found the "packages" attribute from Configuration but I was not able
> to make it work:
> 1. given that we're not using an XML or JSON configuration file I
> don't know how to set the "packages" property for Configuration in a
> log4j v1 properties file
> 2. tried system variable
> -Dlog4j.plugin.packages=com.mycompany.log4j.CustomAppender
> 
> Thank you.
> 
> Pablo Rogina
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j 1.2.x Customer Appender not used as "Plugin" by Log4j 1.2 Bridge

Posted by Pablo Rogina <pa...@gmail.com>.
Hi Piotr,

your suggestion did the trick.

I added a CustomAppenderBuilder into the same package of my
CustomAppender based on Log4j2.
So this new CustomAppenderBuilder can parse a Properties object in
Log4j1 syntax and creates CustomAppender v2 via AppenderWrapper (from
the Log4j 1.2 Bridge).

In summary, no changes to the application: it continues using loggers
from v1, keeps using a Properties object with Log4j1 syntax for
configuration, while the actual management of log files is carried on
by Log4j2-based CustomAppender.

Thank you for the assistance!

Regards. Pablo

On Wed, Mar 30, 2022 at 5:44 AM Piotr P. Karwasz
<pi...@gmail.com> wrote:
>
> Hello Pablo,
>
> On Tue, 29 Mar 2022 at 19:58, Pablo Rogina <pa...@gmail.com> wrote:
> > However this warning appears (application launched with -Dlog4j2.debug=true):
> > WARN StatusLogger Unable to load plugin class name
> > com.mycompany.log4j.CustomAppender with key
> > com.mycompany.log4j.customappender
>
> This is an expected behavior. Most common Log4j 1.x components are
> actually translated into their Log4j 2.x equivalents using
> configuration builder plugins. See [1] for example. If you were using
> "standard" Log4j 1.x components (e.g. org.apache.log4j.FileAppender),
> this warning means that the system is using the real
> org.apache.log4jFileAppender class instead of its Log4j 2.x
> equivalent, which might result in poor performance.
>
> You can actually also write such a builder plugin yourself, if you
> wish to use a Log4j 1.x configuration to start your custom Log4j 2.x
> appender.
>
> Piotr
>
> [1] https://github.com/apache/logging-log4j2/blob/release-2.x/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/RollingFileAppenderBuilder.java
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Log4j 1.2.x Customer Appender not used as "Plugin" by Log4j 1.2 Bridge

Posted by "Piotr P. Karwasz" <pi...@gmail.com>.
Hello Pablo,

On Tue, 29 Mar 2022 at 19:58, Pablo Rogina <pa...@gmail.com> wrote:
> However this warning appears (application launched with -Dlog4j2.debug=true):
> WARN StatusLogger Unable to load plugin class name
> com.mycompany.log4j.CustomAppender with key
> com.mycompany.log4j.customappender

This is an expected behavior. Most common Log4j 1.x components are
actually translated into their Log4j 2.x equivalents using
configuration builder plugins. See [1] for example. If you were using
"standard" Log4j 1.x components (e.g. org.apache.log4j.FileAppender),
this warning means that the system is using the real
org.apache.log4jFileAppender class instead of its Log4j 2.x
equivalent, which might result in poor performance.

You can actually also write such a builder plugin yourself, if you
wish to use a Log4j 1.x configuration to start your custom Log4j 2.x
appender.

Piotr

[1] https://github.com/apache/logging-log4j2/blob/release-2.x/log4j-1.2-api/src/main/java/org/apache/log4j/builders/appender/RollingFileAppenderBuilder.java

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org