Logging
This commit is contained in:
parent
89c04254b8
commit
60c8782bdd
7 changed files with 196 additions and 23 deletions
|
@ -21,7 +21,8 @@ void Connection::initiialize() {
|
|||
gloox->registerConnectionListener(this);
|
||||
gloox->registerMessageHandler(this);
|
||||
|
||||
gloox->logInstance().registerLogHandler(core->config.getLogLevel(), gloox::LogAreaAll, &core->logger);
|
||||
::gloox::LogLevel level = Logger::convert(core->config.getLogLevel());
|
||||
gloox->logInstance().registerLogHandler(level, gloox::LogAreaAll, &core->logger);
|
||||
|
||||
gloox::Disco* disco = gloox->disco();
|
||||
disco->setVersion("Jay", "0.0.1");
|
||||
|
@ -38,6 +39,7 @@ void Connection::deinitialize() {
|
|||
if (state == initial)
|
||||
return;
|
||||
|
||||
core->logger.log(Logger::debug, "deinitializing", {"Connection"});
|
||||
gloox->logInstance().removeLogHandler(&core->logger);
|
||||
|
||||
gloox->removeMessageHandler(this);
|
||||
|
@ -51,21 +53,96 @@ void Connection::connect() {
|
|||
if (state != disconnected)
|
||||
return;
|
||||
|
||||
core->logger.log(Logger::debug, "connecting", {"Connection"});
|
||||
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"});
|
||||
gloox->send(gloox::Message(gloox::Message::Chat, jid, body));
|
||||
}
|
||||
|
||||
void Connection::handleMessage(const gloox::Message& message, gloox::MessageSession* session) {
|
||||
core->router.routeMessage(message.from().bare(), message.body());
|
||||
std::string jid = message.from().bare();
|
||||
core->logger.log(Logger::debug, "received message \"" + message.body() + "\" from " + jid, {"Connection"});
|
||||
core->router.routeMessage(jid, message.body());
|
||||
}
|
||||
|
||||
void Connection::onConnect() {}
|
||||
void Connection::onDisconnect(gloox::ConnectionError e) {}
|
||||
bool Connection::onTLSConnect(const gloox::CertInfo&) { return true; }
|
||||
void Connection::onConnect() {
|
||||
core->logger.log(Logger::info, "connection established", {"Connection"});
|
||||
}
|
||||
void Connection::onDisconnect(gloox::ConnectionError e) {
|
||||
std::string error;
|
||||
|
||||
switch (e) {
|
||||
case gloox::ConnNoError:
|
||||
break;
|
||||
case gloox::ConnStreamError: //TODO Use ClientBase::streamError() to find the reason. */
|
||||
error = "stream error occured";
|
||||
break;
|
||||
case gloox::ConnStreamVersionError:
|
||||
error = "incoming stream's version is not supported";
|
||||
break;
|
||||
case gloox::ConnStreamClosed:
|
||||
error = "stream has been closed (by the server)";
|
||||
break;
|
||||
case gloox::ConnProxyAuthRequired:
|
||||
error = "HTTP/SOCKS5 proxy requires authentication";
|
||||
break;
|
||||
case gloox::ConnProxyAuthFailed:
|
||||
error = "HTTP/SOCKS5 proxy authentication failed";
|
||||
break;
|
||||
case gloox::ConnProxyNoSupportedAuth:
|
||||
error = "HTTP/SOCKS5 proxy requires an unsupported auth mechanism";
|
||||
break;
|
||||
case gloox::ConnIoError:
|
||||
error = "I/O error occured";
|
||||
break;
|
||||
case gloox::ConnParseError:
|
||||
error = "XML parse error occurred";
|
||||
break;
|
||||
case gloox::ConnConnectionRefused:
|
||||
error = "connection was refused by the server (on the socket level)";
|
||||
break;
|
||||
case gloox::ConnDnsError:
|
||||
error = "resolving the server's hostname failed";
|
||||
break;
|
||||
case gloox::ConnOutOfMemory:
|
||||
error = "connection out of memory";
|
||||
break;
|
||||
case gloox::ConnNoSupportedAuth:
|
||||
error = "auth mechanisms the server offers are not supported";
|
||||
break;
|
||||
case gloox::ConnTlsFailed:
|
||||
error = "server's certificate could not be verified or the TLS";
|
||||
break;
|
||||
case gloox::ConnTlsNotAvailable:
|
||||
error = "server didn't offer TLS while it was set to be required";
|
||||
break;
|
||||
case gloox::ConnCompressionFailed:
|
||||
error = "negotiating/initializing compression failed";
|
||||
break;
|
||||
case gloox::ConnAuthenticationFailed: //TODO use ClientBase::authError() to find the reason. */
|
||||
error = "authentication failed";
|
||||
break;
|
||||
|
||||
case gloox::ConnUserDisconnected:
|
||||
error = "user (or higher-level protocol) requested a disconnect";
|
||||
break;
|
||||
case gloox::ConnNotConnected:
|
||||
error = "there is no active connection";
|
||||
}
|
||||
|
||||
if (error.empty())
|
||||
core->logger.log(Logger::info, "disconnected" , {"Connection"});
|
||||
else
|
||||
core->logger.log(Logger::error, "disconnected: " + error , {"Connection"});
|
||||
}
|
||||
bool Connection::onTLSConnect(const gloox::CertInfo&) {
|
||||
core->logger.log(Logger::info, "TLS established", {"Connection"});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue