Skip to content
Snippets Groups Projects
Commit 0cea3445 authored by Valerio Pastore's avatar Valerio Pastore
Browse files

update for log

parent c8731f14
No related branches found
No related tags found
No related merge requests found
Subproject commit ce99aaa20706cca85200a375cee63d7414cebb74
Subproject commit f8149d2831d10e7f467d96ee11335f01bfad81b5
......@@ -11,6 +11,8 @@
#include <iostream> // std::cout, std::endl
#include <thread> // std::this_thread::sleep_for
#include <chrono> // std::chrono::seconds
#include <ctime>
#include <iomanip>
using namespace inaf::oasbo::ConnectionProtocols;
......@@ -34,11 +36,16 @@ int RedisReceiver::connectToClient() {
context = redisConnect(ip.c_str(), port);
if (context == nullptr || context->err) {
if (context) {
std::cout << "Redis Receiver Error: " << context->errstr
<< std::endl;
time_t now = time(nullptr);
std::cerr << "["
<< std::put_time(localtime(&now), "%Y-%m-%d %H:%M:%S")
<< "]\t[Redis Receiver]\t" << context->errstr << std::endl;
} else {
std::cout << "Redis Receiver Error: Can't allocate Redis context"
<< std::endl;
time_t now = time(nullptr);
std::cerr << "["
<< std::put_time(localtime(&now), "%Y-%m-%d %H:%M:%S")
<< "]\t[Redis Receiver]\t"
<< " Can't allocate Redis context" << std::endl;
}
return -1;
}
......@@ -60,10 +67,15 @@ bool RedisReceiver::isConnectedToClient() const {
int RedisReceiver::receiveFromClient(PacketLib::BasePacket &pack) {
if (!isConnectedToClient()) {
if (context) {
std::cerr << "Redis Receiver Error: " << context->errstr
<< std::endl;
time_t now = time(nullptr);
std::cerr << "["
<< std::put_time(localtime(&now), "%Y-%m-%d %H:%M:%S")
<< "]\t[Redis Receiver]\t" << context->errstr << std::endl;
} else {
std::cerr << "Redis Receiver Error: Can't allocate Redis context"
time_t now = time(nullptr);
std::cerr << "["
<< std::put_time(localtime(&now), "%Y-%m-%d %H:%M:%S")
<< "]\t[Redis Receiver]\t" << "Can't allocate Redis context"
<< std::endl;
}
return -1;
......@@ -94,9 +106,12 @@ int RedisReceiver::receiveFromClient(PacketLib::BasePacket &pack) {
+ pack.getTailSize();
if (!pack.isRecognizedHeader() || size < (tot_packet_size)) {
std::cerr << "Redis receiver error: packet not recognized: "
<< pack["type"].value() << " " << pack["subtype"].value() << " "
<< pack.getPayloadSize() << std::endl;
time_t now = time(nullptr);
std::cerr << "["
<< std::put_time(localtime(&now), "%Y-%m-%d %H:%M:%S")
<< "]\t[Redis Receiver]\t" << "packet not recognized: "
<< pack["type"].value() << " " << pack["subtype"].value()
<< " " << pack.getPayloadSize() << std::endl;
freeReplyObject(r);
resetPacket(pack, header_size);
return -1;
......@@ -124,7 +139,9 @@ void RedisReceiver::setHost(std::string host) {
setPort(port);
setKey(key);
} else {
std::cerr << "Redis receiver error: \"" << host
time_t now = time(nullptr);
std::cerr << "[" << std::put_time(localtime(&now), "%Y-%m-%d %H:%M:%S")
<< "]\t[Redis Receiver]\t" << host
<< "\" does not match the format: "
<< "\"xxx.xxx.xxx.xxx:xxxx/xxxx\"" << std::endl;
}
......@@ -137,7 +154,9 @@ void RedisReceiver::setIp(std::string ip) {
this->ip = ip;
this->host = ip + ":" + std::to_string(port) + "/" + key;
} else {
std::cerr << "Redis Receiver Error: invalid IP address: " << ip
time_t now = time(nullptr);
std::cerr << "[" << std::put_time(localtime(&now), "%Y-%m-%d %H:%M:%S")
<< "]\t[Redis Receiver]\t" << "invalid IP address: " << ip
<< std::endl;
}
}
......@@ -147,7 +166,9 @@ void RedisReceiver::setPort(int port) {
this->port = port;
this->host = ip + ":" + std::to_string(port) + "/" + key;
} else {
std::cerr << "Redis Receiver Error: invalid port: " << port
time_t now = time(nullptr);
std::cerr << "[" << std::put_time(localtime(&now), "%Y-%m-%d %H:%M:%S")
<< "]\t[Redis Receiver]\t" << "Invalid port : " << port
<< std::endl;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment