Commit a4c845ab authored by louiz’'s avatar louiz’

Use the logger everywhere

parent 2662ed89
...@@ -64,6 +64,7 @@ target_link_libraries(logger config) ...@@ -64,6 +64,7 @@ target_link_libraries(logger config)
file(GLOB source_network file(GLOB source_network
src/network/*.[hc]pp) src/network/*.[hc]pp)
add_library(network STATIC ${source_network}) add_library(network STATIC ${source_network})
target_link_libraries(network logger)
# #
## irclib ## irclib
...@@ -71,7 +72,7 @@ add_library(network STATIC ${source_network}) ...@@ -71,7 +72,7 @@ add_library(network STATIC ${source_network})
file(GLOB source_irc file(GLOB source_irc
src/irc/*.[hc]pp) src/irc/*.[hc]pp)
add_library(irc STATIC ${source_irc}) add_library(irc STATIC ${source_irc})
target_link_libraries(irc network utils) target_link_libraries(irc network utils logger)
# #
## xmpplib ## xmpplib
...@@ -79,7 +80,7 @@ target_link_libraries(irc network utils) ...@@ -79,7 +80,7 @@ target_link_libraries(irc network utils)
file(GLOB source_xmpp file(GLOB source_xmpp
src/xmpp/*.[hc]pp) src/xmpp/*.[hc]pp)
add_library(xmpp STATIC ${source_xmpp}) add_library(xmpp STATIC ${source_xmpp})
target_link_libraries(xmpp bridge network utils target_link_libraries(xmpp bridge network utils logger
${CRYPTO++_LIBRARIES} ${EXPAT_LIBRARIES} pthread) ${CRYPTO++_LIBRARIES} ${EXPAT_LIBRARIES} pthread)
# #
...@@ -88,7 +89,7 @@ target_link_libraries(xmpp bridge network utils ...@@ -88,7 +89,7 @@ target_link_libraries(xmpp bridge network utils
file(GLOB source_bridge file(GLOB source_bridge
src/bridge/*.[hc]pp) src/bridge/*.[hc]pp)
add_library(bridge STATIC ${source_bridge}) add_library(bridge STATIC ${source_bridge})
target_link_libraries(bridge xmpp irc utils) target_link_libraries(bridge xmpp irc utils logger)
# #
## Main executable ## Main executable
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <xmpp/xmpp_component.hpp> #include <xmpp/xmpp_component.hpp>
#include <network/poller.hpp> #include <network/poller.hpp>
#include <utils/encoding.hpp> #include <utils/encoding.hpp>
#include <logger/logger.hpp>
#include <utils/split.hpp> #include <utils/split.hpp>
#include <iostream> #include <iostream>
...@@ -78,13 +78,13 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body) ...@@ -78,13 +78,13 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
const std::string first_line = lines[0]; const std::string first_line = lines[0];
if (iid.chan.empty() || iid.server.empty()) if (iid.chan.empty() || iid.server.empty())
{ {
std::cout << "Cannot send message to channel: [" << iid.chan << "] on server [" << iid.server << "]" << std::endl; log_warning("Cannot send message to channel: [" << iid.chan << "] on server [" << iid.server << "]");
return; return;
} }
IrcClient* irc = this->get_irc_client(iid.server); IrcClient* irc = this->get_irc_client(iid.server);
if (!irc) if (!irc)
{ {
std::cout << "Cannot send message: no client exist for server " << iid.server << std::endl; log_warning("Cannot send message: no client exist for server " << iid.server);
return; return;
} }
if (first_line.substr(0, 6) == "/mode ") if (first_line.substr(0, 6) == "/mode ")
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <irc/irc_user.hpp> #include <irc/irc_user.hpp>
#include <utils/make_unique.hpp> #include <utils/make_unique.hpp>
// #include <logger/logger.hpp> #include <logger/logger.hpp>
#include <utils/tolower.hpp> #include <utils/tolower.hpp>
#include <utils/split.hpp> #include <utils/split.hpp>
...@@ -18,12 +18,10 @@ IrcClient::IrcClient(const std::string& hostname, const std::string& username, B ...@@ -18,12 +18,10 @@ IrcClient::IrcClient(const std::string& hostname, const std::string& username, B
bridge(bridge), bridge(bridge),
welcomed(false) welcomed(false)
{ {
std::cout << "IrcClient()" << std::endl;
} }
IrcClient::~IrcClient() IrcClient::~IrcClient()
{ {
std::cout << "~IrcClient()" << std::endl;
} }
void IrcClient::start() void IrcClient::start()
...@@ -39,7 +37,7 @@ void IrcClient::on_connected() ...@@ -39,7 +37,7 @@ void IrcClient::on_connected()
void IrcClient::on_connection_close() void IrcClient::on_connection_close()
{ {
std::cout << "Connection closed by remote server." << std::endl; log_warning("Connection closed by remote server.");
} }
IrcChannel* IrcClient::get_channel(const std::string& name) IrcChannel* IrcClient::get_channel(const std::string& name)
...@@ -74,18 +72,19 @@ void IrcClient::parse_in_buffer() ...@@ -74,18 +72,19 @@ void IrcClient::parse_in_buffer()
if (pos == std::string::npos) if (pos == std::string::npos)
break ; break ;
IrcMessage message(this->in_buf.substr(0, pos)); IrcMessage message(this->in_buf.substr(0, pos));
log_debug("IRC RECEIVING: " << message);
this->in_buf = this->in_buf.substr(pos + 2, std::string::npos); this->in_buf = this->in_buf.substr(pos + 2, std::string::npos);
std::cout << message << std::endl;
auto cb = irc_callbacks.find(message.command); auto cb = irc_callbacks.find(message.command);
if (cb != irc_callbacks.end()) if (cb != irc_callbacks.end())
(this->*(cb->second))(message); (this->*(cb->second))(message);
else else
std::cout << "No handler for command " << message.command << std::endl; log_info("No handler for command " << message.command);
} }
} }
void IrcClient::send_message(IrcMessage&& message) void IrcClient::send_message(IrcMessage&& message)
{ {
log_debug("IRC SENDING: " << message);
std::string res; std::string res;
if (!message.prefix.empty()) if (!message.prefix.empty())
res += ":" + std::move(message.prefix) + " "; res += ":" + std::move(message.prefix) + " ";
...@@ -101,8 +100,6 @@ void IrcClient::send_message(IrcMessage&& message) ...@@ -101,8 +100,6 @@ void IrcClient::send_message(IrcMessage&& message)
res += " " + arg; res += " " + arg;
} }
res += "\r\n"; res += "\r\n";
std::cout << "=== IRC SENDING ===" << std::endl;
std::cout << res << std::endl;
this->send_data(std::move(res)); this->send_data(std::move(res));
} }
...@@ -134,7 +131,7 @@ bool IrcClient::send_channel_message(const std::string& chan_name, const std::st ...@@ -134,7 +131,7 @@ bool IrcClient::send_channel_message(const std::string& chan_name, const std::st
IrcChannel* channel = this->get_channel(chan_name); IrcChannel* channel = this->get_channel(chan_name);
if (channel->joined == false) if (channel->joined == false)
{ {
std::cout << "Cannot send message to channel " << chan_name << ", it is not joined" << std::endl; log_warning("Cannot send message to channel " << chan_name << ", it is not joined");
return false; return false;
} }
this->send_message(IrcMessage("PRIVMSG", {chan_name, body})); this->send_message(IrcMessage("PRIVMSG", {chan_name, body}));
...@@ -185,7 +182,7 @@ void IrcClient::set_and_forward_user_list(const IrcMessage& message) ...@@ -185,7 +182,7 @@ void IrcClient::set_and_forward_user_list(const IrcMessage& message)
IrcUser* user = channel->add_user(nick); IrcUser* user = channel->add_user(nick);
if (user->nick != channel->get_self()->nick) if (user->nick != channel->get_self()->nick)
{ {
std::cout << "Adding user [" << nick << "] to chan " << chan_name << std::endl; log_debug("Adding user [" << nick << "] to chan " << chan_name);
this->bridge->send_user_join(this->hostname, chan_name, user->nick); this->bridge->send_user_join(this->hostname, chan_name, user->nick);
} }
} }
......
...@@ -24,5 +24,4 @@ IrcUser::IrcUser(const std::string& name) ...@@ -24,5 +24,4 @@ IrcUser::IrcUser(const std::string& name)
this->nick = name.substr(0, sep); this->nick = name.substr(0, sep);
this->host = name.substr(sep+1); this->host = name.substr(sep+1);
} }
std::cout << "Created user: [" << this->nick << "!" << this->host << std::endl;
} }
...@@ -6,7 +6,6 @@ Logger::Logger(const int log_level): ...@@ -6,7 +6,6 @@ Logger::Logger(const int log_level):
log_level(log_level), log_level(log_level),
stream(std::cout.rdbuf()) stream(std::cout.rdbuf())
{ {
std::cout << "Logger(1)" << std::endl;
} }
Logger::Logger(const int log_level, const std::string& log_file): Logger::Logger(const int log_level, const std::string& log_file):
...@@ -14,7 +13,6 @@ Logger::Logger(const int log_level, const std::string& log_file): ...@@ -14,7 +13,6 @@ Logger::Logger(const int log_level, const std::string& log_file):
ofstream(log_file.data(), std::ios_base::app), ofstream(log_file.data(), std::ios_base::app),
stream(ofstream.rdbuf()) stream(ofstream.rdbuf())
{ {
std::cout << "Logger(" << this->log_level << ")" << std::endl;
} }
std::unique_ptr<Logger>& Logger::instance() std::unique_ptr<Logger>& Logger::instance()
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
Poller::Poller() Poller::Poller()
{ {
std::cout << "Poller()" << std::endl;
#if POLLER == POLL #if POLLER == POLL
memset(this->fds, 0, sizeof(this->fds)); memset(this->fds, 0, sizeof(this->fds));
this->nfds = 0; this->nfds = 0;
...@@ -24,7 +23,6 @@ Poller::Poller() ...@@ -24,7 +23,6 @@ Poller::Poller()
Poller::~Poller() Poller::~Poller()
{ {
std::cout << "~Poller()" << std::endl;
} }
void Poller::add_socket_handler(std::shared_ptr<SocketHandler> socket_handler) void Poller::add_socket_handler(std::shared_ptr<SocketHandler> socket_handler)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <utils/scopeguard.hpp> #include <utils/scopeguard.hpp>
#include <network/poller.hpp> #include <network/poller.hpp>
#include <logger/logger.hpp>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
...@@ -21,7 +22,7 @@ SocketHandler::SocketHandler(): ...@@ -21,7 +22,7 @@ SocketHandler::SocketHandler():
void SocketHandler::connect(const std::string& address, const std::string& port) void SocketHandler::connect(const std::string& address, const std::string& port)
{ {
std::cout << "Trying to connect to " << address << ":" << port << std::endl; log_info("Trying to connect to " << address << ":" << port);
struct addrinfo hints; struct addrinfo hints;
memset(&hints, 0, sizeof(struct addrinfo)); memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_flags = 0; hints.ai_flags = 0;
...@@ -42,17 +43,16 @@ void SocketHandler::connect(const std::string& address, const std::string& port) ...@@ -42,17 +43,16 @@ void SocketHandler::connect(const std::string& address, const std::string& port)
} }
for (struct addrinfo* rp = addr_res; rp; rp = rp->ai_next) for (struct addrinfo* rp = addr_res; rp; rp = rp->ai_next)
{ {
std::cout << "One result" << std::endl;
if (::connect(this->socket, rp->ai_addr, rp->ai_addrlen) == 0) if (::connect(this->socket, rp->ai_addr, rp->ai_addrlen) == 0)
{ {
std::cout << "Connection success." << std::endl; log_info("Connection success.");
this->on_connected(); this->on_connected();
return ; return ;
} }
std::cout << "Connection failed:" << std::endl; log_info("Connection failed:");
perror("connect"); perror("connect");
} }
std::cout << "All connection attempts failed." << std::endl; log_error("All connection attempts failed.");
this->close(); this->close();
} }
......
#include <utils/make_unique.hpp> #include <utils/make_unique.hpp>
#include <logger/logger.hpp>
#include <xmpp/xmpp_component.hpp> #include <xmpp/xmpp_component.hpp>
#include <xmpp/jid.hpp> #include <xmpp/jid.hpp>
...@@ -52,14 +53,14 @@ void XmppComponent::start() ...@@ -52,14 +53,14 @@ void XmppComponent::start()
void XmppComponent::send_stanza(const Stanza& stanza) void XmppComponent::send_stanza(const Stanza& stanza)
{ {
std::cout << "====== Sending ========" << std::endl; std::string str = stanza.to_string();
std::cout << stanza.to_string() << std::endl; log_debug("XMPP SENDING: " << str);
this->send_data(stanza.to_string()); this->send_data(std::move(str));
} }
void XmppComponent::on_connected() void XmppComponent::on_connected()
{ {
std::cout << "connected to XMPP server" << std::endl; log_info("connected to XMPP server");
XmlNode node("stream:stream", nullptr); XmlNode node("stream:stream", nullptr);
node["xmlns"] = COMPONENT_NS; node["xmlns"] = COMPONENT_NS;
node["xmlns:stream"] = STREAM_NS; node["xmlns:stream"] = STREAM_NS;
...@@ -69,7 +70,7 @@ void XmppComponent::on_connected() ...@@ -69,7 +70,7 @@ void XmppComponent::on_connected()
void XmppComponent::on_connection_close() void XmppComponent::on_connection_close()
{ {
std::cout << "XMPP server closed connection" << std::endl; log_info("XMPP server closed connection");
} }
void XmppComponent::parse_in_buffer() void XmppComponent::parse_in_buffer()
...@@ -80,15 +81,14 @@ void XmppComponent::parse_in_buffer() ...@@ -80,15 +81,14 @@ void XmppComponent::parse_in_buffer()
void XmppComponent::on_remote_stream_open(const XmlNode& node) void XmppComponent::on_remote_stream_open(const XmlNode& node)
{ {
std::cout << "====== DOCUMENT_OPEN =======" << std::endl; log_debug("XMPP DOCUMENT OPEN: " << node.to_string());
std::cout << node.to_string() << std::endl;
try try
{ {
this->stream_id = node["id"]; this->stream_id = node["id"];
} }
catch (const AttributeNotFound& e) catch (const AttributeNotFound& e)
{ {
std::cout << "Error: no attribute 'id' found" << std::endl; log_error("Error: no attribute 'id' found");
this->send_stream_error("bad-format", "missing 'id' attribute"); this->send_stream_error("bad-format", "missing 'id' attribute");
this->close_document(); this->close_document();
return ; return ;
...@@ -109,14 +109,12 @@ void XmppComponent::on_remote_stream_open(const XmlNode& node) ...@@ -109,14 +109,12 @@ void XmppComponent::on_remote_stream_open(const XmlNode& node)
void XmppComponent::on_remote_stream_close(const XmlNode& node) void XmppComponent::on_remote_stream_close(const XmlNode& node)
{ {
std::cout << "====== DOCUMENT_CLOSE =======" << std::endl; log_debug("XMPP DOCUMENT CLOSE " << node.to_string());
std::cout << node.to_string() << std::endl;
} }
void XmppComponent::on_stanza(const Stanza& stanza) void XmppComponent::on_stanza(const Stanza& stanza)
{ {
std::cout << "=========== STANZA ============" << std::endl; log_debug("XMPP RECEIVING: " << stanza.to_string());
std::cout << stanza.to_string() << std::endl;
std::function<void(const Stanza&)> handler; std::function<void(const Stanza&)> handler;
try try
{ {
...@@ -124,7 +122,7 @@ void XmppComponent::on_stanza(const Stanza& stanza) ...@@ -124,7 +122,7 @@ void XmppComponent::on_stanza(const Stanza& stanza)
} }
catch (const std::out_of_range& exception) catch (const std::out_of_range& exception)
{ {
std::cout << "No handler for stanza of type " << stanza.get_name() << std::endl; log_warning("No handler for stanza of type " << stanza.get_name());
return; return;
} }
handler(stanza); handler(stanza);
...@@ -145,8 +143,7 @@ void XmppComponent::send_stream_error(const std::string& name, const std::string ...@@ -145,8 +143,7 @@ void XmppComponent::send_stream_error(const std::string& name, const std::string
void XmppComponent::close_document() void XmppComponent::close_document()
{ {
std::cout << "====== Sending ========" << std::endl; log_debug("XMPP SENDING: </stream:stream>");
std::cout << "</stream:stream>" << std::endl;
this->send_data("</stream:stream>"); this->send_data("</stream:stream>");
} }
......
...@@ -209,11 +209,6 @@ std::string XmlNode::to_string() const ...@@ -209,11 +209,6 @@ std::string XmlNode::to_string() const
return res; return res;
} }
void XmlNode::display() const
{
std::cout << this->to_string() << std::endl;
}
bool XmlNode::has_children() const bool XmlNode::has_children() const
{ {
return !this->children.empty(); return !this->children.empty();
......
...@@ -97,7 +97,6 @@ public: ...@@ -97,7 +97,6 @@ public:
* Serialize the stanza into a string * Serialize the stanza into a string
*/ */
std::string to_string() const; std::string to_string() const;
void display() const;
/** /**
* Whether or not this node has at least one child (if not, this is a leaf * Whether or not this node has at least one child (if not, this is a leaf
* node) * node)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment