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

Ralph Goers <[email protected]>
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <[email protected]>
Comments below.

> On Mar 29, 2022, at 3:01 PM, Pablo Rogina <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.