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 Jochen Wiedmann <jo...@gmail.com> on 2016/06/25 06:28:49 UTC

Different Processes, same Logfile

Hi,

is it possible. that multiple proceses share a common log file. (The
processes aree command line executables, ,which will be started at
unpredictable times.

Thanks,

Jochen


-- 
The next time you hear: "Don't reinvent the wheel!"

http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg

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


Re: Different Processes, same Logfile

Posted by Remko Popma <re...@gmail.com>.
I think writing to the same file is possible, but rollover will give
unpredictable results.
As long as you use the normal FileAppender (not RollingFileAppender) this
should work.

Also do not use the RandomAccessFile appender, since both processes will
overwrite each other's log files.

On Sat, Jun 25, 2016 at 3:28 PM, Jochen Wiedmann <jo...@gmail.com>
wrote:

> Hi,
>
> is it possible. that multiple proceses share a common log file. (The
> processes aree command line executables, ,which will be started at
> unpredictable times.
>
> Thanks,
>
> Jochen
>
>
> --
> The next time you hear: "Don't reinvent the wheel!"
>
>
> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: Different Processes, same Logfile

Posted by Jochen Wiedmann <jo...@gmail.com>.
On Sat, Jun 25, 2016 at 4:39 PM, Remko Popma <re...@gmail.com> wrote:

> If you configure a FileAppender
> <http://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender>
> with the locking option set to true, Log4j will do the rest.

Thanks very much, Remko. Exactly, what I was hoping for.

Jochen



-- 
The next time you hear: "Don't reinvent the wheel!"

http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg

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


Re: Different Processes, same Logfile

Posted by Remko Popma <re...@gmail.com>.
If you configure a FileAppender
<http://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender>
with the locking option set to true, Log4j will do the rest.

On Sat, Jun 25, 2016 at 10:45 PM, Jochen Wiedmann <jochen.wiedmann@gmail.com
> wrote:

> On Sat, Jun 25, 2016 at 9:01 AM, Ralph Goers <ra...@dslextreme.com>
> wrote:
> > In order for multiple processes to share a log file os file locking has
> to be used, which impacts performance considerably. Furthermore, only a
> regular FileAppender can be used. You really can’t share a rolling file
> safely as both processes may try to roll the file at the same time.
> Furthermore, if one of the processes fails to specify file locking should
> be used then the file will likely get corrupted on some systems.
>
> I'd be quite ready to pay that price, if I had log4j handle the details
> for me.
>
> Jochen
>
>
>
> --
> The next time you hear: "Don't reinvent the wheel!"
>
>
> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: Different Processes, same Logfile

Posted by Jochen Wiedmann <jo...@gmail.com>.
On Sat, Jun 25, 2016 at 9:01 AM, Ralph Goers <ra...@dslextreme.com> wrote:
> In order for multiple processes to share a log file os file locking has to be used, which impacts performance considerably. Furthermore, only a regular FileAppender can be used. You really can’t share a rolling file safely as both processes may try to roll the file at the same time. Furthermore, if one of the processes fails to specify file locking should be used then the file will likely get corrupted on some systems.

I'd be quite ready to pay that price, if I had log4j handle the details for me.

Jochen



-- 
The next time you hear: "Don't reinvent the wheel!"

http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg

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


Re: Different Processes, same Logfile

Posted by Anthony Maire <ma...@gmail.com>.
In my opinion:
- rolling is an issue
- not using an OS-wide lock is an issue, because the behavior can be
OS-dependant and/or FS-dependant (NFS doesn't natively support append as
far as I know so it will be racy at least on NFS)

It can be possible to do a modified version of a standard appender that use
a OS filelock to synchronize this, but it will surely have an impact on
performance, and it should never be used directly (use a async logger or
async appender before).

Since it can be tricky, I'm wondering why do you need to have the same log
file for several processes ? Is there a better way to address your need
than sharing a common file log ?

2016-06-25 9:08 GMT+02:00 Remko Popma <re...@gmail.com>:

> I would suggest trying without file locking first.
>
> On Sat, Jun 25, 2016 at 4:01 PM, Ralph Goers <ra...@dslextreme.com>
> wrote:
>
> > In order for multiple processes to share a log file os file locking has
> to
> > be used, which impacts performance considerably. Furthermore, only a
> > regular FileAppender can be used. You really can’t share a rolling file
> > safely as both processes may try to roll the file at the same time.
> > Furthermore, if one of the processes fails to specify file locking should
> > be used then the file will likely get corrupted on some systems.
> >
> > Ralph
> >
> > > On Jun 24, 2016, at 11:28 PM, Jochen Wiedmann <
> jochen.wiedmann@gmail.com>
> > wrote:
> > >
> > > Hi,
> > >
> > > is it possible. that multiple proceses share a common log file. (The
> > > processes aree command line executables, ,which will be started at
> > > unpredictable times.
> > >
> > > Thanks,
> > >
> > > Jochen
> > >
> > >
> > > --
> > > The next time you hear: "Don't reinvent the wheel!"
> > >
> > >
> >
> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
> > >
> > > ---------------------------------------------------------------------
> > > 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: Different Processes, same Logfile

Posted by Remko Popma <re...@gmail.com>.
I would suggest trying without file locking first.

On Sat, Jun 25, 2016 at 4:01 PM, Ralph Goers <ra...@dslextreme.com>
wrote:

> In order for multiple processes to share a log file os file locking has to
> be used, which impacts performance considerably. Furthermore, only a
> regular FileAppender can be used. You really can’t share a rolling file
> safely as both processes may try to roll the file at the same time.
> Furthermore, if one of the processes fails to specify file locking should
> be used then the file will likely get corrupted on some systems.
>
> Ralph
>
> > On Jun 24, 2016, at 11:28 PM, Jochen Wiedmann <jo...@gmail.com>
> wrote:
> >
> > Hi,
> >
> > is it possible. that multiple proceses share a common log file. (The
> > processes aree command line executables, ,which will be started at
> > unpredictable times.
> >
> > Thanks,
> >
> > Jochen
> >
> >
> > --
> > The next time you hear: "Don't reinvent the wheel!"
> >
> >
> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
> >
> > ---------------------------------------------------------------------
> > 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: Different Processes, same Logfile

Posted by Ralph Goers <ra...@dslextreme.com>.
In order for multiple processes to share a log file os file locking has to be used, which impacts performance considerably. Furthermore, only a regular FileAppender can be used. You really can’t share a rolling file safely as both processes may try to roll the file at the same time. Furthermore, if one of the processes fails to specify file locking should be used then the file will likely get corrupted on some systems.

Ralph

> On Jun 24, 2016, at 11:28 PM, Jochen Wiedmann <jo...@gmail.com> wrote:
> 
> Hi,
> 
> is it possible. that multiple proceses share a common log file. (The
> processes aree command line executables, ,which will be started at
> unpredictable times.
> 
> Thanks,
> 
> Jochen
> 
> 
> -- 
> The next time you hear: "Don't reinvent the wheel!"
> 
> http://www.keystonedevelopment.co.uk/wp-content/uploads/2014/10/evolution-of-the-wheel-300x85.jpg
> 
> ---------------------------------------------------------------------
> 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