Sys::Syslog question

Discussion in 'Perl Misc' started by Dave Saville, Feb 4, 2011.

  1. Dave Saville

    Dave Saville Guest

    I am writing a script that takes a named pipe as input, does a little
    massaging of the text and then writes it to syslog. The data could
    come infrequently or in bursts depending on the output of the daemon
    whose pipe I am reading.

    The question is, which is best practice?

    1) Inside the read pipe loop - openlog, write, close log for every
    line.
    2) Openlog outside the pipe read loop and write each line as it comes?
    ie keep the file open.

    Google does not suggest an answer. I tend to 1) but it is a heck of an
    overhead if a few thousand lines hits the fan.

    TIA

    --
    Regards
    Dave Saville
    Dave Saville, Feb 4, 2011
    #1
    1. Advertising

  2. On Fri, 04 Feb 2011 11:50:46 +0000, Dave Saville wrote:

    > I am writing a script that takes a named pipe as input, does a little
    > massaging of the text and then writes it to syslog. The data could come
    > infrequently or in bursts depending on the output of the daemon whose
    > pipe I am reading.
    >
    > The question is, which is best practice?
    >
    > 1) Inside the read pipe loop - openlog, write, close log for every line.
    > 2) Openlog outside the pipe read loop and write each line as it comes?
    > ie keep the file open.


    What's wrong with option 2?

    M4
    Martijn Lievaart, Feb 4, 2011
    #2
    1. Advertising

  3. Dave Saville

    Dave Saville Guest

    On Fri, 4 Feb 2011 12:36:06 UTC, Martijn Lievaart <>
    wrote:

    > On Fri, 04 Feb 2011 11:50:46 +0000, Dave Saville wrote:
    >
    > > I am writing a script that takes a named pipe as input, does a little
    > > massaging of the text and then writes it to syslog. The data could come
    > > infrequently or in bursts depending on the output of the daemon whose
    > > pipe I am reading.
    > >
    > > The question is, which is best practice?
    > >
    > > 1) Inside the read pipe loop - openlog, write, close log for every line.
    > > 2) Openlog outside the pipe read loop and write each line as it comes?
    > > ie keep the file open.

    >
    > What's wrong with option 2?
    >


    Well I am not sure if keeping an open connection to the syslogd daemon
    for days on end is a good idea :)


    --
    Regards
    Dave Saville
    Dave Saville, Feb 4, 2011
    #3
  4. On Fri, 04 Feb 2011 13:01:45 +0000, Dave Saville wrote:

    > On Fri, 4 Feb 2011 12:36:06 UTC, Martijn Lievaart <>
    > wrote:
    >
    >> On Fri, 04 Feb 2011 11:50:46 +0000, Dave Saville wrote:
    >>
    >> > I am writing a script that takes a named pipe as input, does a little
    >> > massaging of the text and then writes it to syslog. The data could
    >> > come infrequently or in bursts depending on the output of the daemon
    >> > whose pipe I am reading.
    >> >
    >> > The question is, which is best practice?
    >> >
    >> > 1) Inside the read pipe loop - openlog, write, close log for every
    >> > line. 2) Openlog outside the pipe read loop and write each line as it
    >> > comes? ie keep the file open.

    >>
    >> What's wrong with option 2?
    >>
    >>

    > Well I am not sure if keeping an open connection to the syslogd daemon
    > for days on end is a good idea :)


    Think about it this way (although I may be wrong). The only real problem
    that can occur is restarting the syslog deamon and thus losing the
    connection. But if that was a real problem, it can happen anytime between
    opening syslog and writing to it. So Either there is no problem, or the
    problem must be addressed anyhow.

    But maybe someone else knows more? You could also ask in a Unix group, as
    this is actually more about the clib functionality than the perl wrapper
    around it.

    HTH,
    M4
    Martijn Lievaart, Feb 4, 2011
    #4
  5. with <fV45K0OBJxbE-pn2-djbSFegGnbeu@localhost> Dave Saville wrote:
    > On Fri, 4 Feb 2011 12:36:06 UTC, Martijn Lievaart <>
    > wrote:
    >
    >> On Fri, 04 Feb 2011 11:50:46 +0000, Dave Saville wrote:

    *SKIP*
    >> > The question is, which is best practice?
    >> >
    >> > 1) Inside the read pipe loop - openlog, write, close log for every
    >> > line.
    >> > 2) Openlog outside the pipe read loop and write each line as it
    >> > comes? ie keep the file open.

    >>
    >> What's wrong with option 2?
    >>

    >
    > Well I am not sure if keeping an open connection to the syslogd daemon
    > for days on end is a good idea :)


    Sysloging over network is of UDP kind, thus no-connection. OTOH, if
    there's any connection with /dev/log I can't say without investigation
    (and, honestly, I'm not interested). And please note, fork(2) is
    costly. open(2) isn't. You can safely (if you wish) open-write-close.
    With amounts of bytes you're going to syslog you'll see no problems.

    --
    Torvalds' goal for Linux is very simple: World Domination
    Stallman's goal for GNU is even simpler: Freedom
    Eric Pozharski, Feb 5, 2011
    #5
  6. Dave Saville

    Dave Saville Guest

    On Sat, 5 Feb 2011 10:42:31 UTC, Eric Pozharski
    <> wrote:

    > with <fV45K0OBJxbE-pn2-djbSFegGnbeu@localhost> Dave Saville wrote:
    > > On Fri, 4 Feb 2011 12:36:06 UTC, Martijn Lievaart <>
    > > wrote:
    > >
    > >> On Fri, 04 Feb 2011 11:50:46 +0000, Dave Saville wrote:

    > *SKIP*
    > >> > The question is, which is best practice?
    > >> >
    > >> > 1) Inside the read pipe loop - openlog, write, close log for every
    > >> > line.
    > >> > 2) Openlog outside the pipe read loop and write each line as it
    > >> > comes? ie keep the file open.
    > >>
    > >> What's wrong with option 2?
    > >>

    > >
    > > Well I am not sure if keeping an open connection to the syslogd daemon
    > > for days on end is a good idea :)

    >
    > Sysloging over network is of UDP kind, thus no-connection. OTOH, if
    > there's any connection with /dev/log I can't say without investigation
    > (and, honestly, I'm not interested). And please note, fork(2) is
    > costly. open(2) isn't. You can safely (if you wish) open-write-close.
    > With amounts of bytes you're going to syslog you'll see no problems.
    >


    Thanks - going for option 2 and see if I get any problems.
    --
    Regards
    Dave Saville
    Dave Saville, Feb 6, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    6,053
    Chris Uppal
    Jun 20, 2006
  2. Thomas Glanzmann

    Sys::Syslog issue on Solaris 9 with perl-5.8.2

    Thomas Glanzmann, Jan 10, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    169
    Thomas Glanzmann
    Jan 10, 2004
  3. Stuart Kendrick
    Replies:
    0
    Views:
    177
    Stuart Kendrick
    Feb 26, 2004
  4. leroy isaac
    Replies:
    1
    Views:
    479
    James Willmore
    Oct 29, 2004
  5. Bad Dog
    Replies:
    0
    Views:
    234
    Bad Dog
    Aug 9, 2007
Loading...

Share This Page