Need to override the Append method of the KafkaAppender

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Need to override the Append method of the KafkaAppender

Buks van der Lingen
Hi,
I have a need to wrap the message created by the PatternLayout assigned to my KafkaAppender and pass that to the KafkaManager.

The wrapper contains Spring-Boot environment/Build and other properties.

The KafkaManager is private in the appender and I can’t get around the implementation at append();
For now I duplicated the KafkaAppender and just added the functionality I need in append();

If anyone has a better idea pls advise?

Kind Regards,
Buks

Sent from Mail for Windows 10

Reply | Threaded
Open this post in threaded view
|

Re: Need to override the Append method of the KafkaAppender

Ralph Goers
If you need to wrap the message then you should create a pattern converter.

Ralph

> On Jan 8, 2020, at 5:23 AM, Buks van der Lingen <[hidden email]> wrote:
>
> Hi,
> I have a need to wrap the message created by the PatternLayout assigned to my KafkaAppender and pass that to the KafkaManager.
>
> The wrapper contains Spring-Boot environment/Build and other properties.
>
> The KafkaManager is private in the appender and I can’t get around the implementation at append();
> For now I duplicated the KafkaAppender and just added the functionality I need in append();
>
> If anyone has a better idea pls advise?
>
> Kind Regards,
> Buks
>
> Sent from Mail for Windows 10
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Need to override the Append method of the KafkaAppender

Buks van der Lingen
Hi Ralph,
I cant understand where the hook for the PatternConverter would be.

My override is:
private void tryAppend(final LogEvent event) throws ExecutionException, InterruptedException, TimeoutException {
       
        final Layout<? extends Serializable> layout = getLayout();
        String logMessage = (String)layout.toSerializable(event);        
        BuildProperties buildProperties =
            (BuildProperties) AppContext.getApplicationContext().getBean(BuildProperties.class);    
        LogViewerDao logViewerDao = new LogViewerDao(buildProperties, event, logMessage);        
        manager.send(logViewerDao.toJson().getBytes());
    }

The 2.10 version has:
private void tryAppend(final LogEvent event) throws ExecutionException, InterruptedException, TimeoutException {
        final Layout<? extends Serializable> layout = getLayout();
        byte[] data;
        if (layout instanceof SerializedLayout) {
            final byte[] header = layout.getHeader();
            final byte[] body = layout.toByteArray(event);
            data = new byte[header.length + body.length];
            System.arraycopy(header, 0, data, 0, header.length);
            System.arraycopy(body, 0, data, header.length, body.length);
        } else {
            data = layout.toByteArray(event);
        }
        manager.send(data);
    }

Even here the layout is resolved and directly after that sent to the KafkaManager.
In my version I need some action between where the layout data is embedded as an attribute in another object;

Kind Regards,
Buks

-----Original Message-----
From: Ralph Goers <[hidden email]>
Sent: Wednesday, 08 January 2020 17:23
To: Log4J Users List <[hidden email]>
Subject: Re: Need to override the Append method of the KafkaAppender

If you need to wrap the message then you should create a pattern converter.

Ralph

> On Jan 8, 2020, at 5:23 AM, Buks van der Lingen <[hidden email]> wrote:
>
> Hi,
> I have a need to wrap the message created by the PatternLayout assigned to my KafkaAppender and pass that to the KafkaManager.
>
> The wrapper contains Spring-Boot environment/Build and other properties.
>
> The KafkaManager is private in the appender and I can’t get around the
> implementation at append(); For now I duplicated the KafkaAppender and
> just added the functionality I need in append();
>
> If anyone has a better idea pls advise?
>
> Kind Regards,
> Buks
>
> Sent from Mail for Windows 10
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Need to override the Append method of the KafkaAppender

Carter Kozak-2
Can you write a custom layout which wraps another layout and implements that code on the result? Encapsulation should be easier to support than extension.

-ck

> On Jan 9, 2020, at 8:31 AM, [hidden email] wrote:
>
> Hi Ralph,
> I cant understand where the hook for the PatternConverter would be.
>
> My override is:
> private void tryAppend(final LogEvent event) throws ExecutionException, InterruptedException, TimeoutException {
>
>        final Layout<? extends Serializable> layout = getLayout();
>        String logMessage = (String)layout.toSerializable(event);        
>        BuildProperties buildProperties =
>            (BuildProperties) AppContext.getApplicationContext().getBean(BuildProperties.class);    
>        LogViewerDao logViewerDao = new LogViewerDao(buildProperties, event, logMessage);        
>        manager.send(logViewerDao.toJson().getBytes());
>    }
>
> The 2.10 version has:
> private void tryAppend(final LogEvent event) throws ExecutionException, InterruptedException, TimeoutException {
>        final Layout<? extends Serializable> layout = getLayout();
>        byte[] data;
>        if (layout instanceof SerializedLayout) {
>            final byte[] header = layout.getHeader();
>            final byte[] body = layout.toByteArray(event);
>            data = new byte[header.length + body.length];
>            System.arraycopy(header, 0, data, 0, header.length);
>            System.arraycopy(body, 0, data, header.length, body.length);
>        } else {
>            data = layout.toByteArray(event);
>        }
>        manager.send(data);
>    }
>
> Even here the layout is resolved and directly after that sent to the KafkaManager.
> In my version I need some action between where the layout data is embedded as an attribute in another object;
>
> Kind Regards,
> Buks
>
> -----Original Message-----
> From: Ralph Goers <[hidden email]>
> Sent: Wednesday, 08 January 2020 17:23
> To: Log4J Users List <[hidden email]>
> Subject: Re: Need to override the Append method of the KafkaAppender
>
> If you need to wrap the message then you should create a pattern converter.
>
> Ralph
>
>> On Jan 8, 2020, at 5:23 AM, Buks van der Lingen <[hidden email]> wrote:
>>
>> Hi,
>> I have a need to wrap the message created by the PatternLayout assigned to my KafkaAppender and pass that to the KafkaManager.
>>
>> The wrapper contains Spring-Boot environment/Build and other properties.
>>
>> The KafkaManager is private in the appender and I can’t get around the
>> implementation at append(); For now I duplicated the KafkaAppender and
>> just added the functionality I need in append();
>>
>> If anyone has a better idea pls advise?
>>
>> Kind Regards,
>> Buks
>>
>> Sent from Mail for Windows 10
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Need to override the Append method of the KafkaAppender

Ralph Goers
In reply to this post by Buks van der Lingen


> On Jan 9, 2020, at 6:31 AM, [hidden email] wrote:
>
> Hi Ralph,
> I cant understand where the hook for the PatternConverter would be.

What do you mean by “hook”?  PatternConverters are plugins. If you are using the PatternLayout and need to wrap the message then the pattern would look like “%wrapper{%msg}” where wrapper is the key you assigned your PatternConverter. The RegexReplacementConverter works in a similar fashion.

You could wrap the whole pattern this way if you want - “%wrapper{[%-5level] %c{1.} %msg%n}”.  The pattern converter doesn’t actually have to do any conversion. It can call your DAO and then return the string it was operating on.

Ralph


>
> My override is:
> private void tryAppend(final LogEvent event) throws ExecutionException, InterruptedException, TimeoutException {
>
>        final Layout<? extends Serializable> layout = getLayout();
>        String logMessage = (String)layout.toSerializable(event);        
>        BuildProperties buildProperties =
>            (BuildProperties) AppContext.getApplicationContext().getBean(BuildProperties.class);    
>        LogViewerDao logViewerDao = new LogViewerDao(buildProperties, event, logMessage);        
>        manager.send(logViewerDao.toJson().getBytes());
>    }
>
> The 2.10 version has:
> private void tryAppend(final LogEvent event) throws ExecutionException, InterruptedException, TimeoutException {
>        final Layout<? extends Serializable> layout = getLayout();
>        byte[] data;
>        if (layout instanceof SerializedLayout) {
>            final byte[] header = layout.getHeader();
>            final byte[] body = layout.toByteArray(event);
>            data = new byte[header.length + body.length];
>            System.arraycopy(header, 0, data, 0, header.length);
>            System.arraycopy(body, 0, data, header.length, body.length);
>        } else {
>            data = layout.toByteArray(event);
>        }
>        manager.send(data);
>    }
>
> Even here the layout is resolved and directly after that sent to the KafkaManager.
> In my version I need some action between where the layout data is embedded as an attribute in another object;
>
> Kind Regards,
> Buks
>
> -----Original Message-----
> From: Ralph Goers <[hidden email]>
> Sent: Wednesday, 08 January 2020 17:23
> To: Log4J Users List <[hidden email]>
> Subject: Re: Need to override the Append method of the KafkaAppender
>
> If you need to wrap the message then you should create a pattern converter.
>
> Ralph
>
>> On Jan 8, 2020, at 5:23 AM, Buks van der Lingen <[hidden email]> wrote:
>>
>> Hi,
>> I have a need to wrap the message created by the PatternLayout assigned to my KafkaAppender and pass that to the KafkaManager.
>>
>> The wrapper contains Spring-Boot environment/Build and other properties.
>>
>> The KafkaManager is private in the appender and I can’t get around the
>> implementation at append(); For now I duplicated the KafkaAppender and
>> just added the functionality I need in append();
>>
>> If anyone has a better idea pls advise?
>>
>> Kind Regards,
>> Buks
>>
>> Sent from Mail for Windows 10
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Need to override the Append method of the KafkaAppender

Buks van der Lingen
Aaaah... now i get it thanks.

Kind Regards,
Buks

On Thu, 09 Jan 2020, 17:08 Ralph Goers, <[hidden email]> wrote:

>
>
> > On Jan 9, 2020, at 6:31 AM, [hidden email] wrote:
> >
> > Hi Ralph,
> > I cant understand where the hook for the PatternConverter would be.
>
> What do you mean by “hook”?  PatternConverters are plugins. If you are
> using the PatternLayout and need to wrap the message then the pattern would
> look like “%wrapper{%msg}” where wrapper is the key you assigned your
> PatternConverter. The RegexReplacementConverter works in a similar fashion.
>
> You could wrap the whole pattern this way if you want -
> “%wrapper{[%-5level] %c{1.} %msg%n}”.  The pattern converter doesn’t
> actually have to do any conversion. It can call your DAO and then return
> the string it was operating on.
>
> Ralph
>
>
> >
> > My override is:
> > private void tryAppend(final LogEvent event) throws ExecutionException,
> InterruptedException, TimeoutException {
> >
> >        final Layout<? extends Serializable> layout = getLayout();
> >        String logMessage = (String)layout.toSerializable(event);
> >        BuildProperties buildProperties =
> >            (BuildProperties)
> AppContext.getApplicationContext().getBean(BuildProperties.class);
> >        LogViewerDao logViewerDao = new LogViewerDao(buildProperties,
> event, logMessage);
> >        manager.send(logViewerDao.toJson().getBytes());
> >    }
> >
> > The 2.10 version has:
> > private void tryAppend(final LogEvent event) throws ExecutionException,
> InterruptedException, TimeoutException {
> >        final Layout<? extends Serializable> layout = getLayout();
> >        byte[] data;
> >        if (layout instanceof SerializedLayout) {
> >            final byte[] header = layout.getHeader();
> >            final byte[] body = layout.toByteArray(event);
> >            data = new byte[header.length + body.length];
> >            System.arraycopy(header, 0, data, 0, header.length);
> >            System.arraycopy(body, 0, data, header.length, body.length);
> >        } else {
> >            data = layout.toByteArray(event);
> >        }
> >        manager.send(data);
> >    }
> >
> > Even here the layout is resolved and directly after that sent to the
> KafkaManager.
> > In my version I need some action between where the layout data is
> embedded as an attribute in another object;
> >
> > Kind Regards,
> > Buks
> >
> > -----Original Message-----
> > From: Ralph Goers <[hidden email]>
> > Sent: Wednesday, 08 January 2020 17:23
> > To: Log4J Users List <[hidden email]>
> > Subject: Re: Need to override the Append method of the KafkaAppender
> >
> > If you need to wrap the message then you should create a pattern
> converter.
> >
> > Ralph
> >
> >> On Jan 8, 2020, at 5:23 AM, Buks van der Lingen <[hidden email]>
> wrote:
> >>
> >> Hi,
> >> I have a need to wrap the message created by the PatternLayout assigned
> to my KafkaAppender and pass that to the KafkaManager.
> >>
> >> The wrapper contains Spring-Boot environment/Build and other properties.
> >>
> >> The KafkaManager is private in the appender and I can’t get around the
> >> implementation at append(); For now I duplicated the KafkaAppender and
> >> just added the functionality I need in append();
> >>
> >> If anyone has a better idea pls advise?
> >>
> >> Kind Regards,
> >> Buks
> >>
> >> Sent from Mail for Windows 10
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>