You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by David Nault <da...@criticalpath.net> on 2013/08/17 00:21:35 UTC
BaseConfiguration ignores custom "Lookup" plugins?
Hi All,
We're using Log4j in a webapp and are looking at migrating to Log4j 2.
We'd like to continue writing our log files to a location under the webapp's context root -- that is, under the directory returned by ServletContext.getRealPath("/"). This works very well in our QA environment where multiple versions of the webapp are deployed to a single Tomcat server.
I've written a Lookup plugin that maps "${web:rootDir}" to the desired path. The problem is that the plugin is ignored when parsing the config file, specifically the "filename" attribute of a "File" appender. The BaseConfiguration object seems to be using a StrSubstitutor with a default Interpolator that only knows about the "sys" and "env" prefixes.
For what it's worth, the custom Lookup plugin works fine when used in a pattern layout string.
Any thoughts on how to get the BaseConfiguration to use a custom Lookup plugin, or alternate ways to get the log files to appear under the webapp root? System properties aren't the solution since they are shared between webapps and we'd rather not return to the bad old days of using a different property for each webapp.
Log4j 2 beta 8.
Thanks,
David
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: BaseConfiguration ignores custom "Lookup" plugins?
Posted by David Nault <da...@criticalpath.net>.
On Aug 16, 2013, at 4:55 PM, Gary Gregory <ga...@gmail.com> wrote:
> On Fri, Aug 16, 2013 at 7:54 PM, Gary Gregory <ga...@gmail.com>wrote:
>
>> On Fri, Aug 16, 2013 at 6:21 PM, David Nault <david.nault@criticalpath.net
>>> wrote:
>>
>>> Hi All,
>>>
>>> We're using Log4j in a webapp and are looking at migrating to Log4j 2.
>>>
>>> We'd like to continue writing our log files to a location under the
>>> webapp's context root -- that is, under the directory returned by
>>> ServletContext.getRealPath("/"). This works very well in our QA environment
>>> where multiple versions of the webapp are deployed to a single Tomcat
>>> server.
>>>
>>> I've written a Lookup plugin that maps "${web:rootDir}" to the desired
>>> path. The problem is that the plugin is ignored when parsing the config
>>> file, specifically the "filename" attribute of a "File" appender. The
>>> BaseConfiguration object seems to be using a StrSubstitutor with a default
>>> Interpolator that only knows about the "sys" and "env" prefixes.
>>>
>>> For what it's worth, the custom Lookup plugin works fine when used in a
>>> pattern layout string.
>>>
>>> Any thoughts on how to get the BaseConfiguration to use a custom Lookup
>>> plugin, or alternate ways to get the log files to appear under the webapp
>>> root? System properties aren't the solution since they are shared between
>>> webapps and we'd rather not return to the bad old days of using a different
>>> property for each webapp.
>>>
>>> Log4j 2 beta 8.
>>>
>>>
>> Any config item that is annotated with Log4j annotations has to be part of
>> Log4J's config dat file. I'm not not 100% sure, but I think you might have
>> to regenerate Log4J's config dat file. There might be a way to scan the CP
>> for additional code to scan...
>>
>
> Also: This might be a nice add-on to Log4j if you're willing to contribute
> it ;)
>
> Gary
>
Thanks Gary. I've filed LOG4J2-364 and contributed what I've got so far.
Regarding scanning the class path for plugins, I thought I had taken care of this by executing the following line in a ServletContextListener that runs before Log4j:
PluginManager.addPackage(WebLookup.class.getPackage().getName());
This doesn't seem to have an effect though, since BaseConfiguration doesn't use the PluginManager to create it's initial list of Lookup implementations.
Thanks,
David
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: BaseConfiguration ignores custom "Lookup" plugins?
Posted by Gary Gregory <ga...@gmail.com>.
On Fri, Aug 16, 2013 at 7:54 PM, Gary Gregory <ga...@gmail.com>wrote:
> On Fri, Aug 16, 2013 at 6:21 PM, David Nault <david.nault@criticalpath.net
> > wrote:
>
>> Hi All,
>>
>> We're using Log4j in a webapp and are looking at migrating to Log4j 2.
>>
>> We'd like to continue writing our log files to a location under the
>> webapp's context root -- that is, under the directory returned by
>> ServletContext.getRealPath("/"). This works very well in our QA environment
>> where multiple versions of the webapp are deployed to a single Tomcat
>> server.
>>
>> I've written a Lookup plugin that maps "${web:rootDir}" to the desired
>> path. The problem is that the plugin is ignored when parsing the config
>> file, specifically the "filename" attribute of a "File" appender. The
>> BaseConfiguration object seems to be using a StrSubstitutor with a default
>> Interpolator that only knows about the "sys" and "env" prefixes.
>>
>> For what it's worth, the custom Lookup plugin works fine when used in a
>> pattern layout string.
>>
>> Any thoughts on how to get the BaseConfiguration to use a custom Lookup
>> plugin, or alternate ways to get the log files to appear under the webapp
>> root? System properties aren't the solution since they are shared between
>> webapps and we'd rather not return to the bad old days of using a different
>> property for each webapp.
>>
>> Log4j 2 beta 8.
>>
>>
> Any config item that is annotated with Log4j annotations has to be part of
> Log4J's config dat file. I'm not not 100% sure, but I think you might have
> to regenerate Log4J's config dat file. There might be a way to scan the CP
> for additional code to scan...
>
Also: This might be a nice add-on to Log4j if you're willing to contribute
it ;)
Gary
>
> Gary
>
>
> Thanks,
>> David
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@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
>
--
E-Mail: garydgregory@gmail.com | ggregory@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: BaseConfiguration ignores custom "Lookup" plugins?
Posted by Gary Gregory <ga...@gmail.com>.
On Fri, Aug 16, 2013 at 6:21 PM, David Nault
<da...@criticalpath.net>wrote:
> Hi All,
>
> We're using Log4j in a webapp and are looking at migrating to Log4j 2.
>
> We'd like to continue writing our log files to a location under the
> webapp's context root -- that is, under the directory returned by
> ServletContext.getRealPath("/"). This works very well in our QA environment
> where multiple versions of the webapp are deployed to a single Tomcat
> server.
>
> I've written a Lookup plugin that maps "${web:rootDir}" to the desired
> path. The problem is that the plugin is ignored when parsing the config
> file, specifically the "filename" attribute of a "File" appender. The
> BaseConfiguration object seems to be using a StrSubstitutor with a default
> Interpolator that only knows about the "sys" and "env" prefixes.
>
> For what it's worth, the custom Lookup plugin works fine when used in a
> pattern layout string.
>
> Any thoughts on how to get the BaseConfiguration to use a custom Lookup
> plugin, or alternate ways to get the log files to appear under the webapp
> root? System properties aren't the solution since they are shared between
> webapps and we'd rather not return to the bad old days of using a different
> property for each webapp.
>
> Log4j 2 beta 8.
>
>
Any config item that is annotated with Log4j annotations has to be part of
Log4J's config dat file. I'm not not 100% sure, but I think you might have
to regenerate Log4J's config dat file. There might be a way to scan the CP
for additional code to scan...
Gary
Thanks,
> David
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
--
E-Mail: garydgregory@gmail.com | ggregory@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: BaseConfiguration ignores custom "Lookup" plugins?
Posted by Ralph Goers <ra...@dslextreme.com>.
I've had experiences where the ClassLoader used in the ServletContextListener isn't the same as the ClassLoader the application uses. If that is the case then the behavior you are seeing will occur. Unfortunately, this seems to vary from one container to another.
Ralph
On Aug 19, 2013, at 1:07 PM, David Nault wrote:
> Thanks Ralph. I've filed LOG4J2-364 and attached a draft of the WebLookup plugin for you to evaluate.
>
> I wonder why BaseConfiguration doesn't use the PluginManager when building its initial set of Lookups? I was expecting that to work in conjunction with a call to PluginManager.addPackage(String) prior to Log4J initialization.
>
> Thanks,
> David
>
>
> On Aug 16, 2013, at 5:33 PM, Ralph Goers <ra...@dslextreme.com> wrote:
>
>> The BaseConfiguration has an initial set of Lookups that are hardwired so that some variable substitution is possible on the attributes on the Configuration element. Until the packages attribute is handled custom lookups won't be found. Your custom Lookups should work for other elements in the configuration. I'd like to see your Lookup to see if it could be included as one of the hard-wired plugins.
>>
>> Ralph
>>
>> On Aug 16, 2013, at 3:21 PM, David Nault wrote:
>>
>>> Hi All,
>>>
>>> We're using Log4j in a webapp and are looking at migrating to Log4j 2.
>>>
>>> We'd like to continue writing our log files to a location under the webapp's context root -- that is, under the directory returned by ServletContext.getRealPath("/"). This works very well in our QA environment where multiple versions of the webapp are deployed to a single Tomcat server.
>>>
>>> I've written a Lookup plugin that maps "${web:rootDir}" to the desired path. The problem is that the plugin is ignored when parsing the config file, specifically the "filename" attribute of a "File" appender. The BaseConfiguration object seems to be using a StrSubstitutor with a default Interpolator that only knows about the "sys" and "env" prefixes.
>>>
>>> For what it's worth, the custom Lookup plugin works fine when used in a pattern layout string.
>>>
>>> Any thoughts on how to get the BaseConfiguration to use a custom Lookup plugin, or alternate ways to get the log files to appear under the webapp root? System properties aren't the solution since they are shared between webapps and we'd rather not return to the bad old days of using a different property for each webapp.
>>>
>>> Log4j 2 beta 8.
>>>
>>> Thanks,
>>> David
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: BaseConfiguration ignores custom "Lookup" plugins?
Posted by David Nault <da...@criticalpath.net>.
Thanks Ralph. I've filed LOG4J2-364 and attached a draft of the WebLookup plugin for you to evaluate.
I wonder why BaseConfiguration doesn't use the PluginManager when building its initial set of Lookups? I was expecting that to work in conjunction with a call to PluginManager.addPackage(String) prior to Log4J initialization.
Thanks,
David
On Aug 16, 2013, at 5:33 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> The BaseConfiguration has an initial set of Lookups that are hardwired so that some variable substitution is possible on the attributes on the Configuration element. Until the packages attribute is handled custom lookups won't be found. Your custom Lookups should work for other elements in the configuration. I'd like to see your Lookup to see if it could be included as one of the hard-wired plugins.
>
> Ralph
>
> On Aug 16, 2013, at 3:21 PM, David Nault wrote:
>
>> Hi All,
>>
>> We're using Log4j in a webapp and are looking at migrating to Log4j 2.
>>
>> We'd like to continue writing our log files to a location under the webapp's context root -- that is, under the directory returned by ServletContext.getRealPath("/"). This works very well in our QA environment where multiple versions of the webapp are deployed to a single Tomcat server.
>>
>> I've written a Lookup plugin that maps "${web:rootDir}" to the desired path. The problem is that the plugin is ignored when parsing the config file, specifically the "filename" attribute of a "File" appender. The BaseConfiguration object seems to be using a StrSubstitutor with a default Interpolator that only knows about the "sys" and "env" prefixes.
>>
>> For what it's worth, the custom Lookup plugin works fine when used in a pattern layout string.
>>
>> Any thoughts on how to get the BaseConfiguration to use a custom Lookup plugin, or alternate ways to get the log files to appear under the webapp root? System properties aren't the solution since they are shared between webapps and we'd rather not return to the bad old days of using a different property for each webapp.
>>
>> Log4j 2 beta 8.
>>
>> Thanks,
>> David
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: BaseConfiguration ignores custom "Lookup" plugins?
Posted by Ralph Goers <ra...@dslextreme.com>.
The BaseConfiguration has an initial set of Lookups that are hardwired so that some variable substitution is possible on the attributes on the Configuration element. Until the packages attribute is handled custom lookups won't be found. Your custom Lookups should work for other elements in the configuration. I'd like to see your Lookup to see if it could be included as one of the hard-wired plugins.
Ralph
On Aug 16, 2013, at 3:21 PM, David Nault wrote:
> Hi All,
>
> We're using Log4j in a webapp and are looking at migrating to Log4j 2.
>
> We'd like to continue writing our log files to a location under the webapp's context root -- that is, under the directory returned by ServletContext.getRealPath("/"). This works very well in our QA environment where multiple versions of the webapp are deployed to a single Tomcat server.
>
> I've written a Lookup plugin that maps "${web:rootDir}" to the desired path. The problem is that the plugin is ignored when parsing the config file, specifically the "filename" attribute of a "File" appender. The BaseConfiguration object seems to be using a StrSubstitutor with a default Interpolator that only knows about the "sys" and "env" prefixes.
>
> For what it's worth, the custom Lookup plugin works fine when used in a pattern layout string.
>
> Any thoughts on how to get the BaseConfiguration to use a custom Lookup plugin, or alternate ways to get the log files to appear under the webapp root? System properties aren't the solution since they are shared between webapps and we'd rather not return to the bad old days of using a different property for each webapp.
>
> Log4j 2 beta 8.
>
> Thanks,
> David
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org