diff options
author | Marcus Müller <mmueller@gnuradio.org> | 2020-04-11 01:04:25 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2020-04-13 15:55:41 +0200 |
commit | 95178211eb87d6bf40d51210cf501e6e840863fe (patch) | |
tree | f5b78778291f977ea20d50947086e108bd5a36b5 | |
parent | 7a203ad0481aea3820ea60568402b94cff83ab1d (diff) |
blocks: replace stderr logging by calls to GR's logging facilties
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/file_sink_base.h | 2 | ||||
-rw-r--r-- | gr-blocks/lib/file_descriptor_sink_impl.cc | 2 | ||||
-rw-r--r-- | gr-blocks/lib/file_descriptor_source_impl.cc | 8 | ||||
-rw-r--r-- | gr-blocks/lib/file_meta_sink_impl.cc | 4 | ||||
-rw-r--r-- | gr-blocks/lib/file_meta_source_impl.cc | 4 | ||||
-rw-r--r-- | gr-blocks/lib/file_sink_base.cc | 7 | ||||
-rw-r--r-- | gr-blocks/lib/stream_pdu_base.cc | 9 | ||||
-rw-r--r-- | gr-blocks/lib/stream_pdu_base.h | 3 | ||||
-rw-r--r-- | gr-blocks/lib/tagged_file_sink_impl.cc | 16 | ||||
-rw-r--r-- | gr-blocks/lib/tuntap_pdu_impl.cc | 14 | ||||
-rw-r--r-- | gr-blocks/lib/wavfile_sink_impl.cc | 12 | ||||
-rw-r--r-- | gr-blocks/lib/wavfile_source_impl.cc | 17 |
12 files changed, 64 insertions, 34 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/file_sink_base.h b/gr-blocks/include/gnuradio/blocks/file_sink_base.h index d4a294e253..18eef9caa9 100644 --- a/gr-blocks/include/gnuradio/blocks/file_sink_base.h +++ b/gr-blocks/include/gnuradio/blocks/file_sink_base.h @@ -12,6 +12,7 @@ #define INCLUDED_GR_FILE_SINK_BASE_H #include <gnuradio/blocks/api.h> +#include <gnuradio/logger.h> #include <boost/thread.hpp> #include <cstdio> @@ -31,6 +32,7 @@ protected: boost::mutex d_mutex; bool d_unbuffered; bool d_append; + gr::logger_ptr d_logger, d_debug_logger; protected: file_sink_base(const char* filename, bool is_binary, bool append); diff --git a/gr-blocks/lib/file_descriptor_sink_impl.cc b/gr-blocks/lib/file_descriptor_sink_impl.cc index e0471002a3..809b96e8c1 100644 --- a/gr-blocks/lib/file_descriptor_sink_impl.cc +++ b/gr-blocks/lib/file_descriptor_sink_impl.cc @@ -60,7 +60,7 @@ int file_descriptor_sink_impl::work(int noutput_items, if (errno == EINTR) continue; else { - perror("file_descriptor_sink"); + GR_LOG_ERROR(d_logger, strerror(errno)); return -1; // indicate we're done } } else { diff --git a/gr-blocks/lib/file_descriptor_source_impl.cc b/gr-blocks/lib/file_descriptor_source_impl.cc index 36c761108b..33f317103f 100644 --- a/gr-blocks/lib/file_descriptor_source_impl.cc +++ b/gr-blocks/lib/file_descriptor_source_impl.cc @@ -107,7 +107,9 @@ int file_descriptor_source_impl::work(int noutput_items, if (errno == EINTR) continue; else { - perror("file_descriptor_source[read]"); + GR_LOG_ERROR(d_logger, + boost::format("file_descriptor_source[read]: %s") % + strerror(errno)); return -1; } } else if (r == 0) { // end of file @@ -116,7 +118,9 @@ int file_descriptor_source_impl::work(int noutput_items, else { flush_residue(); if (lseek(d_fd, 0, SEEK_SET) == -1) { - perror("file_descriptor_source[lseek]"); + GR_LOG_ERROR(d_logger, + boost::format("file_descriptor_source[lseek]: %s") % + strerror(errno)); return -1; } } diff --git a/gr-blocks/lib/file_meta_sink_impl.cc b/gr-blocks/lib/file_meta_sink_impl.cc index 783e18de81..24ae787747 100644 --- a/gr-blocks/lib/file_meta_sink_impl.cc +++ b/gr-blocks/lib/file_meta_sink_impl.cc @@ -155,7 +155,7 @@ bool file_meta_sink_impl::_open(FILE** fp, const char* filename) if ((fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC | OUR_O_LARGEFILE | OUR_O_BINARY, 0664)) < 0) { - perror(filename); + GR_LOG_ERROR(d_logger, boost::format("%s: %s") % filename % strerror(errno)); return false; } @@ -165,7 +165,7 @@ bool file_meta_sink_impl::_open(FILE** fp, const char* filename) } if ((*fp = fdopen(fd, "wb")) == NULL) { - perror(filename); + GR_LOG_ERROR(d_logger, boost::format("%s: %s") % filename % strerror(errno)); ::close(fd); // don't leak file descriptor if fdopen fails. } diff --git a/gr-blocks/lib/file_meta_source_impl.cc b/gr-blocks/lib/file_meta_source_impl.cc index 5f114a3182..e5d7f5a46a 100644 --- a/gr-blocks/lib/file_meta_source_impl.cc +++ b/gr-blocks/lib/file_meta_source_impl.cc @@ -263,7 +263,7 @@ bool file_meta_source_impl::_open(FILE** fp, const char* filename) int fd; if ((fd = ::open(filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0) { - perror(filename); + GR_LOG_ERROR(d_logger, boost::format("%s: %s") % filename % strerror(errno)); return false; } @@ -273,7 +273,7 @@ bool file_meta_source_impl::_open(FILE** fp, const char* filename) } if ((*fp = fdopen(fd, "rb")) == NULL) { - perror(filename); + GR_LOG_ERROR(d_logger, boost::format("%s: %s") % filename % strerror(errno)); ::close(fd); // don't leak file descriptor if fdopen fails. } diff --git a/gr-blocks/lib/file_sink_base.cc b/gr-blocks/lib/file_sink_base.cc index 75891c15b9..22dfe0dd5e 100644 --- a/gr-blocks/lib/file_sink_base.cc +++ b/gr-blocks/lib/file_sink_base.cc @@ -13,6 +13,7 @@ #endif #include <gnuradio/blocks/file_sink_base.h> +#include <gnuradio/logger.h> #include <gnuradio/thread/thread.h> #include <fcntl.h> #include <stdio.h> @@ -46,6 +47,7 @@ file_sink_base::file_sink_base(const char* filename, bool is_binary, bool append { if (!open(filename)) throw std::runtime_error("can't open file"); + gr::configure_default_loggers(d_logger, d_debug_logger, "file_sink_base"); } file_sink_base::~file_sink_base() @@ -64,13 +66,14 @@ bool file_sink_base::open(const char* filename) // we use the open system call to get access to the O_LARGEFILE flag. int fd; int flags; + if (d_append) { flags = O_WRONLY | O_CREAT | O_APPEND | OUR_O_LARGEFILE | OUR_O_BINARY; } else { flags = O_WRONLY | O_CREAT | O_TRUNC | OUR_O_LARGEFILE | OUR_O_BINARY; } if ((fd = ::open(filename, flags, 0664)) < 0) { - perror(filename); + GR_LOG_ERROR(d_logger, boost::format("%s: %s") % filename % strerror(errno)); return false; } if (d_new_fp) { // if we've already got a new one open, close it @@ -79,7 +82,7 @@ bool file_sink_base::open(const char* filename) } if ((d_new_fp = fdopen(fd, d_is_binary ? "wb" : "w")) == NULL) { - perror(filename); + GR_LOG_ERROR(d_logger, boost::format("%s: %s") % filename % strerror(errno)); ::close(fd); // don't leak file descriptor if fdopen fails. } diff --git a/gr-blocks/lib/stream_pdu_base.cc b/gr-blocks/lib/stream_pdu_base.cc index cd4d6c71a7..988c70aca9 100644 --- a/gr-blocks/lib/stream_pdu_base.cc +++ b/gr-blocks/lib/stream_pdu_base.cc @@ -23,6 +23,7 @@ #include "stream_pdu_base.h" #include <gnuradio/basic_block.h> #include <gnuradio/blocks/pdu.h> +#include <gnuradio/logger.h> #include <boost/format.hpp> static const long timeout_us = 100 * 1000; // 100ms @@ -32,6 +33,7 @@ namespace blocks { stream_pdu_base::stream_pdu_base(int MTU) : d_fd(-1), d_started(false), d_finished(false) { + gr::configure_default_loggers(d_pdu_logger, d_pdu_debug_logger, "stream_pdu_base"); // reserve space for rx buffer d_rxbuf.resize(MTU, 0); } @@ -98,10 +100,9 @@ void stream_pdu_base::send(pmt::pmt_t msg) const int rv = write(d_fd, pmt::uniform_vector_elements(vector, offset), len); if (rv != len) { - std::cerr << boost::format("WARNING: stream_pdu_base::send(pdu) write failed! " - "(d_fd=%d, len=%d, rv=%d)") % - d_fd % len % rv - << std::endl; + static auto msg = boost::format( + "stream_pdu_base::send(pdu) write failed! (d_fd=%d, len=%d, rv=%d)"); + GR_LOG_WARN(d_pdu_logger, msg % d_fd % len % rv); } } diff --git a/gr-blocks/lib/stream_pdu_base.h b/gr-blocks/lib/stream_pdu_base.h index 0bd9094ddc..9ca1f32043 100644 --- a/gr-blocks/lib/stream_pdu_base.h +++ b/gr-blocks/lib/stream_pdu_base.h @@ -12,6 +12,7 @@ #define INCLUDED_STREAM_PDU_BASE_H #include <gnuradio/basic_block.h> +#include <gnuradio/logger.h> #include <gnuradio/thread/thread.h> #include <pmt/pmt.h> @@ -41,6 +42,8 @@ protected: bool wait_ready(); void start_rxthread(basic_block* blk, pmt::pmt_t rxport); void stop_rxthread(); + + gr::logger_ptr d_pdu_logger, d_pdu_debug_logger; }; } /* namespace blocks */ diff --git a/gr-blocks/lib/tagged_file_sink_impl.cc b/gr-blocks/lib/tagged_file_sink_impl.cc index 92f9d685ad..7003293a08 100644 --- a/gr-blocks/lib/tagged_file_sink_impl.cc +++ b/gr-blocks/lib/tagged_file_sink_impl.cc @@ -153,14 +153,18 @@ int tagged_file_sink_impl::work(int noutput_items, O_WRONLY | O_CREAT | O_TRUNC | OUR_O_LARGEFILE | OUR_O_BINARY, 0664)) < 0) { - perror(filename.str().c_str()); + GR_LOG_ERROR(d_logger, + boost::format("::open %s: %s") % filename.str() % + strerror(errno)); return -1; } // FIXME: // if((d_handle = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL) { if ((d_handle = fdopen(fd, "wb")) == NULL) { - perror(filename.str().c_str()); + GR_LOG_ERROR(d_logger, + boost::format("fdopen %s: %s") % filename.str() % + strerror(errno)); ::close(fd); // don't leak file descriptor if fdopen fails. } @@ -187,7 +191,9 @@ int tagged_file_sink_impl::work(int noutput_items, &inbuf[d_itemsize * idx], d_itemsize, idx_stop - idx, d_handle); if (count == 0) { if (ferror(d_handle)) { - perror("tagged_file_sink: error writing file"); + GR_LOG_ERROR(d_logger, + boost::format("writing file(1): %s") % + strerror(errno)); } } idx = idx_stop; @@ -204,7 +210,9 @@ int tagged_file_sink_impl::work(int noutput_items, &inbuf[d_itemsize * idx], d_itemsize, noutput_items - idx, d_handle); if (count == 0) { if (ferror(d_handle)) { - perror("tagged_file_sink: error writing file"); + GR_LOG_ERROR(d_logger, + boost::format("writing file(2): %s") % + strerror(errno)); } } idx = noutput_items; diff --git a/gr-blocks/lib/tuntap_pdu_impl.cc b/gr-blocks/lib/tuntap_pdu_impl.cc index 83e861ff94..e5e7569077 100644 --- a/gr-blocks/lib/tuntap_pdu_impl.cc +++ b/gr-blocks/lib/tuntap_pdu_impl.cc @@ -63,12 +63,14 @@ tuntap_pdu_impl::tuntap_pdu_impl(std::string dev, int MTU, bool istunflag) "gr::tuntap_pdu::make: tun_alloc failed (are you running as root?)"); int err = set_mtu(dev_cstr, MTU); - if (err < 0) - std::cerr << boost::format("gr::tuntap_pdu: failed to set MTU to %d.\n" - "You should use ifconfig to set the MTU. E.g.,\n" - " $ sudo ifconfig %s mtu %d\n") % - MTU % dev % MTU - << std::endl; + if (err < 0) { + std::ostringstream msg; + msg << boost::format("failed to set MTU to %d. You should use ifconfig to set " + "the MTU. E.g., `$ sudo ifconfig %s mtu %d`") % + MTU % dev % MTU; + GR_LOG_ERROR(d_logger, msg.str()); + } + std::cout << boost::format("Allocated virtual ethernet interface: %s\n" "You must now use ifconfig to set its IP address. E.g.,\n" diff --git a/gr-blocks/lib/wavfile_sink_impl.cc b/gr-blocks/lib/wavfile_sink_impl.cc index 8732ee881e..69fb8d826d 100644 --- a/gr-blocks/lib/wavfile_sink_impl.cc +++ b/gr-blocks/lib/wavfile_sink_impl.cc @@ -97,7 +97,8 @@ bool wavfile_sink_impl::open(const char* filename) if ((fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC | OUR_O_LARGEFILE | OUR_O_BINARY, 0664)) < 0) { - perror(filename); + GR_LOG_ERROR(d_logger, + boost::format("::open: %s: %s") % filename % strerror(errno)); return false; } @@ -107,14 +108,16 @@ bool wavfile_sink_impl::open(const char* filename) } if ((d_new_fp = fdopen(fd, "wb")) == NULL) { - perror(filename); + GR_LOG_ERROR(d_logger, + boost::format("fdopen: %s: %s") % filename % strerror(errno)); ::close(fd); // don't leak file descriptor if fdopen fails. return false; } d_updated = true; if (!wavheader_write(d_new_fp, d_sample_rate, d_nchans, d_bytes_per_sample_new)) { - fprintf(stderr, "[%s] could not write to WAV file\n", __FILE__); + GR_LOG_ERROR(d_logger, + boost::format("could not write to WAV file: %s") % strerror(errno)) exit(-1); } @@ -184,7 +187,8 @@ int wavfile_sink_impl::work(int noutput_items, wav_write_sample(d_fp, sample_buf_s, d_bytes_per_sample); if (feof(d_fp) || ferror(d_fp)) { - fprintf(stderr, "[%s] file i/o error\n", __FILE__); + GR_LOG_ERROR(d_logger, + boost::format("file i/o error %s") % strerror(errno)); close(); exit(-1); } diff --git a/gr-blocks/lib/wavfile_source_impl.cc b/gr-blocks/lib/wavfile_source_impl.cc index ad1853e1ae..0bd1209757 100644 --- a/gr-blocks/lib/wavfile_source_impl.cc +++ b/gr-blocks/lib/wavfile_source_impl.cc @@ -59,13 +59,15 @@ wavfile_source_impl::wavfile_source_impl(const char* filename, bool repeat) // we use "open" to use to the O_LARGEFILE flag int fd; - if ((fd = open(filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0) { - perror(filename); + if ((fd = ::open(filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0) { + GR_LOG_ERROR(d_logger, + boost::format("::open: %s: %s") % filename % strerror(errno)); throw std::runtime_error("can't open file"); } if ((d_fp = fdopen(fd, "rb")) == NULL) { - perror(filename); + GR_LOG_ERROR(d_logger, + boost::format("fdopen: %s: %s") % filename % strerror(errno)); throw std::runtime_error("can't open file"); } @@ -123,7 +125,8 @@ int wavfile_source_impl::work(int noutput_items, } if (fseek(d_fp, d_first_sample_pos, SEEK_SET) == -1) { - fprintf(stderr, "[%s] fseek failed\n", __FILE__); + GR_LOG_ERROR(d_logger, + boost::format("fseek failed %s") % strerror(errno)); exit(-1); } @@ -145,9 +148,9 @@ int wavfile_source_impl::work(int noutput_items, // trouble they won't be processed. Serves them bloody right. if (feof(d_fp) || ferror(d_fp)) { if (i == 0) { - fprintf(stderr, - "[%s] WAV file has corrupted header or i/o error\n", - __FILE__); + GR_LOG_ERROR(d_logger, + boost::format("WAV file has corrupted header or i/o error") % + strerror(errno)); return -1; } return i; |