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 John Lussmyer <Co...@CasaDelGato.com> on 2015/12/21 19:16:28 UTC

Trigger RollingRandomAccessFile appender programmtically?

I have a place in my program where I would like to cause my logger to roll to the next log file.
Basically, a "TriggerNow" triggering policy.
Is there any reasonably easy way to do this?

--
Tigers prowl and Dragons soar in my dreams...

Re: Trigger RollingRandomAccessFile appender programmtically?

Posted by John Lussmyer <Co...@CasaDelGato.com>.
And I just did some more checking.
I rebuilt the .jar file by extracting the log4j*.jar files into my .jar.
Now it works.
Apparently the jarinjarloader is causing problems for log4j


On Sat Jan 02 15:58:07 PST 2016 Cougar@CasaDelGato.com said:
>I knew I forgot to include something with that msg.  Here is my log4j.xml - which  already has the packages entry.
>
><?xml version="1.0" encoding="UTF-8"?>
><Configuration status="info" packages="com.casadelgato.zilladash">
><Appenders>
><RollingRandomAccessFile name="Log"
>fileName="${sys:user.home}/ZillaDash/logs/ZillaDash.log"
>filePattern="${sys:user.home}/ZillaDash/logs/ZillaDash-%d{yyyyMMdd-HHmmss}.log">
><PatternLayout pattern="%d{yy/MM/dd HH:mm:ss.SSS} [%20.20t] %-5level %30.30logger - %msg%n" />
><Policies>
><OnStartupTriggeringPolicy />
><ManualTriggeringPolicy />
></Policies>
></RollingRandomAccessFile>
>
></Appenders>
><Loggers>
><Root level="info">
><AppenderRef ref="Log" />
></Root>
></Loggers>
></Configuration>
>
>I've checked, and if the packages entry is wrong, Eclipse also complains about the Policy.
>This makes me wonder if somehow the Eclipse "jarinjarloader" is causing the clas lookup to fail?
>
>On Sat Jan 02 15:52:59 PST 2016 remko.popma@gmail.com said:
>>You can try specifying the package of your custom plugin in the <Configuration packages="com.yourdomain.yourpluginpackage" ...> attribute of your configuration.
>>
>>Sent from my iPhone
>>
>>> On 2016/01/03, at 8:22, John Lussmyer <Co...@CasaDelGato.com> wrote:
>>>
>>> On Mon Dec 21 15:16:14 PST 2015 Cougar@CasaDelGato.com said:
>>>> On Mon Dec 21 14:11:31 PST 2015 ralph.goers@dslextreme.com said:
>>>>> You would define it as a plugin. Look at how the CronTriggeringPolicy does it.
>>>>
>>>> Okay, after re-reading the code, and doing some experiments - I have it working.
>>>> Thanks!
>>>
>>> Well, I THOUGHT I had it working.
>>> It works fine when I run the app from within Eclipse.
>>> I use eclipse to generate a .jar file, then
>>> If I run the jar via "java -jar <jarname>" I get:
>>>
>>> 2016-01-02 15:12:22,205 main ERROR Policies contains an invalid element or attribute "ManualTriggeringPolicy"
>>>
>>> I'm using "log4j-core-2.5.jar" and "log4j-api-2.5.jar"
>>> Both places are using Java 1.8.
>>>
>>> any ideas on where to look?
>>>
>>>
>>> --
>>>
>>> Worlds only All Electric F-250 truck! http://john.casadelgato.com/Electric-Vehicles/1995-Ford-F-250
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>
>--
>
>Try my Sensible Email package!  https://sourceforge.net/projects/sensibleemail/
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org


--

Try my Sensible Email package!  https://sourceforge.net/projects/sensibleemail/

Re: Trigger RollingRandomAccessFile appender programmtically?

Posted by John Lussmyer <Co...@CasaDelGato.com>.
I knew I forgot to include something with that msg.  Here is my log4j.xml - which  already has the packages entry.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info" packages="com.casadelgato.zilladash">
	<Appenders>
		<RollingRandomAccessFile name="Log"
			fileName="${sys:user.home}/ZillaDash/logs/ZillaDash.log"
			filePattern="${sys:user.home}/ZillaDash/logs/ZillaDash-%d{yyyyMMdd-HHmmss}.log">
			<PatternLayout pattern="%d{yy/MM/dd HH:mm:ss.SSS} [%20.20t] %-5level %30.30logger - %msg%n" />
			<Policies>
				<OnStartupTriggeringPolicy />
				<ManualTriggeringPolicy />
			</Policies>
		</RollingRandomAccessFile>

	</Appenders>
	<Loggers>
		<Root level="info">
			<AppenderRef ref="Log" />
		</Root>
	</Loggers>
</Configuration>

I've checked, and if the packages entry is wrong, Eclipse also complains about the Policy.
This makes me wonder if somehow the Eclipse "jarinjarloader" is causing the clas lookup to fail?

On Sat Jan 02 15:52:59 PST 2016 remko.popma@gmail.com said:
>You can try specifying the package of your custom plugin in the <Configuration packages="com.yourdomain.yourpluginpackage" ...> attribute of your configuration.
>
>Sent from my iPhone
>
>> On 2016/01/03, at 8:22, John Lussmyer <Co...@CasaDelGato.com> wrote:
>>
>> On Mon Dec 21 15:16:14 PST 2015 Cougar@CasaDelGato.com said:
>>> On Mon Dec 21 14:11:31 PST 2015 ralph.goers@dslextreme.com said:
>>>> You would define it as a plugin. Look at how the CronTriggeringPolicy does it.
>>>
>>> Okay, after re-reading the code, and doing some experiments - I have it working.
>>> Thanks!
>>
>> Well, I THOUGHT I had it working.
>> It works fine when I run the app from within Eclipse.
>> I use eclipse to generate a .jar file, then
>> If I run the jar via "java -jar <jarname>" I get:
>>
>> 2016-01-02 15:12:22,205 main ERROR Policies contains an invalid element or attribute "ManualTriggeringPolicy"
>>
>> I'm using "log4j-core-2.5.jar" and "log4j-api-2.5.jar"
>> Both places are using Java 1.8.
>>
>> any ideas on where to look?
>>
>>
>> --
>>
>> Worlds only All Electric F-250 truck! http://john.casadelgato.com/Electric-Vehicles/1995-Ford-F-250
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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


--

Try my Sensible Email package!  https://sourceforge.net/projects/sensibleemail/

Re: Trigger RollingRandomAccessFile appender programmtically?

Posted by Remko Popma <re...@gmail.com>.
You can try specifying the package of your custom plugin in the <Configuration packages="com.yourdomain.yourpluginpackage" ...> attribute of your configuration. 

Sent from my iPhone

> On 2016/01/03, at 8:22, John Lussmyer <Co...@CasaDelGato.com> wrote:
> 
> On Mon Dec 21 15:16:14 PST 2015 Cougar@CasaDelGato.com said:
>> On Mon Dec 21 14:11:31 PST 2015 ralph.goers@dslextreme.com said:
>>> You would define it as a plugin. Look at how the CronTriggeringPolicy does it.
>> 
>> Okay, after re-reading the code, and doing some experiments - I have it working.
>> Thanks!
> 
> Well, I THOUGHT I had it working.
> It works fine when I run the app from within Eclipse.
> I use eclipse to generate a .jar file, then
> If I run the jar via "java -jar <jarname>" I get:
> 
> 2016-01-02 15:12:22,205 main ERROR Policies contains an invalid element or attribute "ManualTriggeringPolicy"
> 
> I'm using "log4j-core-2.5.jar" and "log4j-api-2.5.jar"
> Both places are using Java 1.8.
> 
> any ideas on where to look?
> 
> 
> --
> 
> Worlds only All Electric F-250 truck! http://john.casadelgato.com/Electric-Vehicles/1995-Ford-F-250
> 
> 
> 
> ---------------------------------------------------------------------
> 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: Trigger RollingRandomAccessFile appender programmtically?

Posted by John Lussmyer <Co...@CasaDelGato.com>.
On Mon Dec 21 15:16:14 PST 2015 Cougar@CasaDelGato.com said:
>On Mon Dec 21 14:11:31 PST 2015 ralph.goers@dslextreme.com said:
>>You would define it as a plugin. Look at how the CronTriggeringPolicy does it.
>
>Okay, after re-reading the code, and doing some experiments - I have it working.
>Thanks!

Well, I THOUGHT I had it working.
It works fine when I run the app from within Eclipse.
I use eclipse to generate a .jar file, then
If I run the jar via "java -jar <jarname>" I get:

2016-01-02 15:12:22,205 main ERROR Policies contains an invalid element or attribute "ManualTriggeringPolicy"

I'm using "log4j-core-2.5.jar" and "log4j-api-2.5.jar"
Both places are using Java 1.8.

any ideas on where to look?


--

Worlds only All Electric F-250 truck! http://john.casadelgato.com/Electric-Vehicles/1995-Ford-F-250



Re: Trigger RollingRandomAccessFile appender programmtically?

Posted by John Lussmyer <Co...@CasaDelGato.com>.
On Mon Dec 21 14:11:31 PST 2015 ralph.goers@dslextreme.com said:
>You would define it as a plugin. Look at how the CronTriggeringPolicy does it.

Okay, after re-reading the code, and doing some experiments - I have it working.
Thanks!


--

Try my Sensible Email package!  https://sourceforge.net/projects/sensibleemail/

Re: Trigger RollingRandomAccessFile appender programmtically?

Posted by Ralph Goers <ra...@dslextreme.com>.
You would define it as a plugin. Look at how the CronTriggeringPolicy does it.

Ralph

> On Dec 21, 2015, at 2:22 PM, John Lussmyer <Co...@CasaDelGato.com> wrote:
> 
> I can easily write an "OnDemandTriggeringPolicy" class that implements TriggeringPolicy.
> I just don't see how I can get the RollingRandomAccessFile to use it.
> I'd prefer to just put it in my log4j.xml as one of the <Policies>, but I don't see how to configure log4j to allow that.
> 
> On Mon Dec 21 13:05:47 PST 2015 ralph.goers@dslextreme.com said:
>> What do you mean by ?using a custom triggering policy??
>> 
>> Ralph
>> 
>>> On Dec 21, 2015, at 1:47 PM, John Lussmyer <Co...@CasaDelGato.com> wrote:
>>> 
>>> Looking at the TriggeringPolicy interface, writing one that will do what I need would be trivial.
>>> 
>>> The main problem is that I can't find any info on using a custom triggering policy.
>>> 
>>> On Mon Dec 21 10:48:44 PST 2015 ralph.goers@dslextreme.com said:
>>>> Log4j 2.5 added a CronTriggeringPoilicy that triggers a rollover when the specified time pattern matches. You could look at that and create your own triggering policy that triggers on whatever your criteria is.  As an alternative you can locate the Appender in the configuration, obtain its manager and kick off the rollover in your code.
>>> 
>>>>> On Dec 21, 2015, at 11:16 AM, John Lussmyer <Co...@CasaDelGato.com> wrote:
>>>>> 
>>>>> I have a place in my program where I would like to cause my logger to roll to the next log file.
>>>>> Basically, a "TriggerNow" triggering policy.
>>>>> Is there any reasonably easy way to do this?
>>> --
>>> 
>>> Tigers prowl and Dragons soar in my dreams...
>>> 
>>> ---------------------------------------------------------------------
>>> 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
> 
> 
> --
> 
> Tigers prowl and Dragons soar in my dreams...
> 
> ---------------------------------------------------------------------
> 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: Trigger RollingRandomAccessFile appender programmtically?

Posted by John Lussmyer <Co...@CasaDelGato.com>.
I can easily write an "OnDemandTriggeringPolicy" class that implements TriggeringPolicy.
I just don't see how I can get the RollingRandomAccessFile to use it.
I'd prefer to just put it in my log4j.xml as one of the <Policies>, but I don't see how to configure log4j to allow that.

On Mon Dec 21 13:05:47 PST 2015 ralph.goers@dslextreme.com said:
>What do you mean by ?using a custom triggering policy??
>
>Ralph
>
>> On Dec 21, 2015, at 1:47 PM, John Lussmyer <Co...@CasaDelGato.com> wrote:
>>
>> Looking at the TriggeringPolicy interface, writing one that will do what I need would be trivial.
>>
>> The main problem is that I can't find any info on using a custom triggering policy.
>>
>> On Mon Dec 21 10:48:44 PST 2015 ralph.goers@dslextreme.com said:
>>> Log4j 2.5 added a CronTriggeringPoilicy that triggers a rollover when the specified time pattern matches. You could look at that and create your own triggering policy that triggers on whatever your criteria is.  As an alternative you can locate the Appender in the configuration, obtain its manager and kick off the rollover in your code.
>>
>>>> On Dec 21, 2015, at 11:16 AM, John Lussmyer <Co...@CasaDelGato.com> wrote:
>>>>
>>>> I have a place in my program where I would like to cause my logger to roll to the next log file.
>>>> Basically, a "TriggerNow" triggering policy.
>>>> Is there any reasonably easy way to do this?
>> --
>>
>> Tigers prowl and Dragons soar in my dreams...
>>
>> ---------------------------------------------------------------------
>> 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


--

Tigers prowl and Dragons soar in my dreams...

Re: Trigger RollingRandomAccessFile appender programmtically?

Posted by Ralph Goers <ra...@dslextreme.com>.
What do you mean by “using a custom triggering policy”?

Ralph

> On Dec 21, 2015, at 1:47 PM, John Lussmyer <Co...@CasaDelGato.com> wrote:
> 
> Looking at the TriggeringPolicy interface, writing one that will do what I need would be trivial.
> 
> The main problem is that I can't find any info on using a custom triggering policy.
> 
> On Mon Dec 21 10:48:44 PST 2015 ralph.goers@dslextreme.com said:
>> Log4j 2.5 added a CronTriggeringPoilicy that triggers a rollover when the specified time pattern matches. You could look at that and create your own triggering policy that triggers on whatever your criteria is.  As an alternative you can locate the Appender in the configuration, obtain its manager and kick off the rollover in your code.
> 
>>> On Dec 21, 2015, at 11:16 AM, John Lussmyer <Co...@CasaDelGato.com> wrote:
>>> 
>>> I have a place in my program where I would like to cause my logger to roll to the next log file.
>>> Basically, a "TriggerNow" triggering policy.
>>> Is there any reasonably easy way to do this?
> --
> 
> Tigers prowl and Dragons soar in my dreams...
> 
> ---------------------------------------------------------------------
> 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: Trigger RollingRandomAccessFile appender programmtically?

Posted by John Lussmyer <Co...@CasaDelGato.com>.
Looking at the TriggeringPolicy interface, writing one that will do what I need would be trivial.

The main problem is that I can't find any info on using a custom triggering policy.

On Mon Dec 21 10:48:44 PST 2015 ralph.goers@dslextreme.com said:
>Log4j 2.5 added a CronTriggeringPoilicy that triggers a rollover when the specified time pattern matches. You could look at that and create your own triggering policy that triggers on whatever your criteria is.  As an alternative you can locate the Appender in the configuration, obtain its manager and kick off the rollover in your code.

>> On Dec 21, 2015, at 11:16 AM, John Lussmyer <Co...@CasaDelGato.com> wrote:
>>
>> I have a place in my program where I would like to cause my logger to roll to the next log file.
>> Basically, a "TriggerNow" triggering policy.
>> Is there any reasonably easy way to do this?
--

Tigers prowl and Dragons soar in my dreams...

Re: Trigger RollingRandomAccessFile appender programmtically?

Posted by Ralph Goers <ra...@dslextreme.com>.
Log4j 2.5 added a CronTriggeringPoilicy that triggers a rollover when the specified time pattern matches. You could look at that and create your own triggering policy that triggers on whatever your criteria is.  As an alternative you can locate the Appender in the configuration, obtain its manager and kick off the rollover in your code.

Ralph

> On Dec 21, 2015, at 11:16 AM, John Lussmyer <Co...@CasaDelGato.com> wrote:
> 
> I have a place in my program where I would like to cause my logger to roll to the next log file.
> Basically, a "TriggerNow" triggering policy.
> Is there any reasonably easy way to do this?
> 
> --
> Tigers prowl and Dragons soar in my dreams...
> 
> ---------------------------------------------------------------------
> 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