Re: Trying to write a log function



On 2007-07-04 11:26, Jrgen Exner <jurgenex@xxxxxxxxxxx> wrote:
Tim Southerwood wrote:
Opening and closing the file on every call to Log() is expensive.

True.

One usually opens it once and then keeps the file handle around.

Depends. If you want to capture the last breath of your program before it
dies an untimely death then you don't want to risk loosing its last words in
an unsaved buffer.

You should generally turn autoflush on on log files. Apart from the
reason you just mentioned there are two others:

1) If your program only prints log entries only infrequently, it may
take a long time until the (typically 4kB or 8kB) buffer fills up.
Normally you want every log message in the log immediately, not a
bunch of messages every few hours.

2) Buffers usually have a fixed size, so the blocks written to the log
file will not start and end at line boundaries. If you have several
processes writing to the same log file lines will be mixed. If you
flush after every line that can't happen (at least on Unix, the
kernel makes sure that a single write on a file in append mode is
written atomically). For the same reason you should write the whole
message with a single print call.

hp


--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@xxxxxx |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
.



Relevant Pages

  • RE: SBS2003/ISA 2004 Firewall, Web Proxy and SMTP Message Screener logfiles
    ... specific timescale and reason of keeping the logs. ... To delete the oldest log files when you exceed the limits that you ... This newsgroup only focuses on SBS technical issues. ... you may want to contact Microsoft CSS directly. ...
    (microsoft.public.windows.server.sbs)
  • Re: user-level logrotate?
    ... |> I have a few applications that create log files in my home directory. ... Occasionally your car would die on the freeway for no reason. ... windows, shut it off, restart it, and reopen the windows before you ...
    (Debian-User)
  • Re: pruning image after FBA
    ... Roger Levy wrote: ... > After FBA and before I create an .SDI file for remote booting, ... > reason to retain the FBA directory? ... That would probably depend on which log files? ...
    (microsoft.public.windowsxp.embedded)
  • Re: Computer reboots frequently -what the reason?
    ... Whta can be the reason? ... Is there a sense look at log files for ...
    (microsoft.public.windowsxp.general)

Loading