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 Leon Finker <le...@gmail.com> on 2016/06/15 15:17:58 UTC

OnStartupTriggeringPolicy/custom header

Hi,

What would be the best way to implement the following:
1. Always roll log file once on JVM startup (and only on JVM startup).  - This could be done with implementing another OnStartupTriggeringPolicy (the one from 2.6.1+ doesn't roll empty files anymore).
2. Log an entry in the new log file (after the roll) with something like:
Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + " STARTING " + service_instance_Name + " " + getProcessId() + " ----------"
- Does PatternLayout's header support system property lookup variables (i.e.: service instance name and date time now)?
- Not sure how to allow for custom method call to get the getProcessId() into the header
- It could've been easy if I could do it from OnStartupTriggeringPolicy, but there is no way to write to the new rolled log file from there.

Is there a way?

Thank you

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


Re: OnStartupTriggeringPolicy/custom header

Posted by Ralph Goers <ra...@dslextreme.com>.
The fix for LOG4J2-1440 has been committed.

Ralph

> On Jun 19, 2016, at 9:44 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> 
> I have already created the fix for this along with allowing the user to specify a minimum file size for the OnStartupTriggeringPolicy.  I will be creating the Jira issue so I can commit the fix.
> 
> Ralph
> 
>> On Jun 19, 2016, at 9:10 PM, Remko Popma <re...@gmail.com> wrote:
>> 
>> Yes please create a Jira. We need it for our change log anyway. (And I find that email quickly drops below the horizon...)
>> 
>> Sent from my iPhone
>> 
>>> On 2016/06/20, at 12:30, Leon Finker <le...@gmail.com> wrote:
>>> 
>>> Yes i can confirm each reconfigure causes the rollover, which is not good
>>> for us. Should I create jira? Thank you
>>>> On Jun 15, 2016 12:25 PM, "Ralph Goers" <ra...@dslextreme.com> wrote:
>>>> 
>>>> I can add an option to the OnStartupTriggeringPolicy to only roll if the
>>>> file meets or exceeds a minimum value. The default would be 1 byte.
>>>> 
>>>> Also, I believe I introduced another bug.  The file is now going to roll
>>>> every time a reconfiguration takes place, which is obviously incorrect. I
>>>> need to fix that asap.
>>>> 
>>>> The PatternLayout does not support interpolation of the header and footer
>>>> but the Configuration does. All attributes are interpolated as the
>>>> configuration is read.  You could create your own custom Lookup to get the
>>>> processId, but that may be something we should add to the standard set of
>>>> properties.
>>>> 
>>>> Actually, the triggering policy could write to the file since it has
>>>> access to the Manager.
>>>> 
>>>> Ralph
>>>> 
>>>> 
>>>> 
>>>>> On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> What would be the best way to implement the following:
>>>>> 1. Always roll log file once on JVM startup (and only on JVM startup).
>>>> - This could be done with implementing another OnStartupTriggeringPolicy
>>>> (the one from 2.6.1+ doesn't roll empty files anymore).
>>>>> 2. Log an entry in the new log file (after the roll) with something like:
>>>>> Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + " STARTING "
>>>> + service_instance_Name + " " + getProcessId() + " ----------"
>>>>> - Does PatternLayout's header support system property lookup variables
>>>> (i.e.: service instance name and date time now)?
>>>>> - Not sure how to allow for custom method call to get the getProcessId()
>>>> into the header
>>>>> - It could've been easy if I could do it from OnStartupTriggeringPolicy,
>>>> but there is no way to write to the new rolled log file from there.
>>>>> 
>>>>> Is there a way?
>>>>> 
>>>>> Thank you
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>> 
>>>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
>> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 



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


Re: OnStartupTriggeringPolicy/custom header

Posted by Ralph Goers <ra...@dslextreme.com>.
I have already created the fix for this along with allowing the user to specify a minimum file size for the OnStartupTriggeringPolicy.  I will be creating the Jira issue so I can commit the fix.

Ralph

> On Jun 19, 2016, at 9:10 PM, Remko Popma <re...@gmail.com> wrote:
> 
> Yes please create a Jira. We need it for our change log anyway. (And I find that email quickly drops below the horizon...)
> 
> Sent from my iPhone
> 
>> On 2016/06/20, at 12:30, Leon Finker <le...@gmail.com> wrote:
>> 
>> Yes i can confirm each reconfigure causes the rollover, which is not good
>> for us. Should I create jira? Thank you
>>> On Jun 15, 2016 12:25 PM, "Ralph Goers" <ra...@dslextreme.com> wrote:
>>> 
>>> I can add an option to the OnStartupTriggeringPolicy to only roll if the
>>> file meets or exceeds a minimum value. The default would be 1 byte.
>>> 
>>> Also, I believe I introduced another bug.  The file is now going to roll
>>> every time a reconfiguration takes place, which is obviously incorrect. I
>>> need to fix that asap.
>>> 
>>> The PatternLayout does not support interpolation of the header and footer
>>> but the Configuration does. All attributes are interpolated as the
>>> configuration is read.  You could create your own custom Lookup to get the
>>> processId, but that may be something we should add to the standard set of
>>> properties.
>>> 
>>> Actually, the triggering policy could write to the file since it has
>>> access to the Manager.
>>> 
>>> Ralph
>>> 
>>> 
>>> 
>>>> On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> What would be the best way to implement the following:
>>>> 1. Always roll log file once on JVM startup (and only on JVM startup).
>>> - This could be done with implementing another OnStartupTriggeringPolicy
>>> (the one from 2.6.1+ doesn't roll empty files anymore).
>>>> 2. Log an entry in the new log file (after the roll) with something like:
>>>> Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + " STARTING "
>>> + service_instance_Name + " " + getProcessId() + " ----------"
>>>> - Does PatternLayout's header support system property lookup variables
>>> (i.e.: service instance name and date time now)?
>>>> - Not sure how to allow for custom method call to get the getProcessId()
>>> into the header
>>>> - It could've been easy if I could do it from OnStartupTriggeringPolicy,
>>> but there is no way to write to the new rolled log file from there.
>>>> 
>>>> Is there a way?
>>>> 
>>>> Thank you
>>>> 
>>>> ---------------------------------------------------------------------
>>>> 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: OnStartupTriggeringPolicy/custom header

Posted by Remko Popma <re...@gmail.com>.
Yes please create a Jira. We need it for our change log anyway. (And I find that email quickly drops below the horizon...)

Sent from my iPhone

> On 2016/06/20, at 12:30, Leon Finker <le...@gmail.com> wrote:
> 
> Yes i can confirm each reconfigure causes the rollover, which is not good
> for us. Should I create jira? Thank you
>> On Jun 15, 2016 12:25 PM, "Ralph Goers" <ra...@dslextreme.com> wrote:
>> 
>> I can add an option to the OnStartupTriggeringPolicy to only roll if the
>> file meets or exceeds a minimum value. The default would be 1 byte.
>> 
>> Also, I believe I introduced another bug.  The file is now going to roll
>> every time a reconfiguration takes place, which is obviously incorrect. I
>> need to fix that asap.
>> 
>> The PatternLayout does not support interpolation of the header and footer
>> but the Configuration does. All attributes are interpolated as the
>> configuration is read.  You could create your own custom Lookup to get the
>> processId, but that may be something we should add to the standard set of
>> properties.
>> 
>> Actually, the triggering policy could write to the file since it has
>> access to the Manager.
>> 
>> Ralph
>> 
>> 
>> 
>>> On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> What would be the best way to implement the following:
>>> 1. Always roll log file once on JVM startup (and only on JVM startup).
>> - This could be done with implementing another OnStartupTriggeringPolicy
>> (the one from 2.6.1+ doesn't roll empty files anymore).
>>> 2. Log an entry in the new log file (after the roll) with something like:
>>> Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + " STARTING "
>> + service_instance_Name + " " + getProcessId() + " ----------"
>>> - Does PatternLayout's header support system property lookup variables
>> (i.e.: service instance name and date time now)?
>>> - Not sure how to allow for custom method call to get the getProcessId()
>> into the header
>>> - It could've been easy if I could do it from OnStartupTriggeringPolicy,
>> but there is no way to write to the new rolled log file from there.
>>> 
>>> Is there a way?
>>> 
>>> Thank you
>>> 
>>> ---------------------------------------------------------------------
>>> 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: OnStartupTriggeringPolicy/custom header

Posted by Leon Finker <le...@gmail.com>.
Yes i can confirm each reconfigure causes the rollover, which is not good
for us. Should I create jira? Thank you
On Jun 15, 2016 12:25 PM, "Ralph Goers" <ra...@dslextreme.com> wrote:

> I can add an option to the OnStartupTriggeringPolicy to only roll if the
> file meets or exceeds a minimum value. The default would be 1 byte.
>
> Also, I believe I introduced another bug.  The file is now going to roll
> every time a reconfiguration takes place, which is obviously incorrect. I
> need to fix that asap.
>
> The PatternLayout does not support interpolation of the header and footer
> but the Configuration does. All attributes are interpolated as the
> configuration is read.  You could create your own custom Lookup to get the
> processId, but that may be something we should add to the standard set of
> properties.
>
> Actually, the triggering policy could write to the file since it has
> access to the Manager.
>
> Ralph
>
>
>
> > On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
> >
> > Hi,
> >
> > What would be the best way to implement the following:
> > 1. Always roll log file once on JVM startup (and only on JVM startup).
> - This could be done with implementing another OnStartupTriggeringPolicy
> (the one from 2.6.1+ doesn't roll empty files anymore).
> > 2. Log an entry in the new log file (after the roll) with something like:
> > Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + " STARTING "
> + service_instance_Name + " " + getProcessId() + " ----------"
> > - Does PatternLayout's header support system property lookup variables
> (i.e.: service instance name and date time now)?
> > - Not sure how to allow for custom method call to get the getProcessId()
> into the header
> > - It could've been easy if I could do it from OnStartupTriggeringPolicy,
> but there is no way to write to the new rolled log file from there.
> >
> > Is there a way?
> >
> > Thank you
> >
> > ---------------------------------------------------------------------
> > 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: OnStartupTriggeringPolicy/custom header

Posted by Leon Finker <le...@gmail.com>.
That would be nice. Also, I confirmed and drain(ByteBuffer) works in my
case.
On Jun 15, 2016 8:24 PM, "Remko Popma" <re...@gmail.com> wrote:

> Ralph, any objection to making the write methods public?
>
> Sent from my iPhone
>
> > On 2016/06/16, at 9:05, Leon Finker <le...@gmail.com> wrote:
> >
> > As I remember they are not visible (protected).
> >> On Jun 15, 2016 7:59 PM, "Remko Popma" <re...@gmail.com> wrote:
> >>
> >> I would not use the drain(ByteBuffer) method directly because it would
> >> cause that message to appear in the log file ahead of the messages that
> are
> >> currently in the buffer but haven't been flushed yet.
> >>
> >> Have you looked at the parent OutputStreamManager class?
> >> Why not use one of the write(byte[], ...) methods? They correctly append
> >> to any existing messages.
> >>
> >> Remko
> >>
> >> Sent from my iPhone
> >>
> >>> On 2016/06/16, at 2:40, Ralph Goers <ra...@dslextreme.com>
> wrote:
> >>>
> >>> Yes, the drain method should write whatever is in the ByteBuffer to the
> >> file.
> >>>
> >>> Ralph
> >>>
> >>>> On Jun 15, 2016, at 9:34 AM, Leon Finker <le...@gmail.com> wrote:
> >>>>
> >>>> An option to roll even empty files would be great. Because in our case
> >> we always want to roll the previous log file.
> >>>>
> >>>>> Actually, the triggering policy could write to the file since it has
> >> access to the Manager.
> >>>>
> >>>> I've looked through all the possible methods on RollingFileManager and
> >> nothing jumped out that allows us to write to the log file. I only see
> >> drain(ByteBuffer), is that the one to use? Writing from triggering
> policy
> >> seems to be the easiest way in our case.
> >>>>
> >>>>> On 2016-06-15 12:25 (-0400), Ralph Goers <ralph.goers@dslextreme.com
> >
> >> wrote:
> >>>>> I can add an option to the OnStartupTriggeringPolicy to only roll if
> >> the file meets or exceeds a minimum value. The default would be 1 byte.
> >>>>>
> >>>>> Also, I believe I introduced another bug.  The file is now going to
> >> roll every time a reconfiguration takes place, which is obviously
> >> incorrect. I need to fix that asap.
> >>>>>
> >>>>> The PatternLayout does not support interpolation of the header and
> >> footer but the Configuration does. All attributes are interpolated as
> the
> >> configuration is read.  You could create your own custom Lookup to get
> the
> >> processId, but that may be something we should add to the standard set
> of
> >> properties.
> >>>>>
> >>>>> Actually, the triggering policy could write to the file since it has
> >> access to the Manager.
> >>>>>
> >>>>> Ralph
> >>>>>
> >>>>>
> >>>>>
> >>>>>> On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
> >>>>>>
> >>>>>> Hi,
> >>>>>>
> >>>>>> What would be the best way to implement the following:
> >>>>>> 1. Always roll log file once on JVM startup (and only on JVM
> >> startup).  - This could be done with implementing another
> >> OnStartupTriggeringPolicy (the one from 2.6.1+ doesn't roll empty files
> >> anymore).
> >>>>>> 2. Log an entry in the new log file (after the roll) with something
> >> like:
> >>>>>> Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + "
> >> STARTING " + service_instance_Name + " " + getProcessId() + "
> ----------"
> >>>>>> - Does PatternLayout's header support system property lookup
> >> variables (i.e.: service instance name and date time now)?
> >>>>>> - Not sure how to allow for custom method call to get the
> >> getProcessId() into the header
> >>>>>> - It could've been easy if I could do it from
> >> OnStartupTriggeringPolicy, but there is no way to write to the new
> rolled
> >> log file from there.
> >>>>>>
> >>>>>> Is there a way?
> >>>>>>
> >>>>>> Thank you
> >>>>>>
> >>>>>>
> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>>>>
> >>>>>
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: OnStartupTriggeringPolicy/custom header

Posted by Remko Popma <re...@gmail.com>.
Ralph, any objection to making the write methods public?

Sent from my iPhone

> On 2016/06/16, at 9:05, Leon Finker <le...@gmail.com> wrote:
> 
> As I remember they are not visible (protected).
>> On Jun 15, 2016 7:59 PM, "Remko Popma" <re...@gmail.com> wrote:
>> 
>> I would not use the drain(ByteBuffer) method directly because it would
>> cause that message to appear in the log file ahead of the messages that are
>> currently in the buffer but haven't been flushed yet.
>> 
>> Have you looked at the parent OutputStreamManager class?
>> Why not use one of the write(byte[], ...) methods? They correctly append
>> to any existing messages.
>> 
>> Remko
>> 
>> Sent from my iPhone
>> 
>>> On 2016/06/16, at 2:40, Ralph Goers <ra...@dslextreme.com> wrote:
>>> 
>>> Yes, the drain method should write whatever is in the ByteBuffer to the
>> file.
>>> 
>>> Ralph
>>> 
>>>> On Jun 15, 2016, at 9:34 AM, Leon Finker <le...@gmail.com> wrote:
>>>> 
>>>> An option to roll even empty files would be great. Because in our case
>> we always want to roll the previous log file.
>>>> 
>>>>> Actually, the triggering policy could write to the file since it has
>> access to the Manager.
>>>> 
>>>> I've looked through all the possible methods on RollingFileManager and
>> nothing jumped out that allows us to write to the log file. I only see
>> drain(ByteBuffer), is that the one to use? Writing from triggering policy
>> seems to be the easiest way in our case.
>>>> 
>>>>> On 2016-06-15 12:25 (-0400), Ralph Goers <ra...@dslextreme.com>
>> wrote:
>>>>> I can add an option to the OnStartupTriggeringPolicy to only roll if
>> the file meets or exceeds a minimum value. The default would be 1 byte.
>>>>> 
>>>>> Also, I believe I introduced another bug.  The file is now going to
>> roll every time a reconfiguration takes place, which is obviously
>> incorrect. I need to fix that asap.
>>>>> 
>>>>> The PatternLayout does not support interpolation of the header and
>> footer but the Configuration does. All attributes are interpolated as the
>> configuration is read.  You could create your own custom Lookup to get the
>> processId, but that may be something we should add to the standard set of
>> properties.
>>>>> 
>>>>> Actually, the triggering policy could write to the file since it has
>> access to the Manager.
>>>>> 
>>>>> Ralph
>>>>> 
>>>>> 
>>>>> 
>>>>>> On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
>>>>>> 
>>>>>> Hi,
>>>>>> 
>>>>>> What would be the best way to implement the following:
>>>>>> 1. Always roll log file once on JVM startup (and only on JVM
>> startup).  - This could be done with implementing another
>> OnStartupTriggeringPolicy (the one from 2.6.1+ doesn't roll empty files
>> anymore).
>>>>>> 2. Log an entry in the new log file (after the roll) with something
>> like:
>>>>>> Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + "
>> STARTING " + service_instance_Name + " " + getProcessId() + " ----------"
>>>>>> - Does PatternLayout's header support system property lookup
>> variables (i.e.: service instance name and date time now)?
>>>>>> - Not sure how to allow for custom method call to get the
>> getProcessId() into the header
>>>>>> - It could've been easy if I could do it from
>> OnStartupTriggeringPolicy, but there is no way to write to the new rolled
>> log file from there.
>>>>>> 
>>>>>> Is there a way?
>>>>>> 
>>>>>> Thank you
>>>>>> 
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>>> 
>>>>> 
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
>> 

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


Re: OnStartupTriggeringPolicy/custom header

Posted by Leon Finker <le...@gmail.com>.
As I remember they are not visible (protected).
On Jun 15, 2016 7:59 PM, "Remko Popma" <re...@gmail.com> wrote:

> I would not use the drain(ByteBuffer) method directly because it would
> cause that message to appear in the log file ahead of the messages that are
> currently in the buffer but haven't been flushed yet.
>
> Have you looked at the parent OutputStreamManager class?
> Why not use one of the write(byte[], ...) methods? They correctly append
> to any existing messages.
>
> Remko
>
> Sent from my iPhone
>
> > On 2016/06/16, at 2:40, Ralph Goers <ra...@dslextreme.com> wrote:
> >
> > Yes, the drain method should write whatever is in the ByteBuffer to the
> file.
> >
> > Ralph
> >
> >> On Jun 15, 2016, at 9:34 AM, Leon Finker <le...@gmail.com> wrote:
> >>
> >> An option to roll even empty files would be great. Because in our case
> we always want to roll the previous log file.
> >>
> >>> Actually, the triggering policy could write to the file since it has
> access to the Manager.
> >>
> >> I've looked through all the possible methods on RollingFileManager and
> nothing jumped out that allows us to write to the log file. I only see
> drain(ByteBuffer), is that the one to use? Writing from triggering policy
> seems to be the easiest way in our case.
> >>
> >>> On 2016-06-15 12:25 (-0400), Ralph Goers <ra...@dslextreme.com>
> wrote:
> >>> I can add an option to the OnStartupTriggeringPolicy to only roll if
> the file meets or exceeds a minimum value. The default would be 1 byte.
> >>>
> >>> Also, I believe I introduced another bug.  The file is now going to
> roll every time a reconfiguration takes place, which is obviously
> incorrect. I need to fix that asap.
> >>>
> >>> The PatternLayout does not support interpolation of the header and
> footer but the Configuration does. All attributes are interpolated as the
> configuration is read.  You could create your own custom Lookup to get the
> processId, but that may be something we should add to the standard set of
> properties.
> >>>
> >>> Actually, the triggering policy could write to the file since it has
> access to the Manager.
> >>>
> >>> Ralph
> >>>
> >>>
> >>>
> >>>> On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>> What would be the best way to implement the following:
> >>>> 1. Always roll log file once on JVM startup (and only on JVM
> startup).  - This could be done with implementing another
> OnStartupTriggeringPolicy (the one from 2.6.1+ doesn't roll empty files
> anymore).
> >>>> 2. Log an entry in the new log file (after the roll) with something
> like:
> >>>> Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + "
> STARTING " + service_instance_Name + " " + getProcessId() + " ----------"
> >>>> - Does PatternLayout's header support system property lookup
> variables (i.e.: service instance name and date time now)?
> >>>> - Not sure how to allow for custom method call to get the
> getProcessId() into the header
> >>>> - It could've been easy if I could do it from
> OnStartupTriggeringPolicy, but there is no way to write to the new rolled
> log file from there.
> >>>>
> >>>> Is there a way?
> >>>>
> >>>> Thank you
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: OnStartupTriggeringPolicy/custom header

Posted by Remko Popma <re...@gmail.com>.
I would not use the drain(ByteBuffer) method directly because it would cause that message to appear in the log file ahead of the messages that are currently in the buffer but haven't been flushed yet. 

Have you looked at the parent OutputStreamManager class?
Why not use one of the write(byte[], ...) methods? They correctly append to any existing messages. 

Remko

Sent from my iPhone

> On 2016/06/16, at 2:40, Ralph Goers <ra...@dslextreme.com> wrote:
> 
> Yes, the drain method should write whatever is in the ByteBuffer to the file.
> 
> Ralph
> 
>> On Jun 15, 2016, at 9:34 AM, Leon Finker <le...@gmail.com> wrote:
>> 
>> An option to roll even empty files would be great. Because in our case we always want to roll the previous log file.
>> 
>>> Actually, the triggering policy could write to the file since it has access to the Manager.
>> 
>> I've looked through all the possible methods on RollingFileManager and nothing jumped out that allows us to write to the log file. I only see drain(ByteBuffer), is that the one to use? Writing from triggering policy seems to be the easiest way in our case.
>> 
>>> On 2016-06-15 12:25 (-0400), Ralph Goers <ra...@dslextreme.com> wrote: 
>>> I can add an option to the OnStartupTriggeringPolicy to only roll if the file meets or exceeds a minimum value. The default would be 1 byte.
>>> 
>>> Also, I believe I introduced another bug.  The file is now going to roll every time a reconfiguration takes place, which is obviously incorrect. I need to fix that asap.
>>> 
>>> The PatternLayout does not support interpolation of the header and footer but the Configuration does. All attributes are interpolated as the configuration is read.  You could create your own custom Lookup to get the processId, but that may be something we should add to the standard set of properties.
>>> 
>>> Actually, the triggering policy could write to the file since it has access to the Manager.
>>> 
>>> Ralph
>>> 
>>> 
>>> 
>>>> On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> What would be the best way to implement the following:
>>>> 1. Always roll log file once on JVM startup (and only on JVM startup).  - This could be done with implementing another OnStartupTriggeringPolicy (the one from 2.6.1+ doesn't roll empty files anymore).
>>>> 2. Log an entry in the new log file (after the roll) with something like:
>>>> Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + " STARTING " + service_instance_Name + " " + getProcessId() + " ----------"
>>>> - Does PatternLayout's header support system property lookup variables (i.e.: service instance name and date time now)?
>>>> - Not sure how to allow for custom method call to get the getProcessId() into the header
>>>> - It could've been easy if I could do it from OnStartupTriggeringPolicy, but there is no way to write to the new rolled log file from there.
>>>> 
>>>> Is there a way?
>>>> 
>>>> Thank you
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 

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


Re: OnStartupTriggeringPolicy/custom header

Posted by Ralph Goers <ra...@dslextreme.com>.
Yes, the drain method should write whatever is in the ByteBuffer to the file.

Ralph

> On Jun 15, 2016, at 9:34 AM, Leon Finker <le...@gmail.com> wrote:
> 
> An option to roll even empty files would be great. Because in our case we always want to roll the previous log file.
> 
>> Actually, the triggering policy could write to the file since it has access to the Manager.
> 
> I've looked through all the possible methods on RollingFileManager and nothing jumped out that allows us to write to the log file. I only see drain(ByteBuffer), is that the one to use? Writing from triggering policy seems to be the easiest way in our case.
> 
> On 2016-06-15 12:25 (-0400), Ralph Goers <ra...@dslextreme.com> wrote: 
>> I can add an option to the OnStartupTriggeringPolicy to only roll if the file meets or exceeds a minimum value. The default would be 1 byte.
>> 
>> Also, I believe I introduced another bug.  The file is now going to roll every time a reconfiguration takes place, which is obviously incorrect. I need to fix that asap.
>> 
>> The PatternLayout does not support interpolation of the header and footer but the Configuration does. All attributes are interpolated as the configuration is read.  You could create your own custom Lookup to get the processId, but that may be something we should add to the standard set of properties.
>> 
>> Actually, the triggering policy could write to the file since it has access to the Manager.
>> 
>> Ralph
>> 
>> 
>> 
>>> On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> What would be the best way to implement the following:
>>> 1. Always roll log file once on JVM startup (and only on JVM startup).  - This could be done with implementing another OnStartupTriggeringPolicy (the one from 2.6.1+ doesn't roll empty files anymore).
>>> 2. Log an entry in the new log file (after the roll) with something like:
>>> Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + " STARTING " + service_instance_Name + " " + getProcessId() + " ----------"
>>> - Does PatternLayout's header support system property lookup variables (i.e.: service instance name and date time now)?
>>> - Not sure how to allow for custom method call to get the getProcessId() into the header
>>> - It could've been easy if I could do it from OnStartupTriggeringPolicy, but there is no way to write to the new rolled log file from there.
>>> 
>>> Is there a way?
>>> 
>>> Thank you
>>> 
>>> ---------------------------------------------------------------------
>>> 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: OnStartupTriggeringPolicy/custom header

Posted by Leon Finker <le...@gmail.com>.
An option to roll even empty files would be great. Because in our case we always want to roll the previous log file.

>Actually, the triggering policy could write to the file since it has access to the Manager.

I've looked through all the possible methods on RollingFileManager and nothing jumped out that allows us to write to the log file. I only see drain(ByteBuffer), is that the one to use? Writing from triggering policy seems to be the easiest way in our case.

On 2016-06-15 12:25 (-0400), Ralph Goers <ra...@dslextreme.com> wrote: 
> I can add an option to the OnStartupTriggeringPolicy to only roll if the file meets or exceeds a minimum value. The default would be 1 byte.
> 
> Also, I believe I introduced another bug.  The file is now going to roll every time a reconfiguration takes place, which is obviously incorrect. I need to fix that asap.
> 
> The PatternLayout does not support interpolation of the header and footer but the Configuration does. All attributes are interpolated as the configuration is read.  You could create your own custom Lookup to get the processId, but that may be something we should add to the standard set of properties.
> 
> Actually, the triggering policy could write to the file since it has access to the Manager.
> 
> Ralph
> 
> 
> 
> > On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
> > 
> > Hi,
> > 
> > What would be the best way to implement the following:
> > 1. Always roll log file once on JVM startup (and only on JVM startup).  - This could be done with implementing another OnStartupTriggeringPolicy (the one from 2.6.1+ doesn't roll empty files anymore).
> > 2. Log an entry in the new log file (after the roll) with something like:
> > Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + " STARTING " + service_instance_Name + " " + getProcessId() + " ----------"
> > - Does PatternLayout's header support system property lookup variables (i.e.: service instance name and date time now)?
> > - Not sure how to allow for custom method call to get the getProcessId() into the header
> > - It could've been easy if I could do it from OnStartupTriggeringPolicy, but there is no way to write to the new rolled log file from there.
> > 
> > Is there a way?
> > 
> > Thank you
> > 
> > ---------------------------------------------------------------------
> > 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: OnStartupTriggeringPolicy/custom header

Posted by Ralph Goers <ra...@dslextreme.com>.
I can add an option to the OnStartupTriggeringPolicy to only roll if the file meets or exceeds a minimum value. The default would be 1 byte.

Also, I believe I introduced another bug.  The file is now going to roll every time a reconfiguration takes place, which is obviously incorrect. I need to fix that asap.

The PatternLayout does not support interpolation of the header and footer but the Configuration does. All attributes are interpolated as the configuration is read.  You could create your own custom Lookup to get the processId, but that may be something we should add to the standard set of properties.

Actually, the triggering policy could write to the file since it has access to the Manager.

Ralph



> On Jun 15, 2016, at 8:17 AM, Leon Finker <le...@gmail.com> wrote:
> 
> Hi,
> 
> What would be the best way to implement the following:
> 1. Always roll log file once on JVM startup (and only on JVM startup).  - This could be done with implementing another OnStartupTriggeringPolicy (the one from 2.6.1+ doesn't roll empty files anymore).
> 2. Log an entry in the new log file (after the roll) with something like:
> Constants.LINE_SEPARATOR + "---------- " + DateTime.now() + " STARTING " + service_instance_Name + " " + getProcessId() + " ----------"
> - Does PatternLayout's header support system property lookup variables (i.e.: service instance name and date time now)?
> - Not sure how to allow for custom method call to get the getProcessId() into the header
> - It could've been easy if I could do it from OnStartupTriggeringPolicy, but there is no way to write to the new rolled log file from there.
> 
> Is there a way?
> 
> Thank you
> 
> ---------------------------------------------------------------------
> 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