unofficial mirror of 
 help / color / mirror / Atom feed
* [guile-lib] (logging logger) doesn't call flush-log after each log
@ 2024-01-03  2:54 Maxim Cournoyer
  0 siblings, 0 replies; only message in thread
From: Maxim Cournoyer @ 2024-01-03  2:54 UTC (permalink / raw)
  To: guile-devel; +Cc: David Pirotte


I've recently made use of guile-lib's logging library, and was surprised
that by default the rotating-log logger, which logs to a file, would
write to a file using block buffering, which would means logs would only
be seen added to the file every now and then rather than in real time.

That breaks a common expectation of log files, which can typically be
tail'd -f to see a program output as it runs.

I've come up with this workaround:

--8<---------------cut here---------------start------------->8---
    ;; Ensure log messages are written in real time, not block
    ;; buffered.
    (setvbuf (slot-ref rotating 'port) 'line)))
--8<---------------cut here---------------end--------------->8---

But it was not easily discovered and still doesn't feel exactly 'real
time'.  The Python logging library, which is the inspiration for this
one, calls 'flush' after each log message is written in the base class
from which all handlers inherit (see Lib/logging/

--8<---------------cut here---------------start------------->8---
class StreamHandler(Handler):
    A handler class which writes logging records, appropriately formatted,
    to a stream. Note that this class does not close the stream, as
    sys.stdout or sys.stderr may be used.

    terminator = '\n'

    def __init__(self, stream=None):


    def flush(self):
        Flushes the stream.
            if and hasattr(, "flush"):

    def emit(self, record):
        Emit a record.

        If a formatter is specified, it is used to format the record.
        The record is then written to the stream with a trailing newline.  If
        exception information is present, it is formatted using
        traceback.print_exception and appended to the stream.  If the stream
        has an 'encoding' attribute, it is used to determine how to do the
        output to the stream.
            msg = self.format(record)
            stream =
            # issue 35046: merged two stream.writes into one.
            stream.write(msg + self.terminator)
        except RecursionError:  # See issue 36272
        except Exception:

--8<---------------cut here---------------end--------------->8---

This would be easy to do in our logger implementation (we'd call
'flush-log' at the end of 'emit-log'), if we agree it's a good idea.

Would anyone be opposed to that?  If not, I'll happily send a patch.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-03  2:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-03  2:54 [guile-lib] (logging logger) doesn't call flush-log after each log Maxim Cournoyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).