Re: plugins

2015-08-28 Thread Remko Popma
PrintObject determines if the startup status log messages should include 
initialization statements for this plugin (if my understanding is correct).

Sent from my iPhone

> On 2015/08/28, at 13:47, Nicholas Duane  wrote:
> 
> While I got my LevelRangeFilter working I didn't get an answer to #1 below.  
> Can someone answer that for me so that I can code appropriately?
> 
> Thanks,
> Nick
> 
>> From: nic...@msn.com
>> To: log4j-user@logging.apache.org
>> Subject: plugins
>> Date: Thu, 27 Aug 2015 14:51:58 -0400
>> 
>> 
>> 
>> 
>> I've got a couple questions regarding plugins I'm hoping someone might be 
>> able to help me with.  I checked the docs and it's still not quite clear.
>> 
>> 1. I'm unsure what to set printObject to in my Plugin annotation.  From 
>> http://logging.apache.org/log4j/2.x/manual/extending.html it says:
>> 
>> "Specifying the printObject attribute with a value of "true" indicates that 
>> a call to toString will format the arguments to the filter as the 
>> configuration is being processed."
>> 
>> which unfortunately doesn't clear things up any.  I looked at the docs for 
>> printObject and that doesn't say anything other than it's a Boolean and its 
>> default is false.
>> 
>> 2. I created a LevelRangeFiler and I'm trying to figure out how to get it 
>> loaded by log4j.  I read over the instructions on plugins located at 
>> http://logging.apache.org/log4j/2.x/manual/plugins.html but since I'm a java 
>> noob I'm still a bit lost.  I'm wondering, if I just have a .java class 
>> which I compile to a .class file, can that be used?  If so, how?
>> 
>> Below is the filter I wrote based on looking at the threshold filter example 
>> at http://logging.apache.org/log4j/2.x/manual/extending.html.
>> 
>> import org.apache.logging.log4j.core.filter.AbstractFilter;
>> import org.apache.logging.log4j.core.Filter;
>> import org.apache.logging.log4j.core.config.plugins.Plugin;
>> import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>> import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>> import org.apache.logging.log4j.Level;
>> import org.apache.logging.log4j.core.LogEvent;
>> import org.apache.logging.log4j.core.Logger;
>> import org.apache.logging.log4j.Marker;
>> import org.apache.logging.log4j.message.Message;
>> 
>> @Plugin(name="LevelRangeFilter", category="Core", elementType="filter",
>>printObject=true)
>> public class LevelRangeFilter extends AbstractFilter
>> {
>>private final Level minLevel;
>>private final Level maxLevel;
>> 
>>public LevelRangeFilter(Level minLevel, Level maxLevel,
>>Filter.Result onMatch, Filter.Result onMismatch)
>>{
>>super(onMatch, onMismatch);
>>this.minLevel = minLevel;
>>this.maxLevel = maxLevel;
>>}
>> 
>>private Result filter(Level level)
>>{
>>if (level.isMoreSpecificThan(this.minLevel) &&
>>level.isLessSpecificThan(this.maxLevel))
>>{
>>return this.onMatch;
>>}
>>return this.onMismatch;
>>}
>> 
>>public Filter.Result filter(Logger logger, Level level,
>>Marker marker, String msg, Object[] params)
>>{
>>return filter(level);
>>}
>> 
>>public Filter.Result filter(Logger logger, Level level,
>>Marker marker, Object msg, Throwable t)
>>{
>>return filter(level);
>>}
>> 
>>public Filter.Result filter(Logger logger, Level level,
>>Marker marker, Message msg, Throwable t)
>>{
>>return filter(level);
>>}
>> 
>>public Filter.Result filter(LogEvent event)
>>{
>>return filter(event.getLevel());
>>}
>> 
>>@PluginFactory
>>public static LevelRangeFilter createFilter(
>>@PluginAttribute(value="minLevel",
>>defaultString="DEBUG") Level minLevel,
>>@PluginAttribute(value="maxLevel",
>>defaultString="FATAL") Level maxLevel,
>>@PluginAttribute(value="onMatch",
>>defaultString="NEUTRAL") Result onMatch,
>>@PluginAttribute(value="onMismatch",
>>defaultString="DENY") Result onMismatch)
>>{
>>return new LevelRangeFilter(minLevel, maxLevel, onMatch, onMismatch);
>>}
>> }
>> 
>> Thanks,
>> Nick
> 

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



Re: plugins

2015-08-27 Thread Ralph Goers
printObject affects the way plugins are logged when you have status=debug 
enabled.  If you set printObject to true then the Plugin’s toString method will 
be called to log the Plugin’s “name”.  Usually, this is just the 
SimpleClassName, but if the class name doesn’t match the Plugin name it can do 
something else.  For example, the RootLoggerConfig extends the LoggerConfig 
class so the toString() method does

public String toString() {
return Strings.isEmpty(name) ? "root" : name;
}
If you set the value to false then 

type.getPluginClass().getName() + " with name " + name
will be printed, where type is the PluginType annotation you declared and name 
is the name of the object, if it has one.
Generally, you should set printObject to true and make sure the toString() 
method does the right thing.  If you are extending AbstractFilter then it 
provides a toString() method for you that does
return this.getClass().getSimpleName();
HTH,
Ralph




> On Aug 27, 2015, at 9:47 PM, Nicholas Duane  wrote:
> 
> While I got my LevelRangeFilter working I didn't get an answer to #1 below.  
> Can someone answer that for me so that I can code appropriately?
> 
> Thanks,
> Nick
> 
>> From: nic...@msn.com
>> To: log4j-user@logging.apache.org
>> Subject: plugins
>> Date: Thu, 27 Aug 2015 14:51:58 -0400
>> 
>> 
>> 
>> 
>> I've got a couple questions regarding plugins I'm hoping someone might be 
>> able to help me with.  I checked the docs and it's still not quite clear.
>> 
>> 1. I'm unsure what to set printObject to in my Plugin annotation.  From 
>> http://logging.apache.org/log4j/2.x/manual/extending.html it says:
>> 
>> "Specifying the printObject attribute with a value of "true" indicates that 
>> a call to toString will format the arguments to the filter as the 
>> configuration is being processed."
>> 
>> which unfortunately doesn't clear things up any.  I looked at the docs for 
>> printObject and that doesn't say anything other than it's a Boolean and its 
>> default is false.
>> 
>> 2. I created a LevelRangeFiler and I'm trying to figure out how to get it 
>> loaded by log4j.  I read over the instructions on plugins located at 
>> http://logging.apache.org/log4j/2.x/manual/plugins.html but since I'm a java 
>> noob I'm still a bit lost.  I'm wondering, if I just have a .java class 
>> which I compile to a .class file, can that be used?  If so, how?
>> 
>> Below is the filter I wrote based on looking at the threshold filter example 
>> at http://logging.apache.org/log4j/2.x/manual/extending.html.
>> 
>> import org.apache.logging.log4j.core.filter.AbstractFilter;
>> import org.apache.logging.log4j.core.Filter;
>> import org.apache.logging.log4j.core.config.plugins.Plugin;
>> import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>> import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>> import org.apache.logging.log4j.Level;
>> import org.apache.logging.log4j.core.LogEvent;
>> import org.apache.logging.log4j.core.Logger;
>> import org.apache.logging.log4j.Marker;
>> import org.apache.logging.log4j.message.Message;
>> 
>> @Plugin(name="LevelRangeFilter", category="Core", elementType="filter",
>>printObject=true)
>> public class LevelRangeFilter extends AbstractFilter
>> {
>>private final Level minLevel;
>>private final Level maxLevel;
>> 
>>public LevelRangeFilter(Level minLevel, Level maxLevel,
>>Filter.Result onMatch, Filter.Result onMismatch)
>>{
>>super(onMatch, onMismatch);
>>this.minLevel = minLevel;
>>this.maxLevel = maxLevel;
>>}
>> 
>>private Result filter(Level level)
>>{
>>if (level.isMoreSpecificThan(this.minLevel) &&
>>level.isLessSpecificThan(this.maxLevel))
>>{
>>return this.onMatch;
>>}
>>return this.onMismatch;
>>}
>> 
>>public Filter.Result filter(Logger logger, Level level,
>>Marker marker, String msg, Object[] params)
>>{
>>return filter(level);
>>}
>> 
>>public Filter.Result filter(Logger logger, Level level,
>>Marker marker, Object msg, Throwable t)
>>{
>>return filter(level);
>>}
>> 
>>public Filter.Result filter(Logger logger, Level level,
>>Marker marker, Message msg, Throwable t)
>>{
>>return filter(level);
>>}
>> 
>>public Filter.Result filter(LogEvent event)
>>{
>>return filter(event.getLevel());
>>}
>> 
>>@PluginFactory
>>public static LevelRangeFilter createFilter(
>>@PluginAttribute(value="minLevel",
>>defaultString="DEBUG") Level minLevel,
>>@PluginAttribute(value="maxLevel",
>>defaultString="FATAL") Level maxLevel,
>>@PluginAttribute(value="onMatch",
>>defaultString="NEUTRAL") Result onMatch,
>>@PluginAttribute(value="onMismatch",
>>defaultString="DENY") Result onMismatch)
>>{
>>return new LevelRangeFilter(minLevel, maxLevel, onMatch, onMismatch);
>>}
>> }
>> 
>> Thanks,
>>

RE: plugins

2015-08-27 Thread Nicholas Duane
While I got my LevelRangeFilter working I didn't get an answer to #1 below.  
Can someone answer that for me so that I can code appropriately?
 
Thanks,
Nick
 
> From: nic...@msn.com
> To: log4j-user@logging.apache.org
> Subject: plugins
> Date: Thu, 27 Aug 2015 14:51:58 -0400
> 
> 
> 
> 
> I've got a couple questions regarding plugins I'm hoping someone might be 
> able to help me with.  I checked the docs and it's still not quite clear.
>  
> 1. I'm unsure what to set printObject to in my Plugin annotation.  From 
> http://logging.apache.org/log4j/2.x/manual/extending.html it says:
>  
> "Specifying the printObject attribute with a value of "true" indicates that a 
> call to toString will format the arguments to the filter as the configuration 
> is being processed."
>  
> which unfortunately doesn't clear things up any.  I looked at the docs for 
> printObject and that doesn't say anything other than it's a Boolean and its 
> default is false.
>  
> 2. I created a LevelRangeFiler and I'm trying to figure out how to get it 
> loaded by log4j.  I read over the instructions on plugins located at 
> http://logging.apache.org/log4j/2.x/manual/plugins.html but since I'm a java 
> noob I'm still a bit lost.  I'm wondering, if I just have a .java class which 
> I compile to a .class file, can that be used?  If so, how?
>  
> Below is the filter I wrote based on looking at the threshold filter example 
> at http://logging.apache.org/log4j/2.x/manual/extending.html.
> 
> import org.apache.logging.log4j.core.filter.AbstractFilter;
> import org.apache.logging.log4j.core.Filter;
> import org.apache.logging.log4j.core.config.plugins.Plugin;
> import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
> import org.apache.logging.log4j.core.config.plugins.PluginFactory;
> import org.apache.logging.log4j.Level;
> import org.apache.logging.log4j.core.LogEvent;
> import org.apache.logging.log4j.core.Logger;
> import org.apache.logging.log4j.Marker;
> import org.apache.logging.log4j.message.Message;
> 
> @Plugin(name="LevelRangeFilter", category="Core", elementType="filter",
> printObject=true)
> public class LevelRangeFilter extends AbstractFilter
> {
> private final Level minLevel;
> private final Level maxLevel;
> 
> public LevelRangeFilter(Level minLevel, Level maxLevel,
> Filter.Result onMatch, Filter.Result onMismatch)
> {
> super(onMatch, onMismatch);
> this.minLevel = minLevel;
> this.maxLevel = maxLevel;
> }
> 
> private Result filter(Level level)
> {
> if (level.isMoreSpecificThan(this.minLevel) &&
> level.isLessSpecificThan(this.maxLevel))
> {
> return this.onMatch;
> }
> return this.onMismatch;
> }
> 
> public Filter.Result filter(Logger logger, Level level,
> Marker marker, String msg, Object[] params)
> {
> return filter(level);
> }
> 
> public Filter.Result filter(Logger logger, Level level,
> Marker marker, Object msg, Throwable t)
> {
> return filter(level);
> }
> 
> public Filter.Result filter(Logger logger, Level level,
> Marker marker, Message msg, Throwable t)
> {
> return filter(level);
> }
> 
> public Filter.Result filter(LogEvent event)
> {
> return filter(event.getLevel());
> }
> 
> @PluginFactory
> public static LevelRangeFilter createFilter(
> @PluginAttribute(value="minLevel",
> defaultString="DEBUG") Level minLevel,
> @PluginAttribute(value="maxLevel",
> defaultString="FATAL") Level maxLevel,
> @PluginAttribute(value="onMatch",
> defaultString="NEUTRAL") Result onMatch,
> @PluginAttribute(value="onMismatch",
> defaultString="DENY") Result onMismatch)
> {
> return new LevelRangeFilter(minLevel, maxLevel, onMatch, onMismatch);
> }
> }
> 
> Thanks,
> Nick
> 
> 
> 
  

RE: plugins

2015-08-27 Thread Nicholas Duane
Awesome, thanks.  I needed a little bit more because of my java noobness, but I 
was able to figure that out.  Looks like I needed the -d on the javac command 
so that it created the appropriate directory structure for my .class file based 
on the package name.  Then things started working!!
 
Now I can filter on just a single level with my LevelRangeFilter.
 
Thanks for all the help.  Next I have to get the latest log4j installed on 
fedora 21 so that I can verify custom levels work.
 
Nick
 
> Date: Fri, 28 Aug 2015 07:51:32 +0900
> Subject: Re: plugins
> From: remko.po...@gmail.com
> To: log4j-user@logging.apache.org
> 
> I think you made a mistake there: your config says
> 
> 
> 
> 
> But your code does not have a package declaration at the top. This means it
> is in the default (nameless) package.
> Change your code to start with:
> 
> package com.mycomp.pluginpackage;
> import ...
> 
> And change your config to
> 
> 
> Using the plugin class name in the packages attribute won't work.
> 
> On Friday, August 28, 2015, Nicholas Duane  wrote:
> 
> > I tried that.  I created a jar, I think correctly, from my
> > LevelRangeFilter.class file.  I added that to the packages attribute, as
> > you can see in the config I previously sent.  It still doesn't work.
> >
> > Thanks,
> > Nick
> >
> > > Subject: Re: plugins
> > > From: remko.po...@gmail.com 
> > > Date: Fri, 28 Aug 2015 07:25:35 +0900
> > > To: log4j-user@logging.apache.org 
> > >
> > > Perhaps the simplest thing to do is to add the packages attribute to
> > your log4j2.xml configuration file. Set the value to the package of your
> > custom plugin.
> > >
> > > 
> > > ...
> > >
> > > Remko
> > >
> > > Sent from my iPhone
> > >
> > > > On 2015/08/28, at 6:42, Nicholas Duane >
> > wrote:
> > > >
> > > >
> > > >
> > > >
> > > > I don't think the implementation is the issue, though if/when I get my
> > plugin loading and it doesn't work I will certainly try to compare against
> > what Gary wrote.  Right now I'm just trying to figure out how to get my
> > plugin loaded.  I've got my class file, LevelRangeFilter.java which I
> > compiled to a .class file.  It resides in the same directory as my
> > HelloWorld.class file which contains my "main".  I was hoping my plugin
> > would get loaded but it doesn't seem to be.  What's the easiest way for me
> > to get it loaded?  Right now when I run my program I'm seeing the following
> > error from log4net:
> > > >
> > > > 2015-08-27 15:23:09,682 ERROR File contains an invalid element or
> > attribute "LevelRangeFilter"
> > > >
> > > > Here is my config:
> > > >
> > > > 
> > > >  > packages="LevelRangeFilter">
> > > >  
> > > >
> > > >
> > > >  
> > > >  
> > > >
> > > >  
> > > >%d %p %c{1.} [%t] %m%n
> > > >  
> > > >   > onMatch="ACCEPT"/>
> > > >
> > > >  
> > > >  
> > > >
> > > >  
> > > >
> > > >
> > > >
> > > >  
> > > > 
> > > >
> > > > Thanks,
> > > > Nick
> > > >
> > > >> Subject: Re: plugins
> > > >> From: ralph.go...@dslextreme.com 
> > > >> Date: Thu, 27 Aug 2015 14:20:28 -0700
> > > >> To: log4j-user@logging.apache.org 
> > > >>
> > > >> Can’t you just compare what you wrote to what Gary wrote?  If you
> > build your project then it should get packaged in a jar and automatically
> > have the file Log4j uses to quickly load the plugin.
> > > >>
> > > >> Ralph
> > > >>
> > > >>> On Aug 27, 2015, at 12:50 PM, Nicholas Duane  > > wrote:
> > > >>>
> > > >>> Based on your previous comments I assume one would show up
> > out-of-the-box at some point.  Of course I need mine now so unfortunately I
> > have to write one.
> > > >>>
> > > >>> Any input on my questions below?
> > > >>>
> > > >>> Thanks,
> > > >>> Nick
> > > >>>
> > > >>>> Date: Thu, 27 Aug 2015 12:20:

Re: plugins

2015-08-27 Thread Remko Popma
I think you made a mistake there: your config says




But your code does not have a package declaration at the top. This means it
is in the default (nameless) package.
Change your code to start with:

package com.mycomp.pluginpackage;
import ...

And change your config to


Using the plugin class name in the packages attribute won't work.

On Friday, August 28, 2015, Nicholas Duane  wrote:

> I tried that.  I created a jar, I think correctly, from my
> LevelRangeFilter.class file.  I added that to the packages attribute, as
> you can see in the config I previously sent.  It still doesn't work.
>
> Thanks,
> Nick
>
> > Subject: Re: plugins
> > From: remko.po...@gmail.com 
> > Date: Fri, 28 Aug 2015 07:25:35 +0900
> > To: log4j-user@logging.apache.org 
> >
> > Perhaps the simplest thing to do is to add the packages attribute to
> your log4j2.xml configuration file. Set the value to the package of your
> custom plugin.
> >
> > 
> > ...
> >
> > Remko
> >
> > Sent from my iPhone
> >
> > > On 2015/08/28, at 6:42, Nicholas Duane >
> wrote:
> > >
> > >
> > >
> > >
> > > I don't think the implementation is the issue, though if/when I get my
> plugin loading and it doesn't work I will certainly try to compare against
> what Gary wrote.  Right now I'm just trying to figure out how to get my
> plugin loaded.  I've got my class file, LevelRangeFilter.java which I
> compiled to a .class file.  It resides in the same directory as my
> HelloWorld.class file which contains my "main".  I was hoping my plugin
> would get loaded but it doesn't seem to be.  What's the easiest way for me
> to get it loaded?  Right now when I run my program I'm seeing the following
> error from log4net:
> > >
> > > 2015-08-27 15:23:09,682 ERROR File contains an invalid element or
> attribute "LevelRangeFilter"
> > >
> > > Here is my config:
> > >
> > > 
> > >  packages="LevelRangeFilter">
> > >  
> > >
> > >
> > >  
> > >  
> > >
> > >  
> > >%d %p %c{1.} [%t] %m%n
> > >  
> > >   onMatch="ACCEPT"/>
> > >
> > >  
> > >  
> > >
> > >  
> > >
> > >
> > >
> > >  
> > > 
> > >
> > > Thanks,
> > > Nick
> > >
> > >> Subject: Re: plugins
> > >> From: ralph.go...@dslextreme.com 
> > >> Date: Thu, 27 Aug 2015 14:20:28 -0700
> > >> To: log4j-user@logging.apache.org 
> > >>
> > >> Can’t you just compare what you wrote to what Gary wrote?  If you
> build your project then it should get packaged in a jar and automatically
> have the file Log4j uses to quickly load the plugin.
> > >>
> > >> Ralph
> > >>
> > >>> On Aug 27, 2015, at 12:50 PM, Nicholas Duane  > wrote:
> > >>>
> > >>> Based on your previous comments I assume one would show up
> out-of-the-box at some point.  Of course I need mine now so unfortunately I
> have to write one.
> > >>>
> > >>> Any input on my questions below?
> > >>>
> > >>> Thanks,
> > >>> Nick
> > >>>
> > >>>> Date: Thu, 27 Aug 2015 12:20:07 -0700
> > >>>> Subject: Re: plugins
> > >>>> From: garydgreg...@gmail.com 
> > >>>> To: log4j-user@logging.apache.org 
> > >>>>
> > >>>> Note that I wrote such a filter, which is under review ATM here:
> > >>>>
> > >>>> - https://issues.apache.org/jira/browse/LOG4J2-1106
> > >>>> - https://issues.apache.org/jira/browse/LOG4J2-1105
> > >>>>
> > >>>> Gary
> > >>>>
> > >>>>> On Thu, Aug 27, 2015 at 11:51 AM, Nicholas Duane  > wrote:
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>>
> > >>>>> I've got a couple questions regarding plugins I'm hoping someone
> might be
> > >>>>> able to help me with.  I checked the docs and it's still not quite
> clear.
> > >>>>>
> > >>>>> 1. I'm unsure what to set printObject to in my Plugin annotation.
> From
> > >>>>> http://logging.apache.org/log4j/2.x/ma

RE: plugins

2015-08-27 Thread Nicholas Duane
I tried that.  I created a jar, I think correctly, from my 
LevelRangeFilter.class file.  I added that to the packages attribute, as you 
can see in the config I previously sent.  It still doesn't work.
 
Thanks,
Nick
 
> Subject: Re: plugins
> From: remko.po...@gmail.com
> Date: Fri, 28 Aug 2015 07:25:35 +0900
> To: log4j-user@logging.apache.org
> 
> Perhaps the simplest thing to do is to add the packages attribute to your 
> log4j2.xml configuration file. Set the value to the package of your custom 
> plugin. 
> 
> 
> ...
> 
> Remko
> 
> Sent from my iPhone
> 
> > On 2015/08/28, at 6:42, Nicholas Duane  wrote:
> > 
> > 
> > 
> > 
> > I don't think the implementation is the issue, though if/when I get my 
> > plugin loading and it doesn't work I will certainly try to compare against 
> > what Gary wrote.  Right now I'm just trying to figure out how to get my 
> > plugin loaded.  I've got my class file, LevelRangeFilter.java which I 
> > compiled to a .class file.  It resides in the same directory as my 
> > HelloWorld.class file which contains my "main".  I was hoping my plugin 
> > would get loaded but it doesn't seem to be.  What's the easiest way for me 
> > to get it loaded?  Right now when I run my program I'm seeing the following 
> > error from log4net:
> > 
> > 2015-08-27 15:23:09,682 ERROR File contains an invalid element or attribute 
> > "LevelRangeFilter"
> > 
> > Here is my config:
> > 
> > 
> > 
> >  
> >
> >
> >  
> >  
> >
> >  
> >%d %p %c{1.} [%t] %m%n
> >  
> >  
> >
> >  
> >  
> >
> >  
> >
> >
> >
> >  
> > 
> > 
> > Thanks,
> > Nick
> > 
> >> Subject: Re: plugins
> >> From: ralph.go...@dslextreme.com
> >> Date: Thu, 27 Aug 2015 14:20:28 -0700
> >> To: log4j-user@logging.apache.org
> >> 
> >> Can’t you just compare what you wrote to what Gary wrote?  If you build 
> >> your project then it should get packaged in a jar and automatically have 
> >> the file Log4j uses to quickly load the plugin.
> >> 
> >> Ralph
> >> 
> >>> On Aug 27, 2015, at 12:50 PM, Nicholas Duane  wrote:
> >>> 
> >>> Based on your previous comments I assume one would show up out-of-the-box 
> >>> at some point.  Of course I need mine now so unfortunately I have to 
> >>> write one.
> >>> 
> >>> Any input on my questions below?
> >>> 
> >>> Thanks,
> >>> Nick
> >>> 
> >>>> Date: Thu, 27 Aug 2015 12:20:07 -0700
> >>>> Subject: Re: plugins
> >>>> From: garydgreg...@gmail.com
> >>>> To: log4j-user@logging.apache.org
> >>>> 
> >>>> Note that I wrote such a filter, which is under review ATM here:
> >>>> 
> >>>> - https://issues.apache.org/jira/browse/LOG4J2-1106
> >>>> - https://issues.apache.org/jira/browse/LOG4J2-1105
> >>>> 
> >>>> Gary
> >>>> 
> >>>>> On Thu, Aug 27, 2015 at 11:51 AM, Nicholas Duane  wrote:
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> 
> >>>>> I've got a couple questions regarding plugins I'm hoping someone might 
> >>>>> be
> >>>>> able to help me with.  I checked the docs and it's still not quite 
> >>>>> clear.
> >>>>> 
> >>>>> 1. I'm unsure what to set printObject to in my Plugin annotation.  From
> >>>>> http://logging.apache.org/log4j/2.x/manual/extending.html it says:
> >>>>> 
> >>>>> "Specifying the printObject attribute with a value of "true" indicates
> >>>>> that a call to toString will format the arguments to the filter as the
> >>>>> configuration is being processed."
> >>>>> 
> >>>>> which unfortunately doesn't clear things up any.  I looked at the docs 
> >>>>> for
> >>>>> printObject and that doesn't say anything other than it's a Boolean and 
> >>>>> its
> >>>>> default is false.
> >>>>> 
> >>>>> 2. I created a LevelRangeFiler and I'm trying to figure out how to

Re: plugins

2015-08-27 Thread Remko Popma
Perhaps the simplest thing to do is to add the packages attribute to your 
log4j2.xml configuration file. Set the value to the package of your custom 
plugin. 


...

Remko

Sent from my iPhone

> On 2015/08/28, at 6:42, Nicholas Duane  wrote:
> 
> 
> 
> 
> I don't think the implementation is the issue, though if/when I get my plugin 
> loading and it doesn't work I will certainly try to compare against what Gary 
> wrote.  Right now I'm just trying to figure out how to get my plugin loaded.  
> I've got my class file, LevelRangeFilter.java which I compiled to a .class 
> file.  It resides in the same directory as my HelloWorld.class file which 
> contains my "main".  I was hoping my plugin would get loaded but it doesn't 
> seem to be.  What's the easiest way for me to get it loaded?  Right now when 
> I run my program I'm seeing the following error from log4net:
> 
> 2015-08-27 15:23:09,682 ERROR File contains an invalid element or attribute 
> "LevelRangeFilter"
> 
> Here is my config:
> 
> 
> 
>  
>
>
>  
>  
>
>      
>%d %p %c{1.} [%t] %m%n
>  
>  
>
>  
>  
>
>  
>
>
>
>  
> 
> 
> Thanks,
> Nick
> 
>> Subject: Re: plugins
>> From: ralph.go...@dslextreme.com
>> Date: Thu, 27 Aug 2015 14:20:28 -0700
>> To: log4j-user@logging.apache.org
>> 
>> Can’t you just compare what you wrote to what Gary wrote?  If you build your 
>> project then it should get packaged in a jar and automatically have the file 
>> Log4j uses to quickly load the plugin.
>> 
>> Ralph
>> 
>>> On Aug 27, 2015, at 12:50 PM, Nicholas Duane  wrote:
>>> 
>>> Based on your previous comments I assume one would show up out-of-the-box 
>>> at some point.  Of course I need mine now so unfortunately I have to write 
>>> one.
>>> 
>>> Any input on my questions below?
>>> 
>>> Thanks,
>>> Nick
>>> 
>>>> Date: Thu, 27 Aug 2015 12:20:07 -0700
>>>> Subject: Re: plugins
>>>> From: garydgreg...@gmail.com
>>>> To: log4j-user@logging.apache.org
>>>> 
>>>> Note that I wrote such a filter, which is under review ATM here:
>>>> 
>>>> - https://issues.apache.org/jira/browse/LOG4J2-1106
>>>> - https://issues.apache.org/jira/browse/LOG4J2-1105
>>>> 
>>>> Gary
>>>> 
>>>>> On Thu, Aug 27, 2015 at 11:51 AM, Nicholas Duane  wrote:
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> I've got a couple questions regarding plugins I'm hoping someone might be
>>>>> able to help me with.  I checked the docs and it's still not quite clear.
>>>>> 
>>>>> 1. I'm unsure what to set printObject to in my Plugin annotation.  From
>>>>> http://logging.apache.org/log4j/2.x/manual/extending.html it says:
>>>>> 
>>>>> "Specifying the printObject attribute with a value of "true" indicates
>>>>> that a call to toString will format the arguments to the filter as the
>>>>> configuration is being processed."
>>>>> 
>>>>> which unfortunately doesn't clear things up any.  I looked at the docs for
>>>>> printObject and that doesn't say anything other than it's a Boolean and 
>>>>> its
>>>>> default is false.
>>>>> 
>>>>> 2. I created a LevelRangeFiler and I'm trying to figure out how to get it
>>>>> loaded by log4j.  I read over the instructions on plugins located at
>>>>> http://logging.apache.org/log4j/2.x/manual/plugins.html but since I'm a
>>>>> java noob I'm still a bit lost.  I'm wondering, if I just have a .java
>>>>> class which I compile to a .class file, can that be used?  If so, how?
>>>>> 
>>>>> Below is the filter I wrote based on looking at the threshold filter
>>>>> example at http://logging.apache.org/log4j/2.x/manual/extending.html.
>>>>> 
>>>>> import org.apache.logging.log4j.core.filter.AbstractFilter;
>>>>> import org.apache.logging.log4j.core.Filter;
>>>>> import org.apache.logging.log4j.core.config.plugins.Plugin;
>>>>> import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>>>>> import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>>>>

RE: plugins

2015-08-27 Thread Nicholas Duane



I don't think the implementation is the issue, though if/when I get my plugin 
loading and it doesn't work I will certainly try to compare against what Gary 
wrote.  Right now I'm just trying to figure out how to get my plugin loaded.  
I've got my class file, LevelRangeFilter.java which I compiled to a .class 
file.  It resides in the same directory as my HelloWorld.class file which 
contains my "main".  I was hoping my plugin would get loaded but it doesn't 
seem to be.  What's the easiest way for me to get it loaded?  Right now when I 
run my program I'm seeing the following error from log4net:
 
2015-08-27 15:23:09,682 ERROR File contains an invalid element or attribute 
"LevelRangeFilter"

Here is my config:



  


  
  

  
%d %p %c{1.} [%t] %m%n
  
  

  
  
    
  
    


  


Thanks,
Nick
 
> Subject: Re: plugins
> From: ralph.go...@dslextreme.com
> Date: Thu, 27 Aug 2015 14:20:28 -0700
> To: log4j-user@logging.apache.org
> 
> Can’t you just compare what you wrote to what Gary wrote?  If you build your 
> project then it should get packaged in a jar and automatically have the file 
> Log4j uses to quickly load the plugin.
> 
> Ralph
> 
> > On Aug 27, 2015, at 12:50 PM, Nicholas Duane  wrote:
> > 
> > Based on your previous comments I assume one would show up out-of-the-box 
> > at some point.  Of course I need mine now so unfortunately I have to write 
> > one.
> > 
> > Any input on my questions below?
> > 
> > Thanks,
> > Nick
> > 
> >> Date: Thu, 27 Aug 2015 12:20:07 -0700
> >> Subject: Re: plugins
> >> From: garydgreg...@gmail.com
> >> To: log4j-user@logging.apache.org
> >> 
> >> Note that I wrote such a filter, which is under review ATM here:
> >> 
> >> - https://issues.apache.org/jira/browse/LOG4J2-1106
> >> - https://issues.apache.org/jira/browse/LOG4J2-1105
> >> 
> >> Gary
> >> 
> >> On Thu, Aug 27, 2015 at 11:51 AM, Nicholas Duane  wrote:
> >> 
> >>> 
> >>> 
> >>> 
> >>> I've got a couple questions regarding plugins I'm hoping someone might be
> >>> able to help me with.  I checked the docs and it's still not quite clear.
> >>> 
> >>> 1. I'm unsure what to set printObject to in my Plugin annotation.  From
> >>> http://logging.apache.org/log4j/2.x/manual/extending.html it says:
> >>> 
> >>> "Specifying the printObject attribute with a value of "true" indicates
> >>> that a call to toString will format the arguments to the filter as the
> >>> configuration is being processed."
> >>> 
> >>> which unfortunately doesn't clear things up any.  I looked at the docs for
> >>> printObject and that doesn't say anything other than it's a Boolean and 
> >>> its
> >>> default is false.
> >>> 
> >>> 2. I created a LevelRangeFiler and I'm trying to figure out how to get it
> >>> loaded by log4j.  I read over the instructions on plugins located at
> >>> http://logging.apache.org/log4j/2.x/manual/plugins.html but since I'm a
> >>> java noob I'm still a bit lost.  I'm wondering, if I just have a .java
> >>> class which I compile to a .class file, can that be used?  If so, how?
> >>> 
> >>> Below is the filter I wrote based on looking at the threshold filter
> >>> example at http://logging.apache.org/log4j/2.x/manual/extending.html.
> >>> 
> >>> import org.apache.logging.log4j.core.filter.AbstractFilter;
> >>> import org.apache.logging.log4j.core.Filter;
> >>> import org.apache.logging.log4j.core.config.plugins.Plugin;
> >>> import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
> >>> import org.apache.logging.log4j.core.config.plugins.PluginFactory;
> >>> import org.apache.logging.log4j.Level;
> >>> import org.apache.logging.log4j.core.LogEvent;
> >>> import org.apache.logging.log4j.core.Logger;
> >>> import org.apache.logging.log4j.Marker;
> >>> import org.apache.logging.log4j.message.Message;
> >>> 
> >>> @Plugin(name="LevelRangeFilter", category="Core", elementType="filter",
> >>>printObject=true)
> >>> public class LevelRangeFilter extends AbstractFilter
> >>> {
> >>>private final Level minLevel;
> >>>private final Leve

Re: plugins

2015-08-27 Thread Ralph Goers
Can’t you just compare what you wrote to what Gary wrote?  If you build your 
project then it should get packaged in a jar and automatically have the file 
Log4j uses to quickly load the plugin.

Ralph

> On Aug 27, 2015, at 12:50 PM, Nicholas Duane  wrote:
> 
> Based on your previous comments I assume one would show up out-of-the-box at 
> some point.  Of course I need mine now so unfortunately I have to write one.
> 
> Any input on my questions below?
> 
> Thanks,
> Nick
> 
>> Date: Thu, 27 Aug 2015 12:20:07 -0700
>> Subject: Re: plugins
>> From: garydgreg...@gmail.com
>> To: log4j-user@logging.apache.org
>> 
>> Note that I wrote such a filter, which is under review ATM here:
>> 
>> - https://issues.apache.org/jira/browse/LOG4J2-1106
>> - https://issues.apache.org/jira/browse/LOG4J2-1105
>> 
>> Gary
>> 
>> On Thu, Aug 27, 2015 at 11:51 AM, Nicholas Duane  wrote:
>> 
>>> 
>>> 
>>> 
>>> I've got a couple questions regarding plugins I'm hoping someone might be
>>> able to help me with.  I checked the docs and it's still not quite clear.
>>> 
>>> 1. I'm unsure what to set printObject to in my Plugin annotation.  From
>>> http://logging.apache.org/log4j/2.x/manual/extending.html it says:
>>> 
>>> "Specifying the printObject attribute with a value of "true" indicates
>>> that a call to toString will format the arguments to the filter as the
>>> configuration is being processed."
>>> 
>>> which unfortunately doesn't clear things up any.  I looked at the docs for
>>> printObject and that doesn't say anything other than it's a Boolean and its
>>> default is false.
>>> 
>>> 2. I created a LevelRangeFiler and I'm trying to figure out how to get it
>>> loaded by log4j.  I read over the instructions on plugins located at
>>> http://logging.apache.org/log4j/2.x/manual/plugins.html but since I'm a
>>> java noob I'm still a bit lost.  I'm wondering, if I just have a .java
>>> class which I compile to a .class file, can that be used?  If so, how?
>>> 
>>> Below is the filter I wrote based on looking at the threshold filter
>>> example at http://logging.apache.org/log4j/2.x/manual/extending.html.
>>> 
>>> import org.apache.logging.log4j.core.filter.AbstractFilter;
>>> import org.apache.logging.log4j.core.Filter;
>>> import org.apache.logging.log4j.core.config.plugins.Plugin;
>>> import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>>> import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>>> import org.apache.logging.log4j.Level;
>>> import org.apache.logging.log4j.core.LogEvent;
>>> import org.apache.logging.log4j.core.Logger;
>>> import org.apache.logging.log4j.Marker;
>>> import org.apache.logging.log4j.message.Message;
>>> 
>>> @Plugin(name="LevelRangeFilter", category="Core", elementType="filter",
>>>printObject=true)
>>> public class LevelRangeFilter extends AbstractFilter
>>> {
>>>private final Level minLevel;
>>>private final Level maxLevel;
>>> 
>>>public LevelRangeFilter(Level minLevel, Level maxLevel,
>>>Filter.Result onMatch, Filter.Result onMismatch)
>>>{
>>>super(onMatch, onMismatch);
>>>this.minLevel = minLevel;
>>>this.maxLevel = maxLevel;
>>>}
>>> 
>>>private Result filter(Level level)
>>>{
>>>if (level.isMoreSpecificThan(this.minLevel) &&
>>>level.isLessSpecificThan(this.maxLevel))
>>>{
>>>return this.onMatch;
>>>}
>>>return this.onMismatch;
>>>}
>>> 
>>>public Filter.Result filter(Logger logger, Level level,
>>>Marker marker, String msg, Object[] params)
>>>{
>>>return filter(level);
>>>}
>>> 
>>>public Filter.Result filter(Logger logger, Level level,
>>>Marker marker, Object msg, Throwable t)
>>>{
>>>return filter(level);
>>>}
>>> 
>>>public Filter.Result filter(Logger logger, Level level,
>>>Marker marker, Message msg, Throwable t)
>>>{
>>>return filter(level);
>>>}
>>> 
>>>public Filter.Result filter(LogEvent event)
>>>{
>

RE: plugins

2015-08-27 Thread Nicholas Duane
Based on your previous comments I assume one would show up out-of-the-box at 
some point.  Of course I need mine now so unfortunately I have to write one.
 
Any input on my questions below?
 
Thanks,
Nick
 
> Date: Thu, 27 Aug 2015 12:20:07 -0700
> Subject: Re: plugins
> From: garydgreg...@gmail.com
> To: log4j-user@logging.apache.org
> 
> Note that I wrote such a filter, which is under review ATM here:
> 
> - https://issues.apache.org/jira/browse/LOG4J2-1106
> - https://issues.apache.org/jira/browse/LOG4J2-1105
> 
> Gary
> 
> On Thu, Aug 27, 2015 at 11:51 AM, Nicholas Duane  wrote:
> 
> >
> >
> >
> > I've got a couple questions regarding plugins I'm hoping someone might be
> > able to help me with.  I checked the docs and it's still not quite clear.
> >
> > 1. I'm unsure what to set printObject to in my Plugin annotation.  From
> > http://logging.apache.org/log4j/2.x/manual/extending.html it says:
> >
> > "Specifying the printObject attribute with a value of "true" indicates
> > that a call to toString will format the arguments to the filter as the
> > configuration is being processed."
> >
> > which unfortunately doesn't clear things up any.  I looked at the docs for
> > printObject and that doesn't say anything other than it's a Boolean and its
> > default is false.
> >
> > 2. I created a LevelRangeFiler and I'm trying to figure out how to get it
> > loaded by log4j.  I read over the instructions on plugins located at
> > http://logging.apache.org/log4j/2.x/manual/plugins.html but since I'm a
> > java noob I'm still a bit lost.  I'm wondering, if I just have a .java
> > class which I compile to a .class file, can that be used?  If so, how?
> >
> > Below is the filter I wrote based on looking at the threshold filter
> > example at http://logging.apache.org/log4j/2.x/manual/extending.html.
> >
> > import org.apache.logging.log4j.core.filter.AbstractFilter;
> > import org.apache.logging.log4j.core.Filter;
> > import org.apache.logging.log4j.core.config.plugins.Plugin;
> > import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
> > import org.apache.logging.log4j.core.config.plugins.PluginFactory;
> > import org.apache.logging.log4j.Level;
> > import org.apache.logging.log4j.core.LogEvent;
> > import org.apache.logging.log4j.core.Logger;
> > import org.apache.logging.log4j.Marker;
> > import org.apache.logging.log4j.message.Message;
> >
> > @Plugin(name="LevelRangeFilter", category="Core", elementType="filter",
> > printObject=true)
> > public class LevelRangeFilter extends AbstractFilter
> > {
> > private final Level minLevel;
> > private final Level maxLevel;
> >
> > public LevelRangeFilter(Level minLevel, Level maxLevel,
> > Filter.Result onMatch, Filter.Result onMismatch)
> > {
> > super(onMatch, onMismatch);
> > this.minLevel = minLevel;
> > this.maxLevel = maxLevel;
> > }
> >
> > private Result filter(Level level)
> > {
> > if (level.isMoreSpecificThan(this.minLevel) &&
> > level.isLessSpecificThan(this.maxLevel))
> > {
> > return this.onMatch;
> > }
> > return this.onMismatch;
> > }
> >
> > public Filter.Result filter(Logger logger, Level level,
> > Marker marker, String msg, Object[] params)
> > {
> > return filter(level);
> > }
> >
> > public Filter.Result filter(Logger logger, Level level,
> > Marker marker, Object msg, Throwable t)
> > {
> > return filter(level);
> > }
> >
> > public Filter.Result filter(Logger logger, Level level,
> > Marker marker, Message msg, Throwable t)
> > {
> > return filter(level);
> > }
> >
> > public Filter.Result filter(LogEvent event)
> > {
> > return filter(event.getLevel());
> > }
> >
> > @PluginFactory
> > public static LevelRangeFilter createFilter(
> > @PluginAttribute(value="minLevel",
> > defaultString="DEBUG") Level minLevel,
> > @PluginAttribute(value="maxLevel",
> > defaultString="FATAL") Level maxLevel,
> > @PluginAttribute(value="onMatch",
> > defaultString="NEUTRAL") Result onMatch,
> > @PluginAttribute(value="onMismatch",
> > defaultString="DENY") Result onMismatch)
> > {
> > return new LevelRangeFilter(minLevel, maxLevel, onMatch, onMismatch);
> > }
> > }
> >
> > Thanks,
> > Nick
> >
> >
> >
> 
> 
> 
> 
> -- 
> E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
  

Re: plugins

2015-08-27 Thread Gary Gregory
Note that I wrote such a filter, which is under review ATM here:

- https://issues.apache.org/jira/browse/LOG4J2-1106
- https://issues.apache.org/jira/browse/LOG4J2-1105

Gary

On Thu, Aug 27, 2015 at 11:51 AM, Nicholas Duane  wrote:

>
>
>
> I've got a couple questions regarding plugins I'm hoping someone might be
> able to help me with.  I checked the docs and it's still not quite clear.
>
> 1. I'm unsure what to set printObject to in my Plugin annotation.  From
> http://logging.apache.org/log4j/2.x/manual/extending.html it says:
>
> "Specifying the printObject attribute with a value of "true" indicates
> that a call to toString will format the arguments to the filter as the
> configuration is being processed."
>
> which unfortunately doesn't clear things up any.  I looked at the docs for
> printObject and that doesn't say anything other than it's a Boolean and its
> default is false.
>
> 2. I created a LevelRangeFiler and I'm trying to figure out how to get it
> loaded by log4j.  I read over the instructions on plugins located at
> http://logging.apache.org/log4j/2.x/manual/plugins.html but since I'm a
> java noob I'm still a bit lost.  I'm wondering, if I just have a .java
> class which I compile to a .class file, can that be used?  If so, how?
>
> Below is the filter I wrote based on looking at the threshold filter
> example at http://logging.apache.org/log4j/2.x/manual/extending.html.
>
> import org.apache.logging.log4j.core.filter.AbstractFilter;
> import org.apache.logging.log4j.core.Filter;
> import org.apache.logging.log4j.core.config.plugins.Plugin;
> import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
> import org.apache.logging.log4j.core.config.plugins.PluginFactory;
> import org.apache.logging.log4j.Level;
> import org.apache.logging.log4j.core.LogEvent;
> import org.apache.logging.log4j.core.Logger;
> import org.apache.logging.log4j.Marker;
> import org.apache.logging.log4j.message.Message;
>
> @Plugin(name="LevelRangeFilter", category="Core", elementType="filter",
> printObject=true)
> public class LevelRangeFilter extends AbstractFilter
> {
> private final Level minLevel;
> private final Level maxLevel;
>
> public LevelRangeFilter(Level minLevel, Level maxLevel,
> Filter.Result onMatch, Filter.Result onMismatch)
> {
> super(onMatch, onMismatch);
> this.minLevel = minLevel;
> this.maxLevel = maxLevel;
> }
>
> private Result filter(Level level)
> {
> if (level.isMoreSpecificThan(this.minLevel) &&
> level.isLessSpecificThan(this.maxLevel))
> {
> return this.onMatch;
> }
> return this.onMismatch;
> }
>
> public Filter.Result filter(Logger logger, Level level,
> Marker marker, String msg, Object[] params)
> {
> return filter(level);
> }
>
> public Filter.Result filter(Logger logger, Level level,
> Marker marker, Object msg, Throwable t)
> {
> return filter(level);
> }
>
> public Filter.Result filter(Logger logger, Level level,
> Marker marker, Message msg, Throwable t)
> {
> return filter(level);
> }
>
> public Filter.Result filter(LogEvent event)
> {
> return filter(event.getLevel());
> }
>
> @PluginFactory
> public static LevelRangeFilter createFilter(
> @PluginAttribute(value="minLevel",
> defaultString="DEBUG") Level minLevel,
> @PluginAttribute(value="maxLevel",
> defaultString="FATAL") Level maxLevel,
> @PluginAttribute(value="onMatch",
> defaultString="NEUTRAL") Result onMatch,
> @PluginAttribute(value="onMismatch",
> defaultString="DENY") Result onMismatch)
> {
> return new LevelRangeFilter(minLevel, maxLevel, onMatch, onMismatch);
> }
> }
>
> Thanks,
> Nick
>
>
>




-- 
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