From 0f88db1ef0569bf6fcd5e9c843da38d487a6f54b Mon Sep 17 00:00:00 2001
From: Marcus Müller <mmueller@gnuradio.org>
Date: Sat, 11 Apr 2020 00:43:39 +0200
Subject: runtime: replace stderr logging by calls to GR's logging facilties

---
 gnuradio-runtime/lib/buffer.cc | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

(limited to 'gnuradio-runtime/lib/buffer.cc')

diff --git a/gnuradio-runtime/lib/buffer.cc b/gnuradio-runtime/lib/buffer.cc
index 46d704542b..58b291e649 100644
--- a/gnuradio-runtime/lib/buffer.cc
+++ b/gnuradio-runtime/lib/buffer.cc
@@ -76,6 +76,7 @@ buffer::buffer(int nitems, size_t sizeof_item, block_sptr link)
       d_done(false),
       d_last_min_items_read(0)
 {
+    gr::configure_default_loggers(d_logger, d_debug_logger, "buffer");
     if (!allocate_buffer(nitems, sizeof_item))
         throw std::bad_alloc();
 
@@ -113,21 +114,24 @@ bool buffer::allocate_buffer(int nitems, size_t sizeof_item)
     // This only happens if sizeof_item is not a power of two.
 
     if (nitems > 2 * orig_nitems && nitems * (int)sizeof_item > granularity) {
-        std::cerr << "gr::buffer::allocate_buffer: warning: tried to allocate\n"
-                  << "   " << orig_nitems << " items of size " << sizeof_item
-                  << ". Due to alignment requirements\n"
-                  << "   " << nitems
-                  << " were allocated.  If this isn't OK, consider padding\n"
-                  << "   your structure to a power-of-two bytes.\n"
-                  << "   On this platform, our allocation granularity is " << granularity
-                  << " bytes.\n";
+        auto msg =
+            str(boost::format(
+                    "allocate_buffer: tried to allocate"
+                    "   %d items of size %d. Due to alignment requirements"
+                    "   %d were allocated.  If this isn't OK, consider padding"
+                    "   your structure to a power-of-two bytes."
+                    "   On this platform, our allocation granularity is %d bytes.") %
+                orig_nitems % sizeof_item % nitems % granularity);
+        GR_LOG_WARN(d_logger, msg.c_str());
     }
 
     d_bufsize = nitems;
     d_vmcircbuf.reset(gr::vmcircbuf_sysconfig::make(d_bufsize * d_sizeof_item));
     if (d_vmcircbuf == 0) {
-        std::cerr << "gr::buffer::allocate_buffer: failed to allocate buffer of size "
-                  << d_bufsize * d_sizeof_item / 1024 << " KB\n";
+        std::ostringstream msg;
+        msg << "gr::buffer::allocate_buffer: failed to allocate buffer of size "
+            << d_bufsize * d_sizeof_item / 1024 << " KB";
+        GR_LOG_ERROR(d_logger, msg.str());
         return false;
     }
 
-- 
cgit v1.2.3