Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Gary Gregory
Apostolis,

You are warmly welcome to contribute to Log4j. You can create a JIRA and
attach a patch in unified diff file format. Unit tests as part of the patch
are a must IMO. Feel free to flush out any design or implementation here on
the dev ML.

Thank you!
Gary

On Tue, Jan 26, 2016 at 5:02 PM, Ralph Goers 
wrote:

> All the attributes have to have String representations to be usable in the
> XML, JSON & Properties configurations. Yes, the Map could contain Objects
> but then every one of them has to be cast to its real object to be usable.
>
> The map should be read-only because modifying its contents would have no
> effect on the appender.
>
> The map should not be stored in an ivar but constructed whenever the
> attributes are retrieved. Otherwise it will be temping to just keep them in
> a map and not as individual attributes, which would cause problems.
>
> If you have nesting such as  MyAppender extends MyBaseAppender extends
> AbstractOutputStreamAppender extends AbstractAppender, I envision a
> fillAttributes method at each “level” that fills in the attributes it knows
> about, so fillAttributeMap(map) should always call
> super.fillAttributeMap(map) - except in AbstractAppender of course - and
> should call it before filling in its own attributes so that it can override
> any values provided by the base Appenders.  If the primary Appender does
> not implement fillAttributeMap then only the attributes of its super
> classes will be included, which is actually correct for the SyslogAppender.
>
> Ralph
>
> > On Jan 26, 2016, at 5:24 PM, Apostolis Giannakidis <
> ap.giannaki...@gmail.com> wrote:
> >
> > One thing to note here. Correct me if I am wrong, but the map should
> > be Map > Object> because not all attributes are Strings. From the top of my head,
> I
> > know that an attribute could also be a boolean.
> >
> > On Wed, Jan 27, 2016 at 12:06 AM, Gary Gregory 
> > wrote:
> >
> >> I could see AbstractAppender implementing a getAttributes() method like
> >> this:
> >>
> >>public Map getAttributes() {
> >>Map map = new HashMap<>();
> >>fillAttributeMap(map);
> >>// (1) should the map be read-only? why?
> >>// (2) if the map is cached in an ivar, the it must be updated by
> >> each appender when an attribute changes, so
> >>// I'd say no and follow the KISS principle for now.
> >>return map;
> >>}
> >>
> >>protected void fillAttributeMap(Map map) {
> >>// ...
> >>}
> >>
> >> The boilerplate of creating and/or managing the map can be in
> >> getAttributes().
> >> Actually filling in the map in is done in fillAttributeMap() which each
> >> appender can override.
> >>
> >> fillAttributeMap() could be abstract to force each appender to make sure
> >> developers pay attention to providing an implementation.
> >>
> >> Gary
> >>
> >>
> >> On Tue, Jan 26, 2016 at 3:46 PM, Apostolis Giannakidis <
> >> ap.giannaki...@gmail.com> wrote:
> >>
> >>> Well, since the idea is to add it to the Appender interface, it means
> >> that
> >>> all concrete Appenders need to be modified as well. So, yes, I can give
> >> it
> >>> a try to implement it for all the Appenders. One other simple way would
> >> be
> >>> to implement it once in the AbstractAppender so that all its subclasses
> >>> will inherit it.
> >>>
> >>> On Tue, Jan 26, 2016 at 9:15 PM, Gary Gregory 
> >>> wrote:
> >>>
>  On Tue, Jan 26, 2016 at 1:06 PM, Apostolis Giannakidis <
>  ap.giannaki...@gmail.com> wrote:
> 
> > Actually, since this seems to be a useful feature, I would love to do
> >>> the
> > patch myself and contribute it to the project, if you don't mind.
> >
> 
>  Do you plan on implementing this for all Appenders?
> 
>  Gary
> 
> >
> > On Tue, Jan 26, 2016 at 8:56 PM, Ralph Goers <
> >>> ralph.go...@dslextreme.com
> >
> > wrote:
> >
> >> Actually, I kind of like the idea of adding a getAttributes()
> >> method
> >>> to
> >> the Appender interface. Then each concrete Appender would do:
> >>
> >> public void getAttributes() {
> >>Map attributes = new HashMap<>();
> >>super.getAttributes(attributes):
> >>attributes.put(“myAttribute1”, “value1”);
> >>return Collections.unmodifiableMap(attributes);
> >> }
> >>
> >>
> >>
> >>> On Jan 26, 2016, at 1:28 PM, Gary Gregory <
> >> garydgreg...@gmail.com>
> >> wrote:
> >>>
> >>> How about adding getters for the fields
> >>> in org.apache.logging.log4j.core.net.AbstractSocketManager?
> >>>
> >>> Gary
> >>>
> >>> On Tue, Jan 26, 2016 at 12:20 PM, Matt Sicker 
> > wrote:
> >>>
>  You could always use reflection to access it for now.
> 
>  On 26 January 2016 at 14:17, Apostolis 

Using log4j SimpleSocketServer with log4j2

2016-01-26 Thread Nipuni Piyabasi Perera
Hi all,

I am trying to save logs sent to a server(log4j SimpleSocketserver) via
SocketAppender. I have tried this with log4j and log4j2 as follows.

*Working scenario: *
Log4j.properties configuration:

# MY_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout.

log4j.appender.MY_LOGFILE=org.apache.log4j.net.SocketAppender

log4j.appender.MY_LOGFILE.Port=4712

log4j.appender.MY_LOGFILE.RemoteHost=localhost

log4j.appender.MY_LOGFILE.ReconnectionDelay=1


*Error scenario:*

Log4j2.xml configuration:





   



  


























I am starting the log4j SimpleSocketserver with port 4712 (java -classpath
 apache-log4j.jar  org.apache.log4j.net.SimpleSocketServer 4712
configfile/test.properties) with properties below:

log4j.rootLogger=DEBUG, file


#Define how the socket server should store the log events

log4j.appender.file=org.apache.log4j.RollingFileAppender

log4j.appender.file.File=application-error.log

log4j.appender.file.MaxFileSize=1MB

log4j.appender.file.MaxBackupIndex=1

log4j.appender.file.layout=org.apache.log4j.PatternLayout

log4j.appender.file.layout.ConversionPattern=[%d] [%t] [%m]%n


I could see logs from my custom package with the first (I.e., log4j older)
configuratuon and I am receiving an error[1] from at SimpleSocketServer
side with the log4j2 configuration.  I assume that the SimpleSocketServer
may not compatible with log4j2. If that is the issue is there a log4j
server compatible with log4j2 SocketAppender?. Or am I missing something
here with the log4j2 configuration?

[1]   [2016-01-27 09:49:57,299] [main] [Connected to client at /127.0.0.1]
   [2016-01-27 09:49:57,299] [main] [Starting new socket node.]
   [2016-01-27 09:49:57,300] [main] [Waiting to accept a new client.]
   [2016-01-27 09:49:57,479] [Thread-1] [Unexpected exception. Closing
conneciton.]
   java.lang.ClassNotFoundException:
org.apache.logging.log4j.core.impl.Log4jLogEvent$LogEventProxy
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:626)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
at org.apache.log4j.net.SocketNode.run(SocketNode.java:67)
at java.lang.Thread.run(Thread.java:745)

Thanks,
Nipuni

-- 
Nipuni Perera
Software Engineer; WSO2 Inc.; http://wso2.com
Email: nip...@wso2.com
Git hub profile: https://github.com/nipuni
Blog : http://nipunipererablog.blogspot.com/
Mobile: +94 (71) 5626680


Re: Using log4j SimpleSocketServer with log4j2

2016-01-26 Thread Gary Gregory
Nipuni,

For Log4j 2, please see:

org.apache.logging.log4j.core.net.server.TcpSocketServer
org.apache.logging.log4j.core.net.server.UdpSocketServer

Gary

On Tue, Jan 26, 2016 at 9:25 PM, Nipuni Piyabasi Perera <
nipuni880...@gmail.com> wrote:

> Hi all,
>
> I am trying to save logs sent to a server(log4j SimpleSocketserver) via
> SocketAppender. I have tried this with log4j and log4j2 as follows.
>
> *Working scenario: *
> Log4j.properties configuration:
>
> # MY_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout.
>
> log4j.appender.MY_LOGFILE=org.apache.log4j.net.SocketAppender
>
> log4j.appender.MY_LOGFILE.Port=4712
>
> log4j.appender.MY_LOGFILE.RemoteHost=localhost
>
> log4j.appender.MY_LOGFILE.ReconnectionDelay=1
>
>
> *Error scenario:*
>
> Log4j2.xml configuration:
>
> 
>
> 
>
>
>
> 
>
>   
>
> 
>
> 
>
> 
>
> 
>
> 
>
> 
>
> 
>
>  additivity="false">
>
> 
>
> 
>
> 
>
> 
>
>
> I am starting the log4j SimpleSocketserver with port 4712 (java -classpath
>  apache-log4j.jar  org.apache.log4j.net.SimpleSocketServer 4712
> configfile/test.properties) with properties below:
>
> log4j.rootLogger=DEBUG, file
>
>
> #Define how the socket server should store the log events
>
> log4j.appender.file=org.apache.log4j.RollingFileAppender
>
> log4j.appender.file.File=application-error.log
>
> log4j.appender.file.MaxFileSize=1MB
>
> log4j.appender.file.MaxBackupIndex=1
>
> log4j.appender.file.layout=org.apache.log4j.PatternLayout
>
> log4j.appender.file.layout.ConversionPattern=[%d] [%t] [%m]%n
>
>
> I could see logs from my custom package with the first (I.e., log4j older)
> configuratuon and I am receiving an error[1] from at SimpleSocketServer
> side with the log4j2 configuration.  I assume that the SimpleSocketServer
> may not compatible with log4j2. If that is the issue is there a log4j
> server compatible with log4j2 SocketAppender?. Or am I missing something
> here with the log4j2 configuration?
>
> [1]   [2016-01-27 09:49:57,299] [main] [Connected to client at /127.0.0.1]
>[2016-01-27 09:49:57,299] [main] [Starting new socket node.]
>[2016-01-27 09:49:57,300] [main] [Waiting to accept a new client.]
>[2016-01-27 09:49:57,479] [Thread-1] [Unexpected exception. Closing
> conneciton.]
>java.lang.ClassNotFoundException:
> org.apache.logging.log4j.core.impl.Log4jLogEvent$LogEventProxy
> at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:348)
> at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:626)
> at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)
> at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
> at org.apache.log4j.net.SocketNode.run(SocketNode.java:67)
> at java.lang.Thread.run(Thread.java:745)
>
> Thanks,
> Nipuni
>
> --
> Nipuni Perera
> Software Engineer; WSO2 Inc.; http://wso2.com
> Email: nip...@wso2.com
> Git hub profile: https://github.com/nipuni
> Blog : http://nipunipererablog.blogspot.com/
> Mobile: +94 (71) 5626680
>



-- 
E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
Java Persistence with Hibernate, Second Edition

JUnit in Action, Second Edition 
Spring Batch in Action 
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory


Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Ralph Goers
Not exactly. You can do:

Appender appender = ctx.getConfiguration().getAppender(“syslogAppender”);

then you would have to do 

SyslogAppender syslogAppender = (SyslogAppender) appender;

normally you would probably use instanceof to verify it is actually a 
SyslogAppender.

Once you have that you can call whatever methods the SyslogAppender exposes for 
getting its attributes. They are not stored in a Map however, so you can’t just 
call a generic getAttribute method.

Ralph


> On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis 
>  wrote:
> 
> Hello team,
> 
> I have created a logger with an appender using the ConfigurationBuilder and
> the AppenderComponentBuilder.
> 
> Let's say that this is how I create my appender:
> 
> AppenderComponentBuilder appenderBuilder =
>builder.newAppender( "syslogAppender", "Syslog" )
>.addAttribute( "protocol", "TCP" )
>.addAttribute( "host", "localhost" )
>.addAttribute( "port", 514 )
>.addAttribute( "facility", "LOCAL2" )
>.addAttribute( "immediateFlush", true )
>.addAttribute( "newLine", true );
> 
> Then, after I finish creating the builder I use the
> Configurator.initialize( builder.build() ) to get the LoggerContext.
> 
> Is there any way I can access the attributes of the appender through the
> LoggerContext?
> 
> For example something like this:
> 
> LoggerContext ctx = Configurator.initialize( builder.build() );
> 
> String hostname =
> ctx.getConfiguration()..getAppenders().get("syslogAppender").getAttribute("host");
> 
> Thank you all very much for your help.
> 
> Apostolis



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



Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Apostolis Giannakidis
Thank you very much for the prompt reply Ralph.

As far as I can see, the SyslogAppender class does not expose a way to
access these attributes. So, if there is no other way of accessing these
attributes, then I am not able to retrieve the attributes that I want from
the existing SyslogAppender implementation. If I understand correctly,
correct me if I am wrong, I might have to create my own that exposes these
attributes.

Apos

On Tue, Jan 26, 2016 at 8:03 PM, Ralph Goers 
wrote:

> Not exactly. You can do:
>
> Appender appender = ctx.getConfiguration().getAppender(“syslogAppender”);
>
> then you would have to do
>
> SyslogAppender syslogAppender = (SyslogAppender) appender;
>
> normally you would probably use instanceof to verify it is actually a
> SyslogAppender.
>
> Once you have that you can call whatever methods the SyslogAppender
> exposes for getting its attributes. They are not stored in a Map however,
> so you can’t just call a generic getAttribute method.
>
> Ralph
>
>
> > On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis <
> ap.giannaki...@gmail.com> wrote:
> >
> > Hello team,
> >
> > I have created a logger with an appender using the ConfigurationBuilder
> and
> > the AppenderComponentBuilder.
> >
> > Let's say that this is how I create my appender:
> >
> > AppenderComponentBuilder appenderBuilder =
> >builder.newAppender( "syslogAppender", "Syslog" )
> >.addAttribute( "protocol", "TCP" )
> >.addAttribute( "host", "localhost" )
> >.addAttribute( "port", 514 )
> >.addAttribute( "facility", "LOCAL2" )
> >.addAttribute( "immediateFlush", true )
> >.addAttribute( "newLine", true );
> >
> > Then, after I finish creating the builder I use the
> > Configurator.initialize( builder.build() ) to get the LoggerContext.
> >
> > Is there any way I can access the attributes of the appender through the
> > LoggerContext?
> >
> > For example something like this:
> >
> > LoggerContext ctx = Configurator.initialize( builder.build() );
> >
> > String hostname =
> >
> ctx.getConfiguration()..getAppenders().get("syslogAppender").getAttribute("host");
> >
> > Thank you all very much for your help.
> >
> > Apostolis
>
>
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Matt Sicker
You could always use reflection to access it for now.

On 26 January 2016 at 14:17, Apostolis Giannakidis  wrote:

> Thank you very much for the prompt reply Ralph.
>
> As far as I can see, the SyslogAppender class does not expose a way to
> access these attributes. So, if there is no other way of accessing these
> attributes, then I am not able to retrieve the attributes that I want from
> the existing SyslogAppender implementation. If I understand correctly,
> correct me if I am wrong, I might have to create my own that exposes these
> attributes.
>
> Apos
>
> On Tue, Jan 26, 2016 at 8:03 PM, Ralph Goers 
> wrote:
>
> > Not exactly. You can do:
> >
> > Appender appender = ctx.getConfiguration().getAppender(“syslogAppender”);
> >
> > then you would have to do
> >
> > SyslogAppender syslogAppender = (SyslogAppender) appender;
> >
> > normally you would probably use instanceof to verify it is actually a
> > SyslogAppender.
> >
> > Once you have that you can call whatever methods the SyslogAppender
> > exposes for getting its attributes. They are not stored in a Map however,
> > so you can’t just call a generic getAttribute method.
> >
> > Ralph
> >
> >
> > > On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis <
> > ap.giannaki...@gmail.com> wrote:
> > >
> > > Hello team,
> > >
> > > I have created a logger with an appender using the ConfigurationBuilder
> > and
> > > the AppenderComponentBuilder.
> > >
> > > Let's say that this is how I create my appender:
> > >
> > > AppenderComponentBuilder appenderBuilder =
> > >builder.newAppender( "syslogAppender", "Syslog" )
> > >.addAttribute( "protocol", "TCP" )
> > >.addAttribute( "host", "localhost" )
> > >.addAttribute( "port", 514 )
> > >.addAttribute( "facility", "LOCAL2" )
> > >.addAttribute( "immediateFlush", true )
> > >.addAttribute( "newLine", true );
> > >
> > > Then, after I finish creating the builder I use the
> > > Configurator.initialize( builder.build() ) to get the LoggerContext.
> > >
> > > Is there any way I can access the attributes of the appender through
> the
> > > LoggerContext?
> > >
> > > For example something like this:
> > >
> > > LoggerContext ctx = Configurator.initialize( builder.build() );
> > >
> > > String hostname =
> > >
> >
> ctx.getConfiguration()..getAppenders().get("syslogAppender").getAttribute("host");
> > >
> > > Thank you all very much for your help.
> > >
> > > Apostolis
> >
> >
> >
> > -
> > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> > For additional commands, e-mail: log4j-user-h...@logging.apache.org
> >
> >
>



-- 
Matt Sicker 


Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Gary Gregory
How about adding getters for the fields
in org.apache.logging.log4j.core.net.AbstractSocketManager?

Gary

On Tue, Jan 26, 2016 at 12:20 PM, Matt Sicker  wrote:

> You could always use reflection to access it for now.
>
> On 26 January 2016 at 14:17, Apostolis Giannakidis <
> ap.giannaki...@gmail.com
> > wrote:
>
> > Thank you very much for the prompt reply Ralph.
> >
> > As far as I can see, the SyslogAppender class does not expose a way to
> > access these attributes. So, if there is no other way of accessing these
> > attributes, then I am not able to retrieve the attributes that I want
> from
> > the existing SyslogAppender implementation. If I understand correctly,
> > correct me if I am wrong, I might have to create my own that exposes
> these
> > attributes.
> >
> > Apos
> >
> > On Tue, Jan 26, 2016 at 8:03 PM, Ralph Goers  >
> > wrote:
> >
> > > Not exactly. You can do:
> > >
> > > Appender appender =
> ctx.getConfiguration().getAppender(“syslogAppender”);
> > >
> > > then you would have to do
> > >
> > > SyslogAppender syslogAppender = (SyslogAppender) appender;
> > >
> > > normally you would probably use instanceof to verify it is actually a
> > > SyslogAppender.
> > >
> > > Once you have that you can call whatever methods the SyslogAppender
> > > exposes for getting its attributes. They are not stored in a Map
> however,
> > > so you can’t just call a generic getAttribute method.
> > >
> > > Ralph
> > >
> > >
> > > > On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis <
> > > ap.giannaki...@gmail.com> wrote:
> > > >
> > > > Hello team,
> > > >
> > > > I have created a logger with an appender using the
> ConfigurationBuilder
> > > and
> > > > the AppenderComponentBuilder.
> > > >
> > > > Let's say that this is how I create my appender:
> > > >
> > > > AppenderComponentBuilder appenderBuilder =
> > > >builder.newAppender( "syslogAppender", "Syslog" )
> > > >.addAttribute( "protocol", "TCP" )
> > > >.addAttribute( "host", "localhost" )
> > > >.addAttribute( "port", 514 )
> > > >.addAttribute( "facility", "LOCAL2" )
> > > >.addAttribute( "immediateFlush", true )
> > > >.addAttribute( "newLine", true );
> > > >
> > > > Then, after I finish creating the builder I use the
> > > > Configurator.initialize( builder.build() ) to get the LoggerContext.
> > > >
> > > > Is there any way I can access the attributes of the appender through
> > the
> > > > LoggerContext?
> > > >
> > > > For example something like this:
> > > >
> > > > LoggerContext ctx = Configurator.initialize( builder.build() );
> > > >
> > > > String hostname =
> > > >
> > >
> >
> ctx.getConfiguration()..getAppenders().get("syslogAppender").getAttribute("host");
> > > >
> > > > Thank you all very much for your help.
> > > >
> > > > Apostolis
> > >
> > >
> > >
> > > -
> > > To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> > > For additional commands, e-mail: log4j-user-h...@logging.apache.org
> > >
> > >
> >
>
>
>
> --
> Matt Sicker 
>



-- 
E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
Java Persistence with Hibernate, Second Edition

JUnit in Action, Second Edition 
Spring Batch in Action 
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory


Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Ralph Goers
Actually, I kind of like the idea of adding a getAttributes() method to the 
Appender interface. Then each concrete Appender would do:

public void getAttributes() {
Map attributes = new HashMap<>();
super.getAttributes(attributes):
attributes.put(“myAttribute1”, “value1”);
return Collections.unmodifiableMap(attributes);
}



> On Jan 26, 2016, at 1:28 PM, Gary Gregory  wrote:
> 
> How about adding getters for the fields
> in org.apache.logging.log4j.core.net.AbstractSocketManager?
> 
> Gary
> 
> On Tue, Jan 26, 2016 at 12:20 PM, Matt Sicker  wrote:
> 
>> You could always use reflection to access it for now.
>> 
>> On 26 January 2016 at 14:17, Apostolis Giannakidis <
>> ap.giannaki...@gmail.com
>>> wrote:
>> 
>>> Thank you very much for the prompt reply Ralph.
>>> 
>>> As far as I can see, the SyslogAppender class does not expose a way to
>>> access these attributes. So, if there is no other way of accessing these
>>> attributes, then I am not able to retrieve the attributes that I want
>> from
>>> the existing SyslogAppender implementation. If I understand correctly,
>>> correct me if I am wrong, I might have to create my own that exposes
>> these
>>> attributes.
>>> 
>>> Apos
>>> 
>>> On Tue, Jan 26, 2016 at 8:03 PM, Ralph Goers >> 
>>> wrote:
>>> 
 Not exactly. You can do:
 
 Appender appender =
>> ctx.getConfiguration().getAppender(“syslogAppender”);
 
 then you would have to do
 
 SyslogAppender syslogAppender = (SyslogAppender) appender;
 
 normally you would probably use instanceof to verify it is actually a
 SyslogAppender.
 
 Once you have that you can call whatever methods the SyslogAppender
 exposes for getting its attributes. They are not stored in a Map
>> however,
 so you can’t just call a generic getAttribute method.
 
 Ralph
 
 
> On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis <
 ap.giannaki...@gmail.com> wrote:
> 
> Hello team,
> 
> I have created a logger with an appender using the
>> ConfigurationBuilder
 and
> the AppenderComponentBuilder.
> 
> Let's say that this is how I create my appender:
> 
> AppenderComponentBuilder appenderBuilder =
>   builder.newAppender( "syslogAppender", "Syslog" )
>   .addAttribute( "protocol", "TCP" )
>   .addAttribute( "host", "localhost" )
>   .addAttribute( "port", 514 )
>   .addAttribute( "facility", "LOCAL2" )
>   .addAttribute( "immediateFlush", true )
>   .addAttribute( "newLine", true );
> 
> Then, after I finish creating the builder I use the
> Configurator.initialize( builder.build() ) to get the LoggerContext.
> 
> Is there any way I can access the attributes of the appender through
>>> the
> LoggerContext?
> 
> For example something like this:
> 
> LoggerContext ctx = Configurator.initialize( builder.build() );
> 
> String hostname =
> 
 
>>> 
>> ctx.getConfiguration()..getAppenders().get("syslogAppender").getAttribute("host");
> 
> Thank you all very much for your help.
> 
> Apostolis
 
 
 
 -
 To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
 For additional commands, e-mail: log4j-user-h...@logging.apache.org
 
 
>>> 
>> 
>> 
>> 
>> --
>> Matt Sicker 
>> 
> 
> 
> 
> -- 
> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
> Java Persistence with Hibernate, Second Edition
> 
> JUnit in Action, Second Edition 
> Spring Batch in Action 
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory



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



Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Apostolis Giannakidis
Actually, since this seems to be a useful feature, I would love to do the
patch myself and contribute it to the project, if you don't mind.

On Tue, Jan 26, 2016 at 8:56 PM, Ralph Goers 
wrote:

> Actually, I kind of like the idea of adding a getAttributes() method to
> the Appender interface. Then each concrete Appender would do:
>
> public void getAttributes() {
> Map attributes = new HashMap<>();
> super.getAttributes(attributes):
> attributes.put(“myAttribute1”, “value1”);
> return Collections.unmodifiableMap(attributes);
> }
>
>
>
> > On Jan 26, 2016, at 1:28 PM, Gary Gregory 
> wrote:
> >
> > How about adding getters for the fields
> > in org.apache.logging.log4j.core.net.AbstractSocketManager?
> >
> > Gary
> >
> > On Tue, Jan 26, 2016 at 12:20 PM, Matt Sicker  wrote:
> >
> >> You could always use reflection to access it for now.
> >>
> >> On 26 January 2016 at 14:17, Apostolis Giannakidis <
> >> ap.giannaki...@gmail.com
> >>> wrote:
> >>
> >>> Thank you very much for the prompt reply Ralph.
> >>>
> >>> As far as I can see, the SyslogAppender class does not expose a way to
> >>> access these attributes. So, if there is no other way of accessing
> these
> >>> attributes, then I am not able to retrieve the attributes that I want
> >> from
> >>> the existing SyslogAppender implementation. If I understand correctly,
> >>> correct me if I am wrong, I might have to create my own that exposes
> >> these
> >>> attributes.
> >>>
> >>> Apos
> >>>
> >>> On Tue, Jan 26, 2016 at 8:03 PM, Ralph Goers <
> ralph.go...@dslextreme.com
> >>>
> >>> wrote:
> >>>
>  Not exactly. You can do:
> 
>  Appender appender =
> >> ctx.getConfiguration().getAppender(“syslogAppender”);
> 
>  then you would have to do
> 
>  SyslogAppender syslogAppender = (SyslogAppender) appender;
> 
>  normally you would probably use instanceof to verify it is actually a
>  SyslogAppender.
> 
>  Once you have that you can call whatever methods the SyslogAppender
>  exposes for getting its attributes. They are not stored in a Map
> >> however,
>  so you can’t just call a generic getAttribute method.
> 
>  Ralph
> 
> 
> > On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis <
>  ap.giannaki...@gmail.com> wrote:
> >
> > Hello team,
> >
> > I have created a logger with an appender using the
> >> ConfigurationBuilder
>  and
> > the AppenderComponentBuilder.
> >
> > Let's say that this is how I create my appender:
> >
> > AppenderComponentBuilder appenderBuilder =
> >   builder.newAppender( "syslogAppender", "Syslog" )
> >   .addAttribute( "protocol", "TCP" )
> >   .addAttribute( "host", "localhost" )
> >   .addAttribute( "port", 514 )
> >   .addAttribute( "facility", "LOCAL2" )
> >   .addAttribute( "immediateFlush", true )
> >   .addAttribute( "newLine", true );
> >
> > Then, after I finish creating the builder I use the
> > Configurator.initialize( builder.build() ) to get the LoggerContext.
> >
> > Is there any way I can access the attributes of the appender through
> >>> the
> > LoggerContext?
> >
> > For example something like this:
> >
> > LoggerContext ctx = Configurator.initialize( builder.build() );
> >
> > String hostname =
> >
> 
> >>>
> >>
> ctx.getConfiguration()..getAppenders().get("syslogAppender").getAttribute("host");
> >
> > Thank you all very much for your help.
> >
> > Apostolis
> 
> 
> 
>  -
>  To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
>  For additional commands, e-mail: log4j-user-h...@logging.apache.org
> 
> 
> >>>
> >>
> >>
> >>
> >> --
> >> Matt Sicker 
> >>
> >
> >
> >
> > --
> > E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
> > Java Persistence with Hibernate, Second Edition
> > 
> > JUnit in Action, Second Edition 
> > Spring Batch in Action 
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
>
>
>
> -
> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>
>


Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Gary Gregory
On Tue, Jan 26, 2016 at 1:06 PM, Apostolis Giannakidis <
ap.giannaki...@gmail.com> wrote:

> Actually, since this seems to be a useful feature, I would love to do the
> patch myself and contribute it to the project, if you don't mind.
>

Do you plan on implementing this for all Appenders?

Gary

>
> On Tue, Jan 26, 2016 at 8:56 PM, Ralph Goers 
> wrote:
>
> > Actually, I kind of like the idea of adding a getAttributes() method to
> > the Appender interface. Then each concrete Appender would do:
> >
> > public void getAttributes() {
> > Map attributes = new HashMap<>();
> > super.getAttributes(attributes):
> > attributes.put(“myAttribute1”, “value1”);
> > return Collections.unmodifiableMap(attributes);
> > }
> >
> >
> >
> > > On Jan 26, 2016, at 1:28 PM, Gary Gregory 
> > wrote:
> > >
> > > How about adding getters for the fields
> > > in org.apache.logging.log4j.core.net.AbstractSocketManager?
> > >
> > > Gary
> > >
> > > On Tue, Jan 26, 2016 at 12:20 PM, Matt Sicker 
> wrote:
> > >
> > >> You could always use reflection to access it for now.
> > >>
> > >> On 26 January 2016 at 14:17, Apostolis Giannakidis <
> > >> ap.giannaki...@gmail.com
> > >>> wrote:
> > >>
> > >>> Thank you very much for the prompt reply Ralph.
> > >>>
> > >>> As far as I can see, the SyslogAppender class does not expose a way
> to
> > >>> access these attributes. So, if there is no other way of accessing
> > these
> > >>> attributes, then I am not able to retrieve the attributes that I want
> > >> from
> > >>> the existing SyslogAppender implementation. If I understand
> correctly,
> > >>> correct me if I am wrong, I might have to create my own that exposes
> > >> these
> > >>> attributes.
> > >>>
> > >>> Apos
> > >>>
> > >>> On Tue, Jan 26, 2016 at 8:03 PM, Ralph Goers <
> > ralph.go...@dslextreme.com
> > >>>
> > >>> wrote:
> > >>>
> >  Not exactly. You can do:
> > 
> >  Appender appender =
> > >> ctx.getConfiguration().getAppender(“syslogAppender”);
> > 
> >  then you would have to do
> > 
> >  SyslogAppender syslogAppender = (SyslogAppender) appender;
> > 
> >  normally you would probably use instanceof to verify it is actually
> a
> >  SyslogAppender.
> > 
> >  Once you have that you can call whatever methods the SyslogAppender
> >  exposes for getting its attributes. They are not stored in a Map
> > >> however,
> >  so you can’t just call a generic getAttribute method.
> > 
> >  Ralph
> > 
> > 
> > > On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis <
> >  ap.giannaki...@gmail.com> wrote:
> > >
> > > Hello team,
> > >
> > > I have created a logger with an appender using the
> > >> ConfigurationBuilder
> >  and
> > > the AppenderComponentBuilder.
> > >
> > > Let's say that this is how I create my appender:
> > >
> > > AppenderComponentBuilder appenderBuilder =
> > >   builder.newAppender( "syslogAppender", "Syslog" )
> > >   .addAttribute( "protocol", "TCP" )
> > >   .addAttribute( "host", "localhost" )
> > >   .addAttribute( "port", 514 )
> > >   .addAttribute( "facility", "LOCAL2" )
> > >   .addAttribute( "immediateFlush", true )
> > >   .addAttribute( "newLine", true );
> > >
> > > Then, after I finish creating the builder I use the
> > > Configurator.initialize( builder.build() ) to get the
> LoggerContext.
> > >
> > > Is there any way I can access the attributes of the appender
> through
> > >>> the
> > > LoggerContext?
> > >
> > > For example something like this:
> > >
> > > LoggerContext ctx = Configurator.initialize( builder.build() );
> > >
> > > String hostname =
> > >
> > 
> > >>>
> > >>
> >
> ctx.getConfiguration()..getAppenders().get("syslogAppender").getAttribute("host");
> > >
> > > Thank you all very much for your help.
> > >
> > > Apostolis
> > 
> > 
> > 
> > 
> -
> >  To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> >  For additional commands, e-mail: log4j-user-h...@logging.apache.org
> > 
> > 
> > >>>
> > >>
> > >>
> > >>
> > >> --
> > >> Matt Sicker 
> > >>
> > >
> > >
> > >
> > > --
> > > E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
> > > Java Persistence with Hibernate, Second Edition
> > > 
> > > JUnit in Action, Second Edition 
> > > Spring Batch in Action 
> > > Blog: http://garygregory.wordpress.com
> > > Home: http://garygregory.com/
> > > Tweet! http://twitter.com/GaryGregory
> >
> >
> >
> > -

Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Apostolis Giannakidis
Well, since the idea is to add it to the Appender interface, it means that
all concrete Appenders need to be modified as well. So, yes, I can give it
a try to implement it for all the Appenders. One other simple way would be
to implement it once in the AbstractAppender so that all its subclasses
will inherit it.

On Tue, Jan 26, 2016 at 9:15 PM, Gary Gregory 
wrote:

> On Tue, Jan 26, 2016 at 1:06 PM, Apostolis Giannakidis <
> ap.giannaki...@gmail.com> wrote:
>
> > Actually, since this seems to be a useful feature, I would love to do the
> > patch myself and contribute it to the project, if you don't mind.
> >
>
> Do you plan on implementing this for all Appenders?
>
> Gary
>
> >
> > On Tue, Jan 26, 2016 at 8:56 PM, Ralph Goers  >
> > wrote:
> >
> > > Actually, I kind of like the idea of adding a getAttributes() method to
> > > the Appender interface. Then each concrete Appender would do:
> > >
> > > public void getAttributes() {
> > > Map attributes = new HashMap<>();
> > > super.getAttributes(attributes):
> > > attributes.put(“myAttribute1”, “value1”);
> > > return Collections.unmodifiableMap(attributes);
> > > }
> > >
> > >
> > >
> > > > On Jan 26, 2016, at 1:28 PM, Gary Gregory 
> > > wrote:
> > > >
> > > > How about adding getters for the fields
> > > > in org.apache.logging.log4j.core.net.AbstractSocketManager?
> > > >
> > > > Gary
> > > >
> > > > On Tue, Jan 26, 2016 at 12:20 PM, Matt Sicker 
> > wrote:
> > > >
> > > >> You could always use reflection to access it for now.
> > > >>
> > > >> On 26 January 2016 at 14:17, Apostolis Giannakidis <
> > > >> ap.giannaki...@gmail.com
> > > >>> wrote:
> > > >>
> > > >>> Thank you very much for the prompt reply Ralph.
> > > >>>
> > > >>> As far as I can see, the SyslogAppender class does not expose a way
> > to
> > > >>> access these attributes. So, if there is no other way of accessing
> > > these
> > > >>> attributes, then I am not able to retrieve the attributes that I
> want
> > > >> from
> > > >>> the existing SyslogAppender implementation. If I understand
> > correctly,
> > > >>> correct me if I am wrong, I might have to create my own that
> exposes
> > > >> these
> > > >>> attributes.
> > > >>>
> > > >>> Apos
> > > >>>
> > > >>> On Tue, Jan 26, 2016 at 8:03 PM, Ralph Goers <
> > > ralph.go...@dslextreme.com
> > > >>>
> > > >>> wrote:
> > > >>>
> > >  Not exactly. You can do:
> > > 
> > >  Appender appender =
> > > >> ctx.getConfiguration().getAppender(“syslogAppender”);
> > > 
> > >  then you would have to do
> > > 
> > >  SyslogAppender syslogAppender = (SyslogAppender) appender;
> > > 
> > >  normally you would probably use instanceof to verify it is
> actually
> > a
> > >  SyslogAppender.
> > > 
> > >  Once you have that you can call whatever methods the
> SyslogAppender
> > >  exposes for getting its attributes. They are not stored in a Map
> > > >> however,
> > >  so you can’t just call a generic getAttribute method.
> > > 
> > >  Ralph
> > > 
> > > 
> > > > On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis <
> > >  ap.giannaki...@gmail.com> wrote:
> > > >
> > > > Hello team,
> > > >
> > > > I have created a logger with an appender using the
> > > >> ConfigurationBuilder
> > >  and
> > > > the AppenderComponentBuilder.
> > > >
> > > > Let's say that this is how I create my appender:
> > > >
> > > > AppenderComponentBuilder appenderBuilder =
> > > >   builder.newAppender( "syslogAppender", "Syslog" )
> > > >   .addAttribute( "protocol", "TCP" )
> > > >   .addAttribute( "host", "localhost" )
> > > >   .addAttribute( "port", 514 )
> > > >   .addAttribute( "facility", "LOCAL2" )
> > > >   .addAttribute( "immediateFlush", true )
> > > >   .addAttribute( "newLine", true );
> > > >
> > > > Then, after I finish creating the builder I use the
> > > > Configurator.initialize( builder.build() ) to get the
> > LoggerContext.
> > > >
> > > > Is there any way I can access the attributes of the appender
> > through
> > > >>> the
> > > > LoggerContext?
> > > >
> > > > For example something like this:
> > > >
> > > > LoggerContext ctx = Configurator.initialize( builder.build() );
> > > >
> > > > String hostname =
> > > >
> > > 
> > > >>>
> > > >>
> > >
> >
> ctx.getConfiguration()..getAppenders().get("syslogAppender").getAttribute("host");
> > > >
> > > > Thank you all very much for your help.
> > > >
> > > > Apostolis
> > > 
> > > 
> > > 
> > > 
> > -
> > >  To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
> > >  For additional 

Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Gary Gregory
I could see AbstractAppender implementing a getAttributes() method like
this:

public Map getAttributes() {
Map map = new HashMap<>();
fillAttributeMap(map);
// (1) should the map be read-only? why?
// (2) if the map is cached in an ivar, the it must be updated by
each appender when an attribute changes, so
// I'd say no and follow the KISS principle for now.
return map;
}

protected void fillAttributeMap(Map map) {
// ...
}

The boilerplate of creating and/or managing the map can be in getAttributes().
Actually filling in the map in is done in fillAttributeMap() which each
appender can override.

fillAttributeMap() could be abstract to force each appender to make sure
developers pay attention to providing an implementation.

Gary


On Tue, Jan 26, 2016 at 3:46 PM, Apostolis Giannakidis <
ap.giannaki...@gmail.com> wrote:

> Well, since the idea is to add it to the Appender interface, it means that
> all concrete Appenders need to be modified as well. So, yes, I can give it
> a try to implement it for all the Appenders. One other simple way would be
> to implement it once in the AbstractAppender so that all its subclasses
> will inherit it.
>
> On Tue, Jan 26, 2016 at 9:15 PM, Gary Gregory 
> wrote:
>
> > On Tue, Jan 26, 2016 at 1:06 PM, Apostolis Giannakidis <
> > ap.giannaki...@gmail.com> wrote:
> >
> > > Actually, since this seems to be a useful feature, I would love to do
> the
> > > patch myself and contribute it to the project, if you don't mind.
> > >
> >
> > Do you plan on implementing this for all Appenders?
> >
> > Gary
> >
> > >
> > > On Tue, Jan 26, 2016 at 8:56 PM, Ralph Goers <
> ralph.go...@dslextreme.com
> > >
> > > wrote:
> > >
> > > > Actually, I kind of like the idea of adding a getAttributes() method
> to
> > > > the Appender interface. Then each concrete Appender would do:
> > > >
> > > > public void getAttributes() {
> > > > Map attributes = new HashMap<>();
> > > > super.getAttributes(attributes):
> > > > attributes.put(“myAttribute1”, “value1”);
> > > > return Collections.unmodifiableMap(attributes);
> > > > }
> > > >
> > > >
> > > >
> > > > > On Jan 26, 2016, at 1:28 PM, Gary Gregory 
> > > > wrote:
> > > > >
> > > > > How about adding getters for the fields
> > > > > in org.apache.logging.log4j.core.net.AbstractSocketManager?
> > > > >
> > > > > Gary
> > > > >
> > > > > On Tue, Jan 26, 2016 at 12:20 PM, Matt Sicker 
> > > wrote:
> > > > >
> > > > >> You could always use reflection to access it for now.
> > > > >>
> > > > >> On 26 January 2016 at 14:17, Apostolis Giannakidis <
> > > > >> ap.giannaki...@gmail.com
> > > > >>> wrote:
> > > > >>
> > > > >>> Thank you very much for the prompt reply Ralph.
> > > > >>>
> > > > >>> As far as I can see, the SyslogAppender class does not expose a
> way
> > > to
> > > > >>> access these attributes. So, if there is no other way of
> accessing
> > > > these
> > > > >>> attributes, then I am not able to retrieve the attributes that I
> > want
> > > > >> from
> > > > >>> the existing SyslogAppender implementation. If I understand
> > > correctly,
> > > > >>> correct me if I am wrong, I might have to create my own that
> > exposes
> > > > >> these
> > > > >>> attributes.
> > > > >>>
> > > > >>> Apos
> > > > >>>
> > > > >>> On Tue, Jan 26, 2016 at 8:03 PM, Ralph Goers <
> > > > ralph.go...@dslextreme.com
> > > > >>>
> > > > >>> wrote:
> > > > >>>
> > > >  Not exactly. You can do:
> > > > 
> > > >  Appender appender =
> > > > >> ctx.getConfiguration().getAppender(“syslogAppender”);
> > > > 
> > > >  then you would have to do
> > > > 
> > > >  SyslogAppender syslogAppender = (SyslogAppender) appender;
> > > > 
> > > >  normally you would probably use instanceof to verify it is
> > actually
> > > a
> > > >  SyslogAppender.
> > > > 
> > > >  Once you have that you can call whatever methods the
> > SyslogAppender
> > > >  exposes for getting its attributes. They are not stored in a Map
> > > > >> however,
> > > >  so you can’t just call a generic getAttribute method.
> > > > 
> > > >  Ralph
> > > > 
> > > > 
> > > > > On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis <
> > > >  ap.giannaki...@gmail.com> wrote:
> > > > >
> > > > > Hello team,
> > > > >
> > > > > I have created a logger with an appender using the
> > > > >> ConfigurationBuilder
> > > >  and
> > > > > the AppenderComponentBuilder.
> > > > >
> > > > > Let's say that this is how I create my appender:
> > > > >
> > > > > AppenderComponentBuilder appenderBuilder =
> > > > >   builder.newAppender( "syslogAppender", "Syslog" )
> > > > >   .addAttribute( "protocol", "TCP" )
> > > > >   .addAttribute( "host", 

Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Apostolis Giannakidis
One thing to note here. Correct me if I am wrong, but the map should
be Map because not all attributes are Strings. From the top of my head, I
know that an attribute could also be a boolean.

On Wed, Jan 27, 2016 at 12:06 AM, Gary Gregory 
wrote:

> I could see AbstractAppender implementing a getAttributes() method like
> this:
>
> public Map getAttributes() {
> Map map = new HashMap<>();
> fillAttributeMap(map);
> // (1) should the map be read-only? why?
> // (2) if the map is cached in an ivar, the it must be updated by
> each appender when an attribute changes, so
> // I'd say no and follow the KISS principle for now.
> return map;
> }
>
> protected void fillAttributeMap(Map map) {
> // ...
> }
>
> The boilerplate of creating and/or managing the map can be in
> getAttributes().
> Actually filling in the map in is done in fillAttributeMap() which each
> appender can override.
>
> fillAttributeMap() could be abstract to force each appender to make sure
> developers pay attention to providing an implementation.
>
> Gary
>
>
> On Tue, Jan 26, 2016 at 3:46 PM, Apostolis Giannakidis <
> ap.giannaki...@gmail.com> wrote:
>
> > Well, since the idea is to add it to the Appender interface, it means
> that
> > all concrete Appenders need to be modified as well. So, yes, I can give
> it
> > a try to implement it for all the Appenders. One other simple way would
> be
> > to implement it once in the AbstractAppender so that all its subclasses
> > will inherit it.
> >
> > On Tue, Jan 26, 2016 at 9:15 PM, Gary Gregory 
> > wrote:
> >
> > > On Tue, Jan 26, 2016 at 1:06 PM, Apostolis Giannakidis <
> > > ap.giannaki...@gmail.com> wrote:
> > >
> > > > Actually, since this seems to be a useful feature, I would love to do
> > the
> > > > patch myself and contribute it to the project, if you don't mind.
> > > >
> > >
> > > Do you plan on implementing this for all Appenders?
> > >
> > > Gary
> > >
> > > >
> > > > On Tue, Jan 26, 2016 at 8:56 PM, Ralph Goers <
> > ralph.go...@dslextreme.com
> > > >
> > > > wrote:
> > > >
> > > > > Actually, I kind of like the idea of adding a getAttributes()
> method
> > to
> > > > > the Appender interface. Then each concrete Appender would do:
> > > > >
> > > > > public void getAttributes() {
> > > > > Map attributes = new HashMap<>();
> > > > > super.getAttributes(attributes):
> > > > > attributes.put(“myAttribute1”, “value1”);
> > > > > return Collections.unmodifiableMap(attributes);
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > > > On Jan 26, 2016, at 1:28 PM, Gary Gregory <
> garydgreg...@gmail.com>
> > > > > wrote:
> > > > > >
> > > > > > How about adding getters for the fields
> > > > > > in org.apache.logging.log4j.core.net.AbstractSocketManager?
> > > > > >
> > > > > > Gary
> > > > > >
> > > > > > On Tue, Jan 26, 2016 at 12:20 PM, Matt Sicker 
> > > > wrote:
> > > > > >
> > > > > >> You could always use reflection to access it for now.
> > > > > >>
> > > > > >> On 26 January 2016 at 14:17, Apostolis Giannakidis <
> > > > > >> ap.giannaki...@gmail.com
> > > > > >>> wrote:
> > > > > >>
> > > > > >>> Thank you very much for the prompt reply Ralph.
> > > > > >>>
> > > > > >>> As far as I can see, the SyslogAppender class does not expose a
> > way
> > > > to
> > > > > >>> access these attributes. So, if there is no other way of
> > accessing
> > > > > these
> > > > > >>> attributes, then I am not able to retrieve the attributes that
> I
> > > want
> > > > > >> from
> > > > > >>> the existing SyslogAppender implementation. If I understand
> > > > correctly,
> > > > > >>> correct me if I am wrong, I might have to create my own that
> > > exposes
> > > > > >> these
> > > > > >>> attributes.
> > > > > >>>
> > > > > >>> Apos
> > > > > >>>
> > > > > >>> On Tue, Jan 26, 2016 at 8:03 PM, Ralph Goers <
> > > > > ralph.go...@dslextreme.com
> > > > > >>>
> > > > > >>> wrote:
> > > > > >>>
> > > > >  Not exactly. You can do:
> > > > > 
> > > > >  Appender appender =
> > > > > >> ctx.getConfiguration().getAppender(“syslogAppender”);
> > > > > 
> > > > >  then you would have to do
> > > > > 
> > > > >  SyslogAppender syslogAppender = (SyslogAppender) appender;
> > > > > 
> > > > >  normally you would probably use instanceof to verify it is
> > > actually
> > > > a
> > > > >  SyslogAppender.
> > > > > 
> > > > >  Once you have that you can call whatever methods the
> > > SyslogAppender
> > > > >  exposes for getting its attributes. They are not stored in a
> Map
> > > > > >> however,
> > > > >  so you can’t just call a generic getAttribute method.
> > > > > 
> > > > >  Ralph
> > > > > 
> > > > > 
> > > > > > On Jan 26, 2016, at 11:58 AM, Apostolis Giannakidis <
> > > > >  

Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Gary Gregory
Sure, Object makes sense.

Gary

On Tue, Jan 26, 2016 at 4:24 PM, Apostolis Giannakidis <
ap.giannaki...@gmail.com> wrote:

> One thing to note here. Correct me if I am wrong, but the map should
> be Map Object> because not all attributes are Strings. From the top of my head, I
> know that an attribute could also be a boolean.
>
> On Wed, Jan 27, 2016 at 12:06 AM, Gary Gregory 
> wrote:
>
> > I could see AbstractAppender implementing a getAttributes() method like
> > this:
> >
> > public Map getAttributes() {
> > Map map = new HashMap<>();
> > fillAttributeMap(map);
> > // (1) should the map be read-only? why?
> > // (2) if the map is cached in an ivar, the it must be updated by
> > each appender when an attribute changes, so
> > // I'd say no and follow the KISS principle for now.
> > return map;
> > }
> >
> > protected void fillAttributeMap(Map map) {
> > // ...
> > }
> >
> > The boilerplate of creating and/or managing the map can be in
> > getAttributes().
> > Actually filling in the map in is done in fillAttributeMap() which each
> > appender can override.
> >
> > fillAttributeMap() could be abstract to force each appender to make sure
> > developers pay attention to providing an implementation.
> >
> > Gary
> >
> >
> > On Tue, Jan 26, 2016 at 3:46 PM, Apostolis Giannakidis <
> > ap.giannaki...@gmail.com> wrote:
> >
> > > Well, since the idea is to add it to the Appender interface, it means
> > that
> > > all concrete Appenders need to be modified as well. So, yes, I can give
> > it
> > > a try to implement it for all the Appenders. One other simple way would
> > be
> > > to implement it once in the AbstractAppender so that all its subclasses
> > > will inherit it.
> > >
> > > On Tue, Jan 26, 2016 at 9:15 PM, Gary Gregory 
> > > wrote:
> > >
> > > > On Tue, Jan 26, 2016 at 1:06 PM, Apostolis Giannakidis <
> > > > ap.giannaki...@gmail.com> wrote:
> > > >
> > > > > Actually, since this seems to be a useful feature, I would love to
> do
> > > the
> > > > > patch myself and contribute it to the project, if you don't mind.
> > > > >
> > > >
> > > > Do you plan on implementing this for all Appenders?
> > > >
> > > > Gary
> > > >
> > > > >
> > > > > On Tue, Jan 26, 2016 at 8:56 PM, Ralph Goers <
> > > ralph.go...@dslextreme.com
> > > > >
> > > > > wrote:
> > > > >
> > > > > > Actually, I kind of like the idea of adding a getAttributes()
> > method
> > > to
> > > > > > the Appender interface. Then each concrete Appender would do:
> > > > > >
> > > > > > public void getAttributes() {
> > > > > > Map attributes = new HashMap<>();
> > > > > > super.getAttributes(attributes):
> > > > > > attributes.put(“myAttribute1”, “value1”);
> > > > > > return Collections.unmodifiableMap(attributes);
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > > > On Jan 26, 2016, at 1:28 PM, Gary Gregory <
> > garydgreg...@gmail.com>
> > > > > > wrote:
> > > > > > >
> > > > > > > How about adding getters for the fields
> > > > > > > in org.apache.logging.log4j.core.net.AbstractSocketManager?
> > > > > > >
> > > > > > > Gary
> > > > > > >
> > > > > > > On Tue, Jan 26, 2016 at 12:20 PM, Matt Sicker <
> boa...@gmail.com>
> > > > > wrote:
> > > > > > >
> > > > > > >> You could always use reflection to access it for now.
> > > > > > >>
> > > > > > >> On 26 January 2016 at 14:17, Apostolis Giannakidis <
> > > > > > >> ap.giannaki...@gmail.com
> > > > > > >>> wrote:
> > > > > > >>
> > > > > > >>> Thank you very much for the prompt reply Ralph.
> > > > > > >>>
> > > > > > >>> As far as I can see, the SyslogAppender class does not
> expose a
> > > way
> > > > > to
> > > > > > >>> access these attributes. So, if there is no other way of
> > > accessing
> > > > > > these
> > > > > > >>> attributes, then I am not able to retrieve the attributes
> that
> > I
> > > > want
> > > > > > >> from
> > > > > > >>> the existing SyslogAppender implementation. If I understand
> > > > > correctly,
> > > > > > >>> correct me if I am wrong, I might have to create my own that
> > > > exposes
> > > > > > >> these
> > > > > > >>> attributes.
> > > > > > >>>
> > > > > > >>> Apos
> > > > > > >>>
> > > > > > >>> On Tue, Jan 26, 2016 at 8:03 PM, Ralph Goers <
> > > > > > ralph.go...@dslextreme.com
> > > > > > >>>
> > > > > > >>> wrote:
> > > > > > >>>
> > > > > >  Not exactly. You can do:
> > > > > > 
> > > > > >  Appender appender =
> > > > > > >> ctx.getConfiguration().getAppender(“syslogAppender”);
> > > > > > 
> > > > > >  then you would have to do
> > > > > > 
> > > > > >  SyslogAppender syslogAppender = (SyslogAppender) appender;
> > > > > > 
> > > > > >  normally you would probably use instanceof to verify it is
> > > > actually
> > > > > a
> > > > > >  SyslogAppender.
> > > > > > 
> > > > > >  Once 

Re: Getter method for retrieving the attributes of an appender from the LoggerContext

2016-01-26 Thread Ralph Goers
All the attributes have to have String representations to be usable in the XML, 
JSON & Properties configurations. Yes, the Map could contain Objects but then 
every one of them has to be cast to its real object to be usable. 

The map should be read-only because modifying its contents would have no effect 
on the appender.

The map should not be stored in an ivar but constructed whenever the attributes 
are retrieved. Otherwise it will be temping to just keep them in a map and not 
as individual attributes, which would cause problems.

If you have nesting such as  MyAppender extends MyBaseAppender extends 
AbstractOutputStreamAppender extends AbstractAppender, I envision a 
fillAttributes method at each “level” that fills in the attributes it knows 
about, so fillAttributeMap(map) should always call super.fillAttributeMap(map) 
- except in AbstractAppender of course - and should call it before filling in 
its own attributes so that it can override any values provided by the base 
Appenders.  If the primary Appender does not implement fillAttributeMap then 
only the attributes of its super classes will be included, which is actually 
correct for the SyslogAppender.

Ralph

> On Jan 26, 2016, at 5:24 PM, Apostolis Giannakidis  
> wrote:
> 
> One thing to note here. Correct me if I am wrong, but the map should
> be Map Object> because not all attributes are Strings. From the top of my head, I
> know that an attribute could also be a boolean.
> 
> On Wed, Jan 27, 2016 at 12:06 AM, Gary Gregory 
> wrote:
> 
>> I could see AbstractAppender implementing a getAttributes() method like
>> this:
>> 
>>public Map getAttributes() {
>>Map map = new HashMap<>();
>>fillAttributeMap(map);
>>// (1) should the map be read-only? why?
>>// (2) if the map is cached in an ivar, the it must be updated by
>> each appender when an attribute changes, so
>>// I'd say no and follow the KISS principle for now.
>>return map;
>>}
>> 
>>protected void fillAttributeMap(Map map) {
>>// ...
>>}
>> 
>> The boilerplate of creating and/or managing the map can be in
>> getAttributes().
>> Actually filling in the map in is done in fillAttributeMap() which each
>> appender can override.
>> 
>> fillAttributeMap() could be abstract to force each appender to make sure
>> developers pay attention to providing an implementation.
>> 
>> Gary
>> 
>> 
>> On Tue, Jan 26, 2016 at 3:46 PM, Apostolis Giannakidis <
>> ap.giannaki...@gmail.com> wrote:
>> 
>>> Well, since the idea is to add it to the Appender interface, it means
>> that
>>> all concrete Appenders need to be modified as well. So, yes, I can give
>> it
>>> a try to implement it for all the Appenders. One other simple way would
>> be
>>> to implement it once in the AbstractAppender so that all its subclasses
>>> will inherit it.
>>> 
>>> On Tue, Jan 26, 2016 at 9:15 PM, Gary Gregory 
>>> wrote:
>>> 
 On Tue, Jan 26, 2016 at 1:06 PM, Apostolis Giannakidis <
 ap.giannaki...@gmail.com> wrote:
 
> Actually, since this seems to be a useful feature, I would love to do
>>> the
> patch myself and contribute it to the project, if you don't mind.
> 
 
 Do you plan on implementing this for all Appenders?
 
 Gary
 
> 
> On Tue, Jan 26, 2016 at 8:56 PM, Ralph Goers <
>>> ralph.go...@dslextreme.com
> 
> wrote:
> 
>> Actually, I kind of like the idea of adding a getAttributes()
>> method
>>> to
>> the Appender interface. Then each concrete Appender would do:
>> 
>> public void getAttributes() {
>>Map attributes = new HashMap<>();
>>super.getAttributes(attributes):
>>attributes.put(“myAttribute1”, “value1”);
>>return Collections.unmodifiableMap(attributes);
>> }
>> 
>> 
>> 
>>> On Jan 26, 2016, at 1:28 PM, Gary Gregory <
>> garydgreg...@gmail.com>
>> wrote:
>>> 
>>> How about adding getters for the fields
>>> in org.apache.logging.log4j.core.net.AbstractSocketManager?
>>> 
>>> Gary
>>> 
>>> On Tue, Jan 26, 2016 at 12:20 PM, Matt Sicker 
> wrote:
>>> 
 You could always use reflection to access it for now.
 
 On 26 January 2016 at 14:17, Apostolis Giannakidis <
 ap.giannaki...@gmail.com
> wrote:
 
> Thank you very much for the prompt reply Ralph.
> 
> As far as I can see, the SyslogAppender class does not expose a
>>> way
> to
> access these attributes. So, if there is no other way of
>>> accessing
>> these
> attributes, then I am not able to retrieve the attributes that
>> I
 want
 from
> the existing SyslogAppender implementation. If I understand
> correctly,
> correct me if I am