Logging is easier now, assigned in runtime group is now stored in config
This commit is contained in:
parent
7f57cd3bf6
commit
1bda854139
19 changed files with 153 additions and 53 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "connection.h"
|
||||
|
||||
Connection::Connection(const std::shared_ptr<Core>& core):
|
||||
Shared::Loggable(core->logger, {"Connection"}),
|
||||
state(initial),
|
||||
core(core),
|
||||
gloox()
|
||||
|
@ -21,7 +22,7 @@ void Connection::initialize() {
|
|||
gloox->registerConnectionListener(this);
|
||||
gloox->registerMessageHandler(this);
|
||||
|
||||
::gloox::LogLevel level = Logger::convert(core->config.getLogLevel());
|
||||
::gloox::LogLevel level = Shared::Logger::convert(core->config.getLogLevel());
|
||||
gloox->logInstance().registerLogHandler(level, gloox::LogAreaAll, &core->logger);
|
||||
|
||||
gloox::Disco* disco = gloox->disco();
|
||||
|
@ -39,7 +40,7 @@ void Connection::deinitialize() {
|
|||
if (state == initial)
|
||||
return;
|
||||
|
||||
core->logger.log(Logger::debug, "deinitializing", {"Connection"});
|
||||
debug("deinitializing");
|
||||
gloox->logInstance().removeLogHandler(&core->logger);
|
||||
|
||||
gloox->removeMessageHandler(this);
|
||||
|
@ -53,14 +54,14 @@ void Connection::connect() {
|
|||
if (state != disconnected)
|
||||
return;
|
||||
|
||||
core->logger.log(Logger::debug, "connecting", {"Connection"});
|
||||
debug("connecting");
|
||||
state = connected;
|
||||
gloox->connect(true);
|
||||
state = disconnected;
|
||||
}
|
||||
|
||||
void Connection::send(const std::string& jid, const std::string& body) {
|
||||
core->logger.log(Logger::debug, "sending message \"" + body + "\" to " + jid, {"Connection"});
|
||||
debug("sending message \"" + body + "\" to " + jid);
|
||||
gloox->send(gloox::Message(gloox::Message::Chat, jid, body));
|
||||
}
|
||||
|
||||
|
@ -73,12 +74,12 @@ void Connection::handleMessage(const gloox::Message& message, gloox::MessageSess
|
|||
return;
|
||||
|
||||
std::string jid = message.from().bare();
|
||||
core->logger.log(Logger::debug, "received message \"" + body + "\" from " + jid, {"Connection"});
|
||||
debug("received message \"" + body + "\" from " + jid);
|
||||
core->router.routeMessage(jid, body);
|
||||
}
|
||||
|
||||
void Connection::onConnect() {
|
||||
core->logger.log(Logger::info, "connection established", {"Connection"});
|
||||
info("connection established");
|
||||
}
|
||||
void Connection::onDisconnect(gloox::ConnectionError e) {
|
||||
std::string error;
|
||||
|
@ -143,12 +144,12 @@ void Connection::onDisconnect(gloox::ConnectionError e) {
|
|||
}
|
||||
|
||||
if (error.empty())
|
||||
core->logger.log(Logger::info, "disconnected" , {"Connection"});
|
||||
info("disconnected");
|
||||
else
|
||||
core->logger.log(Logger::error, "disconnected: " + error , {"Connection"});
|
||||
Loggable::error("disconnected: " + error);
|
||||
}
|
||||
bool Connection::onTLSConnect(const gloox::CertInfo&) {
|
||||
core->logger.log(Logger::info, "TLS established", {"Connection"});
|
||||
info("TLS established");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,11 @@
|
|||
#include <gloox/connectionlistener.h>
|
||||
#include <gloox/messagehandler.h>
|
||||
|
||||
#include "shared/loggable.h"
|
||||
#include "component/core.h"
|
||||
|
||||
class Connection:
|
||||
private Shared::Loggable,
|
||||
public gloox::ConnectionListener,
|
||||
public gloox::MessageHandler
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue