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 EDMONDO SENA <ed...@gmail.com> on 2020/02/27 09:25:10 UTC

PatternLayout Log4j2

Hi Everybody,

In log4j1.x I was using the PatternLayout(String Pattern) namely:

- setLayout(new PatternLayout("%d %-lp - %m").

Now I didn't understand the equivalent of making this regular expression in log4j2.
Can you help me understand better?

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


Re: PatternLayout Log4j2

Posted by Matt Sicker <bo...@gmail.com>.
One thing to keep in mind is that unless you’re willing to keep updating
code based on internal changes, you shouldn’t be creating plugin objects
directly from their builder classes or factory methods. The programmatic
config has a few examples in our unit tests.

On Thu, Feb 27, 2020 at 09:38 EDMONDO SENA <ed...@gmail.com> wrote:

> I saw it but not everything in that examples is clear to me...
>
>
>
> On 2020/02/27 15:33:56, Matt Sicker <bo...@gmail.com> wrote:
> > http://logging.apache.org/log4j/2.x/manual/customconfig.html
> >
> >
> > On Thu, Feb 27, 2020 at 09:32 EDMONDO SENA <ed...@gmail.com> wrote:
> >
> > >
> > > Is it possible to do it in java code without configuration file?
> > >
> > >
> > >
> > > On 2020/02/27 15:28:26, Ralph Goers <ra...@dslextreme.com>
> wrote:
> > > > Why are you using the PatternLayout with the SyslogAppender?  If you
> > > replace the Layout it will no longer be sending data in accordance
> with the
> > > Syslog spec.  Why are you doing this programmatically instead of using
> a
> > > configuration file?
> > > >
> > > > Ralph
> > > >
> > > > > On Feb 27, 2020, at 8:25 AM, EDMONDO SENA <ed...@gmail.com>
> wrote:
> > > > >
> > > > >
> > > > > I've used:
> > > > >
> > > > > Call ->
> > > > > final Builder<?> builder2 = newSyslogAppenderBuilder(protocol,
> format,
> > > newLine);
> > > > >
> > > > >
> > > > > protected static Builder<?> newSyslogAppenderBuilder(final String
> > > protocol,final String format,final boolean newLine)
> > > > >
> > > > > return Syslog4jAppenderLI.newSyslogAppenderBuilder()
> > > > >                     .withHost(xxxxx)
> > > > >                     .withPort(xxxxx).
> > > > >
> > > > > .....
> > > > >
> > > > > builder2.setLayout((Layout<? extends Serializable> )
> > > PatternLayout.newBuilder().withPattern("%d %-lp - %m").build());
> > > > >
> > > > > I don't know if it is will work.
> > > > >
> > > > >
> > > > >
> > > > > On 2020/02/27 15:18:24, Ralph Goers <ra...@dslextreme.com>
> > > wrote:
> > > > >> I am not sure what you mean by “regular expression” with regards
> to
> > > the PatternLayout as it doesn’t use regular expressions.  Have you
> tried
> > > the same pattern? My guess is it should do the same thing Log4j 1 did.
> > > > >>
> > > > >> Ralph
> > > > >>
> > > > >>> On Feb 27, 2020, at 2:25 AM, EDMONDO SENA <ed...@gmail.com>
> wrote:
> > > > >>>
> > > > >>>
> > > > >>> Hi Everybody,
> > > > >>>
> > > > >>> In log4j1.x I was using the PatternLayout(String Pattern) namely:
> > > > >>>
> > > > >>> - setLayout(new PatternLayout("%d %-lp - %m").
> > > > >>>
> > > > >>> Now I didn't understand the equivalent of making this regular
> > > expression in log4j2.
> > > > >>> Can you help me understand better?
> > > > >>>
> > > > >>>
> ---------------------------------------------------------------------
> > > > >>> 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
> > > > >>
> > > > >>
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > 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
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > > For additional commands, e-mail: log4j-user-help@logging.apache.org
> > >
> > > --
> > Matt Sicker <bo...@gmail.com>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
> --
Matt Sicker <bo...@gmail.com>

Re: PatternLayout Log4j2

Posted by EDMONDO SENA <ed...@gmail.com>.
I saw it but not everything in that examples is clear to me...



On 2020/02/27 15:33:56, Matt Sicker <bo...@gmail.com> wrote: 
> http://logging.apache.org/log4j/2.x/manual/customconfig.html
> 
> 
> On Thu, Feb 27, 2020 at 09:32 EDMONDO SENA <ed...@gmail.com> wrote:
> 
> >
> > Is it possible to do it in java code without configuration file?
> >
> >
> >
> > On 2020/02/27 15:28:26, Ralph Goers <ra...@dslextreme.com> wrote:
> > > Why are you using the PatternLayout with the SyslogAppender?  If you
> > replace the Layout it will no longer be sending data in accordance with the
> > Syslog spec.  Why are you doing this programmatically instead of using a
> > configuration file?
> > >
> > > Ralph
> > >
> > > > On Feb 27, 2020, at 8:25 AM, EDMONDO SENA <ed...@gmail.com> wrote:
> > > >
> > > >
> > > > I've used:
> > > >
> > > > Call ->
> > > > final Builder<?> builder2 = newSyslogAppenderBuilder(protocol, format,
> > newLine);
> > > >
> > > >
> > > > protected static Builder<?> newSyslogAppenderBuilder(final String
> > protocol,final String format,final boolean newLine)
> > > >
> > > > return Syslog4jAppenderLI.newSyslogAppenderBuilder()
> > > >                     .withHost(xxxxx)
> > > >                     .withPort(xxxxx).
> > > >
> > > > .....
> > > >
> > > > builder2.setLayout((Layout<? extends Serializable> )
> > PatternLayout.newBuilder().withPattern("%d %-lp - %m").build());
> > > >
> > > > I don't know if it is will work.
> > > >
> > > >
> > > >
> > > > On 2020/02/27 15:18:24, Ralph Goers <ra...@dslextreme.com>
> > wrote:
> > > >> I am not sure what you mean by “regular expression” with regards to
> > the PatternLayout as it doesn’t use regular expressions.  Have you tried
> > the same pattern? My guess is it should do the same thing Log4j 1 did.
> > > >>
> > > >> Ralph
> > > >>
> > > >>> On Feb 27, 2020, at 2:25 AM, EDMONDO SENA <ed...@gmail.com> wrote:
> > > >>>
> > > >>>
> > > >>> Hi Everybody,
> > > >>>
> > > >>> In log4j1.x I was using the PatternLayout(String Pattern) namely:
> > > >>>
> > > >>> - setLayout(new PatternLayout("%d %-lp - %m").
> > > >>>
> > > >>> Now I didn't understand the equivalent of making this regular
> > expression in log4j2.
> > > >>> Can you help me understand better?
> > > >>>
> > > >>> ---------------------------------------------------------------------
> > > >>> 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
> > > >>
> > > >>
> > > >
> > > > ---------------------------------------------------------------------
> > > > 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
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> > --
> Matt Sicker <bo...@gmail.com>
> 

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


Re: PatternLayout Log4j2

Posted by Matt Sicker <bo...@gmail.com>.
http://logging.apache.org/log4j/2.x/manual/customconfig.html


On Thu, Feb 27, 2020 at 09:32 EDMONDO SENA <ed...@gmail.com> wrote:

>
> Is it possible to do it in java code without configuration file?
>
>
>
> On 2020/02/27 15:28:26, Ralph Goers <ra...@dslextreme.com> wrote:
> > Why are you using the PatternLayout with the SyslogAppender?  If you
> replace the Layout it will no longer be sending data in accordance with the
> Syslog spec.  Why are you doing this programmatically instead of using a
> configuration file?
> >
> > Ralph
> >
> > > On Feb 27, 2020, at 8:25 AM, EDMONDO SENA <ed...@gmail.com> wrote:
> > >
> > >
> > > I've used:
> > >
> > > Call ->
> > > final Builder<?> builder2 = newSyslogAppenderBuilder(protocol, format,
> newLine);
> > >
> > >
> > > protected static Builder<?> newSyslogAppenderBuilder(final String
> protocol,final String format,final boolean newLine)
> > >
> > > return Syslog4jAppenderLI.newSyslogAppenderBuilder()
> > >                     .withHost(xxxxx)
> > >                     .withPort(xxxxx).
> > >
> > > .....
> > >
> > > builder2.setLayout((Layout<? extends Serializable> )
> PatternLayout.newBuilder().withPattern("%d %-lp - %m").build());
> > >
> > > I don't know if it is will work.
> > >
> > >
> > >
> > > On 2020/02/27 15:18:24, Ralph Goers <ra...@dslextreme.com>
> wrote:
> > >> I am not sure what you mean by “regular expression” with regards to
> the PatternLayout as it doesn’t use regular expressions.  Have you tried
> the same pattern? My guess is it should do the same thing Log4j 1 did.
> > >>
> > >> Ralph
> > >>
> > >>> On Feb 27, 2020, at 2:25 AM, EDMONDO SENA <ed...@gmail.com> wrote:
> > >>>
> > >>>
> > >>> Hi Everybody,
> > >>>
> > >>> In log4j1.x I was using the PatternLayout(String Pattern) namely:
> > >>>
> > >>> - setLayout(new PatternLayout("%d %-lp - %m").
> > >>>
> > >>> Now I didn't understand the equivalent of making this regular
> expression in log4j2.
> > >>> Can you help me understand better?
> > >>>
> > >>> ---------------------------------------------------------------------
> > >>> 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
> > >>
> > >>
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
> --
Matt Sicker <bo...@gmail.com>

Re: PatternLayout Log4j2

Posted by EDMONDO SENA <ed...@gmail.com>.
Is it possible to do it in java code without configuration file?



On 2020/02/27 15:28:26, Ralph Goers <ra...@dslextreme.com> wrote: 
> Why are you using the PatternLayout with the SyslogAppender?  If you replace the Layout it will no longer be sending data in accordance with the Syslog spec.  Why are you doing this programmatically instead of using a configuration file? 
> 
> Ralph
> 
> > On Feb 27, 2020, at 8:25 AM, EDMONDO SENA <ed...@gmail.com> wrote:
> > 
> > 
> > I've used:
> > 
> > Call ->
> > final Builder<?> builder2 = newSyslogAppenderBuilder(protocol, format, newLine);
> > 
> > 
> > protected static Builder<?> newSyslogAppenderBuilder(final String protocol,final String format,final boolean newLine)
> > 
> > return Syslog4jAppenderLI.newSyslogAppenderBuilder()
> > 	    		.withHost(xxxxx)
> > 	    		.withPort(xxxxx).
> > 
> > .....
> > 
> > builder2.setLayout((Layout<? extends Serializable> ) PatternLayout.newBuilder().withPattern("%d %-lp - %m").build());
> > 
> > I don't know if it is will work. 
> > 
> > 
> > 
> > On 2020/02/27 15:18:24, Ralph Goers <ra...@dslextreme.com> wrote: 
> >> I am not sure what you mean by “regular expression” with regards to the PatternLayout as it doesn’t use regular expressions.  Have you tried the same pattern? My guess is it should do the same thing Log4j 1 did.
> >> 
> >> Ralph
> >> 
> >>> On Feb 27, 2020, at 2:25 AM, EDMONDO SENA <ed...@gmail.com> wrote:
> >>> 
> >>> 
> >>> Hi Everybody,
> >>> 
> >>> In log4j1.x I was using the PatternLayout(String Pattern) namely:
> >>> 
> >>> - setLayout(new PatternLayout("%d %-lp - %m").
> >>> 
> >>> Now I didn't understand the equivalent of making this regular expression in log4j2.
> >>> Can you help me understand better?
> >>> 
> >>> ---------------------------------------------------------------------
> >>> 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
> >> 
> >> 
> > 
> > ---------------------------------------------------------------------
> > 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
> 
> 

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


Re: PatternLayout Log4j2

Posted by Ralph Goers <ra...@dslextreme.com>.
Why are you using the PatternLayout with the SyslogAppender?  If you replace the Layout it will no longer be sending data in accordance with the Syslog spec.  Why are you doing this programmatically instead of using a configuration file? 

Ralph

> On Feb 27, 2020, at 8:25 AM, EDMONDO SENA <ed...@gmail.com> wrote:
> 
> 
> I've used:
> 
> Call ->
> final Builder<?> builder2 = newSyslogAppenderBuilder(protocol, format, newLine);
> 
> 
> protected static Builder<?> newSyslogAppenderBuilder(final String protocol,final String format,final boolean newLine)
> 
> return Syslog4jAppenderLI.newSyslogAppenderBuilder()
> 	    		.withHost(xxxxx)
> 	    		.withPort(xxxxx).
> 
> .....
> 
> builder2.setLayout((Layout<? extends Serializable> ) PatternLayout.newBuilder().withPattern("%d %-lp - %m").build());
> 
> I don't know if it is will work. 
> 
> 
> 
> On 2020/02/27 15:18:24, Ralph Goers <ra...@dslextreme.com> wrote: 
>> I am not sure what you mean by “regular expression” with regards to the PatternLayout as it doesn’t use regular expressions.  Have you tried the same pattern? My guess is it should do the same thing Log4j 1 did.
>> 
>> Ralph
>> 
>>> On Feb 27, 2020, at 2:25 AM, EDMONDO SENA <ed...@gmail.com> wrote:
>>> 
>>> 
>>> Hi Everybody,
>>> 
>>> In log4j1.x I was using the PatternLayout(String Pattern) namely:
>>> 
>>> - setLayout(new PatternLayout("%d %-lp - %m").
>>> 
>>> Now I didn't understand the equivalent of making this regular expression in log4j2.
>>> Can you help me understand better?
>>> 
>>> ---------------------------------------------------------------------
>>> 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
>> 
>> 
> 
> ---------------------------------------------------------------------
> 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: PatternLayout Log4j2

Posted by EDMONDO SENA <ed...@gmail.com>.
I've used:

Call ->
final Builder<?> builder2 = newSyslogAppenderBuilder(protocol, format, newLine);


protected static Builder<?> newSyslogAppenderBuilder(final String protocol,final String format,final boolean newLine)

return Syslog4jAppenderLI.newSyslogAppenderBuilder()
	    		.withHost(xxxxx)
	    		.withPort(xxxxx).

.....

builder2.setLayout((Layout<? extends Serializable> ) PatternLayout.newBuilder().withPattern("%d %-lp - %m").build());

I don't know if it is will work. 



On 2020/02/27 15:18:24, Ralph Goers <ra...@dslextreme.com> wrote: 
> I am not sure what you mean by “regular expression” with regards to the PatternLayout as it doesn’t use regular expressions.  Have you tried the same pattern? My guess is it should do the same thing Log4j 1 did.
> 
> Ralph
> 
> > On Feb 27, 2020, at 2:25 AM, EDMONDO SENA <ed...@gmail.com> wrote:
> > 
> > 
> > Hi Everybody,
> > 
> > In log4j1.x I was using the PatternLayout(String Pattern) namely:
> > 
> > - setLayout(new PatternLayout("%d %-lp - %m").
> > 
> > Now I didn't understand the equivalent of making this regular expression in log4j2.
> > Can you help me understand better?
> > 
> > ---------------------------------------------------------------------
> > 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
> 
> 

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


Re: PatternLayout Log4j2

Posted by Ralph Goers <ra...@dslextreme.com>.
I am not sure what you mean by “regular expression” with regards to the PatternLayout as it doesn’t use regular expressions.  Have you tried the same pattern? My guess is it should do the same thing Log4j 1 did.

Ralph

> On Feb 27, 2020, at 2:25 AM, EDMONDO SENA <ed...@gmail.com> wrote:
> 
> 
> Hi Everybody,
> 
> In log4j1.x I was using the PatternLayout(String Pattern) namely:
> 
> - setLayout(new PatternLayout("%d %-lp - %m").
> 
> Now I didn't understand the equivalent of making this regular expression in log4j2.
> Can you help me understand better?
> 
> ---------------------------------------------------------------------
> 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