0

I have been searching this site and the Boost.Log doc for a way to do this but have come up empty so far.

The doc (https://www.boost.org/doc/libs/1_74_0/libs/log/doc/html/log/detailed/sink_backends.html) mentions the ability to set a text_stream_backend to flush after each log record written by calling auto_flush(true).

While this works well for debugging, I was wondering if it was possible to configure a custom number of log records received by the core (or sink?) before a flush() occurs. My goal is to strike a balance between useful live logging (I can see the log records frequently enough with a tail -f) and performance.

Alternatively, would it be possible to configure the size of the buffer containing log records so that once it fills up, it gets flushed?

Naju
  • 145
  • 2
  • 12
  • What you ask is not supported by Boost.Log. – Andrey Semashev Aug 27 '20 at 08:37
  • @AndreySemashev I see. Is the default behavior documented somewhere? I'd like to know what determines when a flush occurs (with auto_flush off of course). – Naju Aug 27 '20 at 13:31
  • The default behavior is whatever the behavior of the underlying C/C++ runtime library. Boost.Log does not implement buffering of its own (apart from async sinks) and passes the formatted content to the file stream. – Andrey Semashev Aug 27 '20 at 15:22
  • @AndreySemashev ah! So if I understand correctly, what I need to do is to create my own `ofstream`, configure its behavior and buffer size, and pass it to the backend with `add_stream()` ? – Naju Aug 27 '20 at 16:37
  • Hmmm, I realize now that if I use a `text_ostream_backend` instead of a `text_file_backend`, I lose `scan_for_files()` and `set_file_collector`. Kind of a raw deal. Oh well. – Naju Aug 27 '20 at 17:46
  • There is no portable API to configure internal buffering of file streams - neither in C++ nor in C (and C++ `ofstream` typically builds on top of C `FILE*`). This property is an implementation detail of the runtime library. If you really need to control buffering, you should implement a custom sink backend, which uses the core OS primitives internally, like file descriptors (POSIX) and file handles (Windows). – Andrey Semashev Aug 27 '20 at 19:58
  • @AndreySemashev Ok thanks for the info – Naju Aug 27 '20 at 20:03

0 Answers0