Skip to content

Commit

Permalink
Signal manager logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Apr 14, 2024
1 parent 1b23f51 commit f9ea8fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions nano/lib/logging_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enum class type
rep_tiers,
syn_cookies,
thread_runner,
signal_manager,

// bootstrap
bulk_pull_client,
Expand Down
17 changes: 9 additions & 8 deletions nano/lib/signal_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ void nano::signal_manager::register_signal_handler (int signum, std::function<vo
nano::signal_manager::base_handler (descriptor, error, signum);
});

log (boost::str (boost::format ("Registered signal handler for signal %d") % signum));
logger.debug (nano::log::type::signal_manager, "Registered signal handler for signal: {}", to_signal_name (signum));
}

void nano::signal_manager::base_handler (nano::signal_manager::signal_descriptor descriptor, boost::system::error_code const & error, int signum)
void nano::signal_manager::base_handler (nano::signal_manager::signal_descriptor descriptor, boost::system::error_code const & ec, int signum)
{
if (!error)
auto & logger = descriptor.sigman.logger;

if (!ec)
{
descriptor.sigman.log (boost::str (boost::format ("Signal received: %d") % signum));
logger.debug (nano::log::type::signal_manager, "Signal received: {}", to_signal_name (signum));

// call the user supplied function, if one is provided
if (descriptor.handler_func)
Expand All @@ -70,14 +72,13 @@ void nano::signal_manager::base_handler (nano::signal_manager::signal_descriptor
}
else
{
descriptor.sigman.log (boost::str (boost::format ("Signal handler %d will not repeat") % signum));
logger.debug (nano::log::type::signal_manager, "Signal handler {} will not repeat", to_signal_name (signum));

descriptor.sigset->clear ();
}

descriptor.sigman.log (boost::str (boost::format ("Signal processed: %d") % signum));
}
else
{
descriptor.sigman.log (boost::str (boost::format ("Signal error: %d (%s)") % error.value () % error.message ()));
logger.debug (nano::log::type::signal_manager, "Signal error: {} ({})", ec.message (), to_signal_name (signum));
}
}
9 changes: 3 additions & 6 deletions nano/lib/signal_manager.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <nano/lib/logging.hpp>
#include <nano/lib/utility.hpp>

#include <boost/asio.hpp>
Expand Down Expand Up @@ -51,18 +52,14 @@ class signal_manager final
bool repeat;
};

/**
* Logging function of signal manager. It does nothing at the moment, it throws away the log.
* I expect to revisit this in the future. It also makes it easy to manually introduce logs, if needed temporarily.
*/
void log (std::string const &){};

/**
* This is the actual handler that is registered with boost asio.
* It calls the caller supplied function (if one is given) and sets the handler to repeat (or not).
*/
static void base_handler (nano::signal_manager::signal_descriptor descriptor, boost::system::error_code const & error, int signum);

nano::logger logger;

/** boost asio context to use */
boost::asio::io_context ioc;

Expand Down

0 comments on commit f9ea8fe

Please sign in to comment.