Skip to content

Commit

Permalink
Modernize logging in analog, fft, filter, video-sdl and zeromq
Browse files Browse the repository at this point in the history
Signed-off-by: Clayton Smith <[email protected]>
  • Loading branch information
argilo authored and mormj committed Mar 8, 2022
1 parent c59f10c commit b6278eb
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 71 deletions.
13 changes: 6 additions & 7 deletions gr-analog/lib/sig_source_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void sig_source_impl<T>::set_cmd_msg(pmt::pmt_t msg)
} else if (pmt::is_pair(msg)) {
list_of_items = pmt::list1(msg);
} else {
GR_LOG_WARN(this->d_logger, "malformed message: is not dict nor pair");
this->d_logger->warn("malformed message: is not dict nor pair");
return;
}

Expand All @@ -92,29 +92,28 @@ void sig_source_impl<T>::set_cmd_msg(pmt::pmt_t msg)
if (pmt::is_number(val)) {
set_frequency(pmt::to_double(val));
} else {
GR_LOG_WARN(this->d_logger, "frequency value needs to be a number")
this->d_logger->warn("frequency value needs to be a number");
}
} else if (key == ampl_key) {
if (pmt::is_number(val)) {
set_amplitude(pmt::to_double(val));
} else {
GR_LOG_WARN(this->d_logger, "amplitude value needs to be a number")
this->d_logger->warn("amplitude value needs to be a number");
}
} else if (key == phase_key) {
if (pmt::is_number(val)) {
set_phase(pmt::to_double(val));
} else {
GR_LOG_WARN(this->d_logger, "phase value needs to be a number")
this->d_logger->warn("phase value needs to be a number");
}
} else if (key == offset_key) {
if (pmt::is_number(val)) {
set_offset(pmt::to_double(val));
} else {
GR_LOG_WARN(this->d_logger, "offset value needs to be a number")
this->d_logger->warn("offset value needs to be a number");
}
} else {
GR_LOG_WARN(this->d_logger,
"unsupported message key " + pmt::write_string(key));
this->d_logger->warn("unsupported message key {}", key);
}

// advance to next item, if any
Expand Down
4 changes: 1 addition & 3 deletions gr-fft/lib/ctrlport_probe_psd_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ std::vector<gr_complex> ctrlport_probe_psd_impl::get()
void ctrlport_probe_psd_impl::set_length(int len)
{
if (len > 8191) {
std::ostringstream msg;
msg << "length " << len << " exceeds maximum buffer size of 8191";
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error("length {:d} exceeds maximum buffer size of 8191", len);
len = 8191;
}

Expand Down
24 changes: 12 additions & 12 deletions gr-filter/lib/fft_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ void fft_filter_fff::compute_sizes(int ntaps)
d_nsamples = d_fftsize - d_ntaps + 1;

if (VERBOSE) {
std::ostringstream msg;
msg << "fft_filter_fff: ntaps = " << d_ntaps << " fftsize = " << d_fftsize
<< " nsamples = " << d_nsamples;
GR_LOG_ALERT(d_logger, msg.str());
d_logger->alert("fft_filter_fff: ntaps = {:d} fftsize = {:d} nsamples = {:d}",
d_ntaps,
d_fftsize,
d_nsamples);
}

// compute new plans
Expand Down Expand Up @@ -208,10 +208,10 @@ void fft_filter_ccc::compute_sizes(int ntaps)
d_nsamples = d_fftsize - d_ntaps + 1;

if (VERBOSE) {
std::ostringstream msg;
msg << "fft_filter_ccc: ntaps = " << d_ntaps << " fftsize = " << d_fftsize
<< " nsamples = " << d_nsamples;
GR_LOG_ALERT(d_logger, msg.str());
d_logger->alert("fft_filter_ccc: ntaps = {:d} fftsize = {:d} nsamples = {:d}",
d_ntaps,
d_fftsize,
d_nsamples);
}

// compute new plans
Expand Down Expand Up @@ -340,10 +340,10 @@ void fft_filter_ccf::compute_sizes(int ntaps)
d_nsamples = d_fftsize - d_ntaps + 1;

if (VERBOSE) {
std::ostringstream msg;
msg << "fft_filter_ccf: ntaps = " << d_ntaps << " fftsize = " << d_fftsize
<< " nsamples = " << d_nsamples;
GR_LOG_ALERT(d_logger, msg.str());
d_logger->alert("fft_filter_ccf: ntaps = {:d} fftsize = {:d} nsamples = {:d}",
d_ntaps,
d_fftsize,
d_nsamples);
}

// compute new plans
Expand Down
2 changes: 1 addition & 1 deletion gr-filter/lib/pm_remez.cc
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ static int remez(double h[],

static void punt(gr::logger_ptr logger, const std::string msg)
{
GR_LOG_ERROR(logger, msg);
logger->error(msg);
throw std::runtime_error(msg);
}

Expand Down
29 changes: 10 additions & 19 deletions gr-video-sdl/lib/sink_s_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ sink_s_impl::sink_s_impl(

atexit(SDL_Quit); // check if this is the way to do this
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::ostringstream msg;
msg << "Couldn't initialize SDL:" << SDL_GetError()
<< "; SDL_Init(SDL_INIT_VIDEO) failed";
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error("Couldn't initialize SDL: {:s}; SDL_Init(SDL_INIT_VIDEO) failed",
SDL_GetError());
throw std::runtime_error("video_sdl::sink_s");
};

Expand All @@ -79,10 +77,8 @@ sink_s_impl::sink_s_impl(
SDL_ANYFORMAT); // SDL_DOUBLEBUF |SDL_SWSURFACE| SDL_HWSURFACE||SDL_FULLSCREEN

if (d_screen == NULL) {
std::ostringstream msg;
msg << "Unable to set SDL video mode: " << SDL_GetError()
<< "; SDL_SetVideoMode() Failed";
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error("Unable to set SDL video mode: {:s}; SDL_SetVideoMode() Failed",
SDL_GetError());
exit(1);
}
if (d_image) {
Expand All @@ -92,9 +88,7 @@ sink_s_impl::sink_s_impl(
/* Initialize and create the YUV Overlay used for video out */
if (!(d_image =
SDL_CreateYUVOverlay(d_width, d_height, SDL_IYUV_OVERLAY, d_screen))) {
std::ostringstream msg;
msg << "Couldn't create a YUV overlay: " << SDL_GetError();
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error("Couldn't create a YUV overlay: {:s}", SDL_GetError());
throw std::runtime_error("video_sdl::sink_s");
}

Expand All @@ -115,9 +109,7 @@ sink_s_impl::sink_s_impl(
// clear the surface to grey

if (SDL_LockYUVOverlay(d_image)) {
std::ostringstream msg;
msg << "Couldn't lock a YUV overlay:" << SDL_GetError();
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error("Couldn't lock a YUV overlay: {:s}", SDL_GetError());
throw std::runtime_error("video_sdl::sink_s");
}

Expand Down Expand Up @@ -290,11 +282,10 @@ int sink_s_impl::work(int noutput_items,
}
break;
default: // 0 or more then 3 channels
std::ostringstream msg;
msg << "Wrong number of channels: 1, 2 or 3 channels are supported. Requested "
"number of channels is "
<< input_items.size();
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error(
"Wrong number of channels: 1, 2 or 3 channels are supported. Requested "
"number of channels is {:d}",
input_items.size());
throw std::runtime_error("video_sdl::sink_s");
}

Expand Down
29 changes: 10 additions & 19 deletions gr-video-sdl/lib/sink_uc_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ sink_uc_impl::sink_uc_impl(

atexit(SDL_Quit); // check if this is the way to do this
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::ostringstream msg;
msg << "Couldn't initialize SDL:" << SDL_GetError()
<< "; SDL_Init(SDL_INIT_VIDEO) failed";
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error("Couldn't initialize SDL: {:s}; SDL_Init(SDL_INIT_VIDEO) failed",
SDL_GetError());
throw std::runtime_error("video_sdl::sink_uc");
}

Expand All @@ -79,10 +77,8 @@ sink_uc_impl::sink_uc_impl(
SDL_ANYFORMAT); // SDL_DOUBLEBUF |SDL_SWSURFACE| SDL_HWSURFACE||SDL_FULLSCREEN

if (d_screen == NULL) {
std::ostringstream msg;
msg << "Unable to set SDL video mode: " << SDL_GetError()
<< "; SDL_SetVideoMode() Failed";
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error("Unable to set SDL video mode: {:s}; SDL_SetVideoMode() Failed",
SDL_GetError());
exit(1);
}

Expand All @@ -93,9 +89,7 @@ sink_uc_impl::sink_uc_impl(
/* Initialize and create the YUV Overlay used for video out */
if (!(d_image =
SDL_CreateYUVOverlay(d_width, d_height, SDL_IYUV_OVERLAY, d_screen))) {
std::ostringstream msg;
msg << "SDL: Couldn't create a YUV overlay: " << SDL_GetError();
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error("Couldn't create a YUV overlay: {:s}", SDL_GetError());
throw std::runtime_error("video_sdl::sink_uc");
}

Expand All @@ -116,9 +110,7 @@ sink_uc_impl::sink_uc_impl(
// clear the surface to grey

if (SDL_LockYUVOverlay(d_image)) {
std::ostringstream msg;
msg << "SDL: Couldn't lock a YUV overlay: " << SDL_GetError();
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error("Couldn't lock a YUV overlay: {:s}", SDL_GetError());
throw std::runtime_error("video_sdl::sink_uc");
}

Expand Down Expand Up @@ -285,11 +277,10 @@ int sink_uc_impl::work(int noutput_items,
}
break;
default: // 0 or more then 3 channels
std::ostringstream msg;
msg << "Wrong number of channels: 1, 2 or 3 channels are supported. Requested "
"number of channels is "
<< input_items.size();
GR_LOG_ERROR(d_logger, msg.str());
d_logger->error(
"Wrong number of channels: 1, 2 or 3 channels are supported. Requested "
"number of channels is {:d}",
input_items.size());
throw std::runtime_error("video_sdl::sink_uc");
}

Expand Down
4 changes: 2 additions & 2 deletions gr-zeromq/lib/base_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ bool base_source_impl::load_message(bool wait)
if (!ok) {
// This shouldn't happen since we polled POLLIN, but ZMQ wants us to check
// the return value.
GR_LOG_WARN(d_logger, "Failed to recv() message.");
d_logger->warn("Failed to recv() message.");
return false;
}

Expand All @@ -235,7 +235,7 @@ bool base_source_impl::load_message(bool wait)
const bool multi_ok = d_socket.recv(&d_msg);
#endif
if (!multi_ok) {
GR_LOG_ERROR(d_logger, "Failure to receive multi-part message.");
d_logger->error("Failure to receive multi-part message.");
}
} else {
return false;
Expand Down
4 changes: 2 additions & 2 deletions gr-zeromq/lib/pull_msg_source_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void pull_msg_source_impl::readloop()
#endif
if (!ok) {
// Should not happen, we've checked POLLIN.
GR_LOG_ERROR(d_logger, "Failed to receive message.");
d_logger->error("Failed to receive message.");
std::this_thread::sleep_for(100us);
continue;
}
Expand All @@ -103,7 +103,7 @@ void pull_msg_source_impl::readloop()
pmt::pmt_t m = pmt::deserialize(sb);
message_port_pub(d_port, m);
} catch (pmt::exception& e) {
GR_LOG_ERROR(d_logger, std::string("Invalid PMT message: ") + e.what());
d_logger->error("Invalid PMT message: {:s}", e.what());
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion gr-zeromq/lib/rep_msg_sink_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void rep_msg_sink_impl::readloop()
#endif
if (!ok) {
// Should not happen, we've checked POLLIN.
GR_LOG_ERROR(d_logger, "Failed to receive message.");
d_logger->error("Failed to receive message.");
break; // Fall back to re-check d_finished
}

Expand Down
2 changes: 1 addition & 1 deletion gr-zeromq/lib/rep_sink_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int rep_sink_impl::work(int noutput_items,
#endif
if (!ok) {
// Should not happen, we've checked POLLIN.
GR_LOG_ERROR(d_logger, "Failed to receive message.");
d_logger->error("Failed to receive message.");
break;
}

Expand Down
4 changes: 2 additions & 2 deletions gr-zeromq/lib/req_msg_source_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void req_msg_source_impl::readloop()
#endif
if (!ok) {
// Should not happen, we've checked POLLIN.
GR_LOG_ERROR(d_logger, "Failed to receive message.");
d_logger->error("Failed to receive message.");
std::this_thread::sleep_for(100us);
continue;
}
Expand All @@ -121,7 +121,7 @@ void req_msg_source_impl::readloop()
pmt::pmt_t m = pmt::deserialize(sb);
message_port_pub(d_port, m);
} catch (pmt::exception& e) {
GR_LOG_ERROR(d_logger, std::string("Invalid PMT message: ") + e.what());
d_logger->error("Invalid PMT message: {:s}", e.what());
}

} else {
Expand Down
4 changes: 2 additions & 2 deletions gr-zeromq/lib/sub_msg_source_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void sub_msg_source_impl::readloop()
#endif
if (!ok) {
// Should not happen, we've checked POLLIN.
GR_LOG_ERROR(d_logger, "Failed to receive message.");
d_logger->error("Failed to receive message.");
std::this_thread::sleep_for(100us);
continue;
}
Expand All @@ -101,7 +101,7 @@ void sub_msg_source_impl::readloop()
pmt::pmt_t m = pmt::deserialize(sb);
message_port_pub(d_port, m);
} catch (pmt::exception& e) {
GR_LOG_ERROR(d_logger, std::string("Invalid PMT message: ") + e.what());
d_logger->error("Invalid PMT message: {:s}", e.what());
}
} else {
std::this_thread::sleep_for(100us);
Expand Down

0 comments on commit b6278eb

Please sign in to comment.