switched to new logging

This commit is contained in:
john30
2015-01-25 19:07:38 +01:00
parent 89349e7d21
commit 8fb73a5f5d
2 changed files with 29 additions and 36 deletions
+24 -29
View File
@@ -22,7 +22,7 @@
#include "data.h" #include "data.h"
#include "result.h" #include "result.h"
#include "symbol.h" #include "symbol.h"
#include "logger.h" #include "log.h"
#include "appl.h" #include "appl.h"
#include <string> #include <string>
#include <vector> #include <vector>
@@ -33,11 +33,6 @@
using namespace std; using namespace std;
extern Logger& L;
/** helper macro for conditional logging (avoids unnecessary code execution). */
#define LOG(area, level, ...) (L.hasSink(area, level) == true) ? L.log(area, level, __VA_ARGS__) : void(0)
/** /**
* Return the string corresponding to the @a BusState. * Return the string corresponding to the @a BusState.
* @param state the @a BusState. * @param state the @a BusState.
@@ -68,7 +63,7 @@ result_t PollRequest::prepare(unsigned char ownMasterAddress)
istringstream input; istringstream input;
result_t result = m_message->prepareMaster(ownMasterAddress, m_master, input); result_t result = m_message->prepareMaster(ownMasterAddress, m_master, input);
if (result == RESULT_OK) if (result == RESULT_OK)
LOG(bus, trace, "poll cmd: %s", m_master.getDataStr().c_str()); logInfo(lf_bus, "poll cmd: %s", m_master.getDataStr().c_str());
return result; return result;
} }
@@ -79,9 +74,9 @@ bool PollRequest::notify(result_t result, SymbolString& slave)
result = m_message->decode(pt_slaveData, slave, output); // decode data result = m_message->decode(pt_slaveData, slave, output); // decode data
} }
if (result != RESULT_OK) if (result != RESULT_OK)
L.log(bus, error, "poll %s %s failed: %s", m_message->getClass().c_str(), m_message->getName().c_str(), getResultCode(result)); logError(lf_bus, "poll %s %s failed: %s", m_message->getClass().c_str(), m_message->getName().c_str(), getResultCode(result));
else else
LOG(bus, event, "poll %s %s: %s", m_message->getClass().c_str(), m_message->getName().c_str(), output.str().c_str()); logNotice(lf_bus, "poll %s %s: %s", m_message->getClass().c_str(), m_message->getName().c_str(), output.str().c_str());
return false; return false;
} }
@@ -92,7 +87,7 @@ result_t ScanRequest::prepare(unsigned char ownMasterAddress, unsigned char dstA
istringstream input; istringstream input;
result_t result = m_message->prepareMaster(ownMasterAddress, m_master, input, UI_FIELD_SEPARATOR, dstAddress); result_t result = m_message->prepareMaster(ownMasterAddress, m_master, input, UI_FIELD_SEPARATOR, dstAddress);
if (result == RESULT_OK) if (result == RESULT_OK)
LOG(bus, trace, "scan cmd: %s", m_master.getDataStr().c_str()); logInfo(lf_bus, "scan cmd: %s", m_master.getDataStr().c_str());
return result; return result;
} }
@@ -107,12 +102,12 @@ bool ScanRequest::notify(result_t result, SymbolString& slave)
result = m_message->decode(pt_slaveData, slave, scanResult, append); // decode data result = m_message->decode(pt_slaveData, slave, scanResult, append); // decode data
} }
if (result != RESULT_OK) { if (result != RESULT_OK) {
L.log(bus, error, "scan %2.2x failed: %s", dstAddress, getResultCode(result)); logError(lf_bus, "scan %2.2x failed: %s", dstAddress, getResultCode(result));
return false; return false;
} }
string str = scanResult.str(); string str = scanResult.str();
LOG(bus, event, "scan: %s", str.c_str()); logNotice(lf_bus, "scan: %s", str.c_str());
if (m_scanResults != NULL) { if (m_scanResults != NULL) {
if (append == true) if (append == true)
(*m_scanResults)[dstAddress] += str; (*m_scanResults)[dstAddress] += str;
@@ -138,7 +133,7 @@ bool ScanRequest::notify(result_t result, SymbolString& slave)
bool ActiveBusRequest::notify(result_t result, SymbolString& slave) bool ActiveBusRequest::notify(result_t result, SymbolString& slave)
{ {
if (result == RESULT_OK) if (result == RESULT_OK)
LOG(bus, event, "read res: %s", slave.getDataStr().c_str()); logNotice(lf_bus, "read res: %s", slave.getDataStr().c_str());
m_result = result; m_result = result;
m_slave = SymbolString(slave, false, false); m_slave = SymbolString(slave, false, false);
@@ -161,10 +156,10 @@ result_t BusHandler::sendAndWait(SymbolString& master, SymbolString& slave)
break; break;
if (success == false || result == RESULT_ERR_NO_SIGNAL) { if (success == false || result == RESULT_ERR_NO_SIGNAL) {
L.log(bus, error, "%s, give up", getResultCode(result)); logError(lf_bus, "%s, give up", getResultCode(result));
break; break;
} }
L.log(bus, error, "%s, %s", getResultCode(result), sendRetries>0 ? "retry send" : ""); logError(lf_bus, "%s, %s", getResultCode(result), sendRetries>0 ? "retry send" : "");
request->m_busLostRetries = 0; request->m_busLostRetries = 0;
} }
@@ -185,7 +180,7 @@ void BusHandler::run()
result_t result = m_port->open(); result_t result = m_port->open();
if (result != RESULT_OK) if (result != RESULT_OK)
L.log(bus, error, "can't open %s", m_port->getDeviceName()); logError(lf_bus, "can't open %s", m_port->getDeviceName());
} }
@@ -225,7 +220,7 @@ result_t BusHandler::handleSymbol()
PollRequest* request = new PollRequest(message); PollRequest* request = new PollRequest(message);
result_t ret = request->prepare(m_ownMasterAddress); result_t ret = request->prepare(m_ownMasterAddress);
if (ret != RESULT_OK) { if (ret != RESULT_OK) {
L.log(bus, error, "prepare poll message: %s", getResultCode(ret)); logError(lf_bus, "prepare poll message: %s", getResultCode(ret));
delete request; delete request;
} }
else { else {
@@ -588,13 +583,13 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
{ {
if (m_currentRequest != NULL) { if (m_currentRequest != NULL) {
if (result == RESULT_ERR_BUS_LOST && m_currentRequest->m_busLostRetries < m_busLostRetries) { if (result == RESULT_ERR_BUS_LOST && m_currentRequest->m_busLostRetries < m_busLostRetries) {
L.log(bus, error, "%s, retry", getResultCode(result)); logError(lf_bus, "%s, retry", getResultCode(result));
m_currentRequest->m_busLostRetries++; m_currentRequest->m_busLostRetries++;
m_nextRequests.add(m_currentRequest); // repeat m_nextRequests.add(m_currentRequest); // repeat
m_currentRequest = NULL; m_currentRequest = NULL;
} }
else if (state == bs_sendSyn || (result != RESULT_OK && firstRepetition == false)) { else if (state == bs_sendSyn || (result != RESULT_OK && firstRepetition == false)) {
LOG(bus, debug, "notify request: %s", getResultCode(result)); logDebug(lf_bus, "notify request: %s", getResultCode(result));
unsigned char dstAddress = m_currentRequest->m_master[1]; unsigned char dstAddress = m_currentRequest->m_master[1];
if (result == RESULT_OK && isValidAddress(dstAddress, false) == true) if (result == RESULT_OK && isValidAddress(dstAddress, false) == true)
m_seenAddresses[dstAddress] = true; m_seenAddresses[dstAddress] = true;
@@ -631,9 +626,9 @@ result_t BusHandler::setState(BusState state, result_t result, bool firstRepetit
return result; return result;
if (result < RESULT_OK || (result != RESULT_OK && state == bs_skip)) if (result < RESULT_OK || (result != RESULT_OK && state == bs_skip))
LOG(bus, debug, "%s during %s, switching to %s", getResultCode(result), getStateCode(m_state), getStateCode(state)); logDebug(lf_bus, "%s during %s, switching to %s", getResultCode(result), getStateCode(m_state), getStateCode(state));
else if (m_currentRequest != NULL || state == bs_sendCmd || state == bs_sendResAck || state == bs_sendSyn) else if (m_currentRequest != NULL || state == bs_sendCmd || state == bs_sendResAck || state == bs_sendSyn)
LOG(bus, debug, "switching from %s to %s", getStateCode(m_state), getStateCode(state)); logDebug(lf_bus, "switching from %s to %s", getStateCode(m_state), getStateCode(state));
m_state = state; m_state = state;
if (state == bs_ready || state == bs_skip) { if (state == bs_ready || state == bs_skip) {
@@ -653,13 +648,13 @@ void BusHandler::receiveCompleted()
bool master = isMaster(dstAddress); bool master = isMaster(dstAddress);
m_seenAddresses[m_command[0]] = true; m_seenAddresses[m_command[0]] = true;
if (dstAddress == BROADCAST) if (dstAddress == BROADCAST)
LOG(upd, trace, "update BC cmd: %s", m_command.getDataStr().c_str()); logInfo(lf_update, "update BC cmd: %s", m_command.getDataStr().c_str());
else if (master == true) { else if (master == true) {
LOG(upd, trace, "update MM cmd: %s", m_command.getDataStr().c_str()); logInfo(lf_update, "update MM cmd: %s", m_command.getDataStr().c_str());
m_seenAddresses[dstAddress] = true; m_seenAddresses[dstAddress] = true;
} }
else { else {
LOG(upd, trace, "update MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str()); logInfo(lf_update, "update MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str());
m_seenAddresses[dstAddress] = true; m_seenAddresses[dstAddress] = true;
} }
@@ -670,19 +665,19 @@ void BusHandler::receiveCompleted()
ostringstream output; ostringstream output;
result_t result = message->decode(m_command, m_response, output); result_t result = message->decode(m_command, m_response, output);
if (result != RESULT_OK) if (result != RESULT_OK)
L.log(upd, error, "unable to parse %s %s from %s / %s: %s", clazz.c_str(), name.c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result)); logError(lf_update, "unable to parse %s %s from %s / %s: %s", clazz.c_str(), name.c_str(), m_command.getDataStr().c_str(), m_response.getDataStr().c_str(), getResultCode(result));
else { else {
string data = output.str(); string data = output.str();
LOG(upd, event, "update %s %s: %s", clazz.c_str(), name.c_str(), data.c_str()); logNotice(lf_update, "update %s %s: %s", clazz.c_str(), name.c_str(), data.c_str());
} }
} }
else { else {
if (dstAddress == BROADCAST) if (dstAddress == BROADCAST)
LOG(upd, event, "unknown BC cmd: %s", m_command.getDataStr().c_str()); logNotice(lf_update, "unknown BC cmd: %s", m_command.getDataStr().c_str());
else if (master == true) else if (master == true)
LOG(upd, event, "unknown MM cmd: %s", m_command.getDataStr().c_str()); logNotice(lf_update, "unknown MM cmd: %s", m_command.getDataStr().c_str());
else else
LOG(upd, event, "unknown MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str()); logNotice(lf_update, "unknown MS cmd: %s / %s", m_command.getDataStr().c_str(), m_response.getDataStr().c_str());
} }
} }
+5 -7
View File
@@ -22,7 +22,7 @@
#endif #endif
#include "network.h" #include "network.h"
#include "logger.h" #include "log.h"
#include "appl.h" #include "appl.h"
#include <cstring> #include <cstring>
@@ -32,8 +32,6 @@
using namespace std; using namespace std;
extern Logger& L;
int Connection::m_ids = 0; int Connection::m_ids = 0;
void Connection::run() void Connection::run()
@@ -132,7 +130,7 @@ void Connection::run()
m_netQueue->add(&message); m_netQueue->add(&message);
// wait for result // wait for result
L.log(net, debug, "[%05d] wait for result", getID()); logDebug(lf_network, "[%05d] wait for result", getID());
string result = message.getResult(); string result = message.getResult();
if (m_socket->isValid() == false) if (m_socket->isValid() == false)
@@ -146,7 +144,7 @@ void Connection::run()
delete m_socket; delete m_socket;
m_socket = NULL; m_socket = NULL;
L.log(net, trace, "[%05d] connection closed", getID()); logInfo(lf_network, "[%05d] connection closed", getID());
} }
@@ -266,7 +264,7 @@ void Network::run()
connection->start("connection"); connection->start("connection");
m_connections.push_back(connection); m_connections.push_back(connection);
L.log(net, trace, "[%05d] connection opened %s", connection->getID(), socket->getIP().c_str()); logInfo(lf_network, "[%05d] connection opened %s", connection->getID(), socket->getIP().c_str());
} }
} }
@@ -280,7 +278,7 @@ void Network::cleanConnections()
Connection* connection = *c_it; Connection* connection = *c_it;
c_it = m_connections.erase(c_it); c_it = m_connections.erase(c_it);
delete connection; delete connection;
L.log(net, debug, "dead connection removed - %d", m_connections.size()); logDebug(lf_network, "dead connection removed - %d", m_connections.size());
} }
} }
} }