Skip to content

Commit

Permalink
#20 Update microservice logs
Browse files Browse the repository at this point in the history
  • Loading branch information
securesocketfunneling committed Sep 4, 2016
1 parent b385256 commit 615c84e
Show file tree
Hide file tree
Showing 21 changed files with 166 additions and 153 deletions.
2 changes: 1 addition & 1 deletion src/core/client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ int main(int argc, char** argv) {
if (p_service.get() != nullptr) {
if (ec) {
SSF_LOG(kLogError) << "client: service <" << p_service->GetName()
<< "> NOK";
<< "> KO";
} else {
SSF_LOG(kLogInfo) << "client: service <" << p_service->GetName()
<< "> OK";
Expand Down
2 changes: 1 addition & 1 deletion src/core/command_line/standard/command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void CommandLine::PopulateLocalOptions(OptionDescription& local_opts) {
local_opts.add_options()
("status,S",
boost::program_options::bool_switch()->default_value(false),
"Display micro services statuses (on/off)");
"Display micro services status (on/off)");
// clang-format on
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TransportProtocolPolicy {
TransportProtocolPolicy(Callback callback) : callback_(callback) {}

void DoSSFInitiate(SocketPtr p_socket) {
SSF_LOG(kLogInfo) << "transport: starting SSF protocol";
SSF_LOG(kLogDebug) << "transport: starting SSF protocol";

uint32_t version = GetVersion();
auto p_ssf_request = std::make_shared<SSFRequest>(version);
Expand Down Expand Up @@ -81,7 +81,7 @@ class TransportProtocolPolicy {
void DoSSFValidReceive(SSFRequestPtr p_ssf_request, SocketPtr p_socket,
const boost::system::error_code& ec, size_t length) {
if (!ec) {
SSF_LOG(kLogInfo) << "transport: SSF request sent";
SSF_LOG(kLogDebug) << "transport: SSF request sent";

auto p_ssf_reply = std::make_shared<SSFReply>();

Expand All @@ -101,7 +101,7 @@ class TransportProtocolPolicy {
size_t length) {
if (!ec) {
if (p_ssf_reply->result()) {
SSF_LOG(kLogInfo) << "transport: SSF reply OK";
SSF_LOG(kLogDebug) << "transport: SSF reply OK";
callback_(p_socket, ec);
} else {
boost::system::error_code result_ec(::error::wrong_protocol_type,
Expand Down
8 changes: 6 additions & 2 deletions src/services/admin/admin.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ void Admin<Demux>::InitializeRemoteServices(

// If something went wrong remote_all_started_ > 0
if (remote_all_started_) {
SSF_LOG(kLogWarning) << "service[admin]: remote could not start";
SSF_LOG(kLogError) << "service[admin]: could not start remote "
"microservice for service["
<< user_services_[i_]->GetName() << "]";

Notify(ssf::services::initialisation::SERVICE, user_services_[i_],
boost::system::error_code(::error::operation_canceled,
Expand All @@ -183,7 +185,9 @@ void Admin<Demux>::InitializeRemoteServices(

// If something went wrong local_all_started_ == false
if (!local_all_started_) {
SSF_LOG(kLogWarning) << "service[admin]: local could not start";
SSF_LOG(kLogError) << "service[admin]: could not start local "
"microservice for service["
<< user_services_[i_]->GetName() << "]";

Notify(ssf::services::initialisation::SERVICE, user_services_[i_],
boost::system::error_code(::error::operation_canceled,
Expand Down
9 changes: 5 additions & 4 deletions src/services/copy_file/fiber_to_file/fiber_to_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ class FiberToFile : public BaseService<Demux> {
// Start service and listen new fiber on demux port kServicePort
virtual void start(boost::system::error_code& ec) {
endpoint ep(this->get_demux(), kServicePort);
SSF_LOG(kLogInfo) << "service[fiber to file]: start accept on fiber port "
<< kServicePort;
SSF_LOG(kLogInfo)
<< "microservice[fiber to file]: start accept on fiber port "
<< kServicePort;
fiber_acceptor_.bind(ep, ec);
fiber_acceptor_.listen(boost::asio::socket_base::max_connections, ec);
if (ec) {
Expand All @@ -58,7 +59,7 @@ class FiberToFile : public BaseService<Demux> {

// Stop service
virtual void stop(boost::system::error_code& ec) {
SSF_LOG(kLogInfo) << "service[fiber to file]: stopping";
SSF_LOG(kLogInfo) << "microservice[fiber to file]: stopping";
manager_.stop_all();
fiber_acceptor_.close(ec);
fiber_.close(ec);
Expand Down Expand Up @@ -99,7 +100,7 @@ class FiberToFile : public BaseService<Demux> {
// Create a session to transmit files for the new connection
void StartDataForwarderSessionHandler(const boost::system::error_code& ec) {
if (ec) {
SSF_LOG(kLogInfo) << "service[fiber to file]: fail accept fiber";
SSF_LOG(kLogInfo) << "microservice[fiber to file]: fail accept fiber";
return;
}

Expand Down
5 changes: 2 additions & 3 deletions src/services/copy_file/file_enquirer/file_enquirer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ class FileEnquirer : public BaseService<Demux> {
}

reenter(coroutine_) {
SSF_LOG(kLogDebug)
<< "service[file enquirer]: connect to remote fiber acceptor port "
<< remote_endpoint_.port();
SSF_LOG(kLogDebug) << "microservice[file enquirer]: connect to remote "
"fiber acceptor port " << remote_endpoint_.port();

yield fiber_.async_connect(
remote_endpoint_,
Expand Down
16 changes: 9 additions & 7 deletions src/services/copy_file/file_to_fiber/file_to_fiber.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ class FileToFiber : public BaseService<Demux> {

if (accept_) {
endpoint ep(this->get_demux(), kServicePort);
SSF_LOG(kLogInfo) << "service[file to fiber]: start accept on fiber port "
<< kServicePort;
SSF_LOG(kLogInfo)
<< "microservice[file to fiber]: start accept on fiber port "
<< kServicePort;
fiber_acceptor_.bind(ep, ec);
fiber_acceptor_.listen(boost::asio::socket_base::max_connections, ec);
if (ec) {
Expand All @@ -104,7 +105,7 @@ class FileToFiber : public BaseService<Demux> {

// Stop service
virtual void stop(boost::system::error_code& ec) {
SSF_LOG(kLogInfo) << "service[file to fiber]: stopping";
SSF_LOG(kLogInfo) << "microservice[file to fiber]: stopping";
manager_.stop_all();
boost::system::error_code close_ec;
fiber_acceptor_.close(close_ec);
Expand Down Expand Up @@ -282,7 +283,7 @@ class FileToFiber : public BaseService<Demux> {
std::make_shared<fiber>(this->get_demux().get_io_service());

SSF_LOG(kLogDebug)
<< "service[file to fiber]: connect to remote fiber acceptor port "
<< "microservice[file to fiber]: connect to remote fiber acceptor port "
<< ssf::services::copy_file::fiber_to_file::FiberToFile<
Demux>::kServicePort;

Expand Down Expand Up @@ -310,11 +311,12 @@ class FileToFiber : public BaseService<Demux> {

if (from_stdin) {
SSF_LOG(kLogInfo)
<< "service[file to fiber]: start forward data from stdin to "
<< "microservice[file to fiber]: start forward data from stdin to "
<< output_file;
} else {
SSF_LOG(kLogInfo) << "service[file to fiber]: start forward data from "
<< input_file << " to " << output_file;
SSF_LOG(kLogInfo)
<< "microservice[file to fiber]: start forward data from "
<< input_file << " to " << output_file;
}

if (!from_stdin) {
Expand Down
24 changes: 13 additions & 11 deletions src/services/datagrams_to_fibers/datagrams_to_fibers.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DatagramsToFibers<Demux>::DatagramsToFibers(boost::asio::io_service& io_service,
template <typename Demux>
void DatagramsToFibers<Demux>::start(boost::system::error_code& ec) {
SSF_LOG(kLogInfo)
<< "service[datagrams to fibers]: starting relay on local port udp "
<< "microservice[datagrams to fibers]: start forwarding local UDP port "
<< local_port_;

boost::asio::ip::udp::resolver resolver(socket_.get_io_service());
Expand All @@ -33,9 +33,8 @@ void DatagramsToFibers<Demux>::start(boost::system::error_code& ec) {
auto ep_it = resolver.resolve(query, ec);

if (ec) {
SSF_LOG(kLogError)
<< "service[datagrams to fibers]: could not resolve query <localhost, "
<< local_port_ << ">";
SSF_LOG(kLogError) << "microservice[datagrams to fibers]: could not "
"resolve query <localhost, " << local_port_ << ">";
return;
}

Expand All @@ -44,22 +43,24 @@ void DatagramsToFibers<Demux>::start(boost::system::error_code& ec) {
boost::system::error_code close_ec;
socket_.open(boost::asio::ip::udp::v4(), ec);
if (ec) {
SSF_LOG(kLogError) << "service[datagrams to fibers]: could not open socket";
SSF_LOG(kLogError)
<< "microservice[datagrams to fibers]: could not open socket";
socket_.close(close_ec);
return;
}
boost::asio::socket_base::reuse_address reuse_address_option(true);
socket_.set_option(reuse_address_option, ec);
if (ec) {
SSF_LOG(kLogError)
<< "service[datagrams to fibers]: could not set reuse address option";
SSF_LOG(kLogError) << "microservice[datagrams to fibers]: could not set "
"reuse address option";
socket_.close(close_ec);
return;
}

socket_.bind(endpoint_, ec);
if (ec) {
SSF_LOG(kLogError) << "service[datagrams to fibers]: could not bind socket";
SSF_LOG(kLogError)
<< "microservice[datagrams to fibers]: could not bind socket";
socket_.close(close_ec);
return;
}
Expand All @@ -71,11 +72,11 @@ void DatagramsToFibers<Demux>::start(boost::system::error_code& ec) {

template <typename Demux>
void DatagramsToFibers<Demux>::stop(boost::system::error_code& ec) {
SSF_LOG(kLogInfo) << "service[datagrams to fibers]: stopping";
SSF_LOG(kLogInfo) << "microservice[datagrams to fibers]: stopping";
socket_.close(ec);

if (ec) {
SSF_LOG(kLogDebug) << "service[datagrams to fibers]: error on stop "
SSF_LOG(kLogDebug) << "microservice[datagrams to fibers]: error on stop "
<< ec.message();
}

Expand All @@ -89,7 +90,8 @@ uint32_t DatagramsToFibers<Demux>::service_type_id() {

template <typename Demux>
void DatagramsToFibers<Demux>::StartReceivingDatagrams() {
SSF_LOG(kLogTrace) << "service[datagrams to fibers]: receiving new datagrams";
SSF_LOG(kLogTrace)
<< "microservice[datagrams to fibers]: receiving new datagrams";

socket_.async_receive_from(
boost::asio::buffer(working_buffer_), endpoint_,
Expand Down
11 changes: 6 additions & 5 deletions src/services/fibers_to_datagrams/fibers_to_datagrams.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ FibersToDatagrams<Demux>::FibersToDatagrams(boost::asio::io_service& io_service,

template <typename Demux>
void FibersToDatagrams<Demux>::start(boost::system::error_code& ec) {
SSF_LOG(kLogInfo)
<< "service[fibers to datagrams]: starting relay on local port udp "
<< local_port_;
SSF_LOG(kLogInfo) << "microservice[fibers to datagrams]: start forwarding "
"fiber datagrams from port " << local_port_ << " to <"
<< ip_ << ":" << remote_port_ << ">";

// fiber.open()
fiber_.bind(datagram_endpoint(this->get_demux(), local_port_), ec);
Expand All @@ -46,7 +46,7 @@ void FibersToDatagrams<Demux>::start(boost::system::error_code& ec) {

template <typename Demux>
void FibersToDatagrams<Demux>::stop(boost::system::error_code& ec) {
SSF_LOG(kLogInfo) << "service[fibers to datagrams]: stopping";
SSF_LOG(kLogInfo) << "microservice[fibers to datagrams]: stopping";
ec.assign(::error::success, ::error::get_ssf_category());

fiber_.close();
Expand All @@ -60,7 +60,8 @@ uint32_t FibersToDatagrams<Demux>::service_type_id() {

template <typename Demux>
void FibersToDatagrams<Demux>::StartReceivingDatagrams() {
SSF_LOG(kLogTrace) << "service[fibers to datagrams]: receiving new datagrams";
SSF_LOG(kLogTrace)
<< "microservice[fibers to datagrams]: receiving new datagrams";

fiber_.async_receive_from(
boost::asio::buffer(working_buffer_), received_from_,
Expand Down
15 changes: 8 additions & 7 deletions src/services/fibers_to_sockets/fibers_to_sockets.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ FibersToSockets<Demux>::FibersToSockets(boost::asio::io_service& io_service,

template <typename Demux>
void FibersToSockets<Demux>::start(boost::system::error_code& ec) {
SSF_LOG(kLogInfo)
<< "service[fibers to sockets]: starting relay on local port tcp "
<< local_port_;
SSF_LOG(kLogInfo) << "microservice[fibers to sockets]: start "
"forwarding stream fiber from port " << local_port_
<< " to <" << ip_ << ":" << remote_port_ << ">";

endpoint ep(this->get_demux(), local_port_);
fiber_acceptor_.bind(ep, ec);
Expand All @@ -49,7 +49,7 @@ void FibersToSockets<Demux>::start(boost::system::error_code& ec) {

template <typename Demux>
void FibersToSockets<Demux>::stop(boost::system::error_code& ec) {
SSF_LOG(kLogInfo) << "service[fibers to sockets]: stopping";
SSF_LOG(kLogInfo) << "microservice[fibers to sockets]: stopping";
ec.assign(::error::success, ::error::get_ssf_category());

fiber_acceptor_.close();
Expand All @@ -63,7 +63,8 @@ uint32_t FibersToSockets<Demux>::service_type_id() {

template <typename Demux>
void FibersToSockets<Demux>::StartAcceptFibers() {
SSF_LOG(kLogTrace) << "service[fibers to sockets]: accepting new clients";
SSF_LOG(kLogTrace)
<< "microservice[fibers to sockets]: accepting new clients";

fiber_acceptor_.async_accept(
fiber_, Then(&FibersToSockets::FiberAcceptHandler, this->SelfFromThis()));
Expand All @@ -72,7 +73,7 @@ void FibersToSockets<Demux>::StartAcceptFibers() {
template <typename Demux>
void FibersToSockets<Demux>::FiberAcceptHandler(
const boost::system::error_code& ec) {
SSF_LOG(kLogTrace) << "service[fibers to sockets]: accept handler";
SSF_LOG(kLogTrace) << "microservice[fibers to sockets]: accept handler";

if (!fiber_acceptor_.is_open()) {
return;
Expand All @@ -88,7 +89,7 @@ void FibersToSockets<Demux>::FiberAcceptHandler(
template <typename Demux>
void FibersToSockets<Demux>::SocketConnectHandler(
const boost::system::error_code& ec) {
SSF_LOG(kLogTrace) << "service[fibers to sockets]: connect handler";
SSF_LOG(kLogTrace) << "microservice[fibers to sockets]: connect handler";

if (!ec) {
auto session = SessionForwarder<fiber, socket>::create(
Expand Down
21 changes: 10 additions & 11 deletions src/services/process/posix/session.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ Session<Demux>::Session(SessionManager* p_session_manager, fiber client,

template <typename Demux>
void Session<Demux>::start(boost::system::error_code& ec) {
SSF_LOG(kLogInfo) << "session[process]: start";
SSF_LOG(kLogInfo) << "session[shell]: start";
int master_tty;
int slave_tty;

InitMasterSlaveTty(&master_tty, &slave_tty, ec);

if (ec) {
SSF_LOG(kLogError) << "session[process]: init tty failed";
SSF_LOG(kLogError) << "session[shell]: init tty failed";
stop(ec);
return;
}

signal_.add(SIGCHLD, ec);
if (ec) {
SSF_LOG(kLogError)
<< "session[process]: init signal handler on SIGCHLD failed";
<< "session[shell]: init signal handler on SIGCHLD failed";
stop(ec);
return;
}

child_pid_ = fork();
if (child_pid_ < 0) {
SSF_LOG(kLogError) << "session[process]: fork failed";
SSF_LOG(kLogError) << "session[shell]: fork failed";
ec.assign(::error::process_not_created, ::error::get_ssf_category());
stop(ec);
return;
Expand All @@ -78,7 +78,7 @@ void Session<Demux>::start(boost::system::error_code& ec) {

tcgetattr(slave_tty, &new_term_settings);
// IGNCR: ignore carriage return on input
new_term_settings.c_iflag |= ( IGNCR );
new_term_settings.c_iflag |= (IGNCR);
tcsetattr(slave_tty, TCSANOW, &new_term_settings);

// new process as session leader
Expand Down Expand Up @@ -138,11 +138,11 @@ void Session<Demux>::start(boost::system::error_code& ec) {

template <typename Demux>
void Session<Demux>::stop(boost::system::error_code& ec) {
SSF_LOG(kLogInfo) << "session[process]: stop";
SSF_LOG(kLogInfo) << "session[shell]: stop";

client_.close();
if (ec) {
SSF_LOG(kLogError) << "session[process]: stop error " << ec.message();
SSF_LOG(kLogError) << "session[shell]: stop error " << ec.message();
}

if (child_pid_ > 0) {
Expand Down Expand Up @@ -253,7 +253,7 @@ void Session<Demux>::InitMasterSlaveTty(int* p_master_tty, int* p_slave_tty,
// open an available pseudo terminal device (master/slave pair)
*p_master_tty = posix_openpt(O_RDWR | O_NOCTTY);
if (*p_master_tty < 0) {
SSF_LOG(kLogError) << "session[process]: could not open master tty";
SSF_LOG(kLogError) << "session[shell]: could not open master tty";
ec.assign(::error::broken_pipe, ::error::get_ssf_category());
return;
}
Expand All @@ -273,7 +273,7 @@ void Session<Demux>::InitMasterSlaveTty(int* p_master_tty, int* p_slave_tty,
// open slave side
*p_slave_tty = open(ptsname(*p_master_tty), O_RDWR | O_NOCTTY);
if (*p_slave_tty < 0) {
SSF_LOG(kLogError) << "session[process]: could not open slave tty";
SSF_LOG(kLogError) << "session[shell]: could not open slave tty";
ec.assign(::error::broken_pipe, ::error::get_ssf_category());
return;
}
Expand All @@ -283,8 +283,7 @@ template <typename Demux>
void Session<Demux>::StartForwarding(boost::system::error_code& ec) {
sd_.assign(master_tty_, ec);
if (ec) {
SSF_LOG(kLogError)
<< "session[process]: could not initialize stream handle";
SSF_LOG(kLogError) << "session[shell]: could not initialize stream handle";
return;
}

Expand Down
Loading

0 comments on commit 615c84e

Please sign in to comment.