Logging cleanups.

This commit is contained in:
JoelKatz
2012-12-18 14:39:02 -08:00
parent db10d65651
commit 2203313945
8 changed files with 54 additions and 53 deletions

View File

@@ -10,6 +10,8 @@
#include "Config.h"
#include "Log.h"
SETUP_LOG();
// #define SNTP_DEBUG
static uint8_t SNTPQueryData[48] =
@@ -73,7 +75,7 @@ void SNTPClient::resolveComplete(const boost::system::error_code& error, boost::
time_t now = time(NULL);
if ((query.mLocalTimeSent == now) || ((query.mLocalTimeSent + 1) == now))
{ // This can happen if the same IP address is reached through multiple names
Log(lsTRACE) << "SNTP: Redundant query suppressed";
cLog(lsTRACE) << "SNTP: Redundant query suppressed";
return;
}
query.mReceivedReply = false;
@@ -94,23 +96,23 @@ void SNTPClient::receivePacket(const boost::system::error_code& error, std::size
{
boost::mutex::scoped_lock sl(mLock);
#ifdef SNTP_DEBUG
Log(lsTRACE) << "SNTP: Packet from " << mReceiveEndpoint;
cLog(lsTRACE) << "SNTP: Packet from " << mReceiveEndpoint;
#endif
std::map<boost::asio::ip::udp::endpoint, SNTPQuery>::iterator query = mQueries.find(mReceiveEndpoint);
if (query == mQueries.end())
Log(lsDEBUG) << "SNTP: Reply from " << mReceiveEndpoint << " found without matching query";
cLog(lsDEBUG) << "SNTP: Reply from " << mReceiveEndpoint << " found without matching query";
else if (query->second.mReceivedReply)
Log(lsDEBUG) << "SNTP: Duplicate response from " << mReceiveEndpoint;
cLog(lsDEBUG) << "SNTP: Duplicate response from " << mReceiveEndpoint;
else
{
query->second.mReceivedReply = true;
if (time(NULL) > (query->second.mLocalTimeSent + 1))
Log(lsWARNING) << "SNTP: Late response from " << mReceiveEndpoint;
cLog(lsWARNING) << "SNTP: Late response from " << mReceiveEndpoint;
else if (bytes_xferd < 48)
Log(lsWARNING) << "SNTP: Short reply from " << mReceiveEndpoint
cLog(lsWARNING) << "SNTP: Short reply from " << mReceiveEndpoint
<< " (" << bytes_xferd << ") " << mReceiveBuffer.size();
else if (reinterpret_cast<uint32*>(&mReceiveBuffer[0])[NTP_OFF_ORGTS_FRAC] != query->second.mQueryNonce)
Log(lsWARNING) << "SNTP: Reply from " << mReceiveEndpoint << "had wrong nonce";
cLog(lsWARNING) << "SNTP: Reply from " << mReceiveEndpoint << "had wrong nonce";
else
processReply();
}
@@ -123,8 +125,7 @@ void SNTPClient::receivePacket(const boost::system::error_code& error, std::size
void SNTPClient::sendComplete(const boost::system::error_code& error, std::size_t)
{
if (error)
Log(lsWARNING) << "SNTP: Send error";
tLog(error, lsWARNING) << "SNTP: Send error";
}
void SNTPClient::processReply()
@@ -138,12 +139,12 @@ void SNTPClient::processReply()
if ((info >> 30) == 3)
{
Log(lsINFO) << "SNTP: Alarm condition " << mReceiveEndpoint;
cLog(lsINFO) << "SNTP: Alarm condition " << mReceiveEndpoint;
return;
}
if ((stratum == 0) || (stratum > 14))
{
Log(lsINFO) << "SNTP: Unreasonable stratum (" << stratum << ") from " << mReceiveEndpoint;
cLog(lsINFO) << "SNTP: Unreasonable stratum (" << stratum << ") from " << mReceiveEndpoint;
return;
}
@@ -171,10 +172,7 @@ void SNTPClient::processReply()
if ((mOffset == -1) || (mOffset == 1)) // small corrections likely do more harm than good
mOffset = 0;
#ifndef SNTP_DEBUG
if (timev || mOffset)
#endif
Log(lsTRACE) << "SNTP: Offset is " << timev << ", new system offset is " << mOffset;
tLog(timev || mOffset, lsTRACE) << "SNTP: Offset is " << timev << ", new system offset is " << mOffset;
}
void SNTPClient::timerEntry(const boost::system::error_code& error)
@@ -198,7 +196,7 @@ void SNTPClient::init(const std::vector<std::string>& servers)
std::vector<std::string>::const_iterator it = servers.begin();
if (it == servers.end())
{
Log(lsINFO) << "SNTP: no server specified";
cLog(lsINFO) << "SNTP: no server specified";
return;
}
BOOST_FOREACH(const std::string& it, servers)
@@ -231,13 +229,13 @@ bool SNTPClient::doQuery()
best = it;
if (best == mServers.end())
{
Log(lsINFO) << "SNTP: No server to query";
cLog(lsINFO) << "SNTP: No server to query";
return false;
}
time_t now = time(NULL);
if ((best->second != (time_t) -1) && ((best->second + NTP_MIN_QUERY) >= now))
{
Log(lsTRACE) << "SNTP: All servers recently queried";
cLog(lsTRACE) << "SNTP: All servers recently queried";
return false;
}
best->second = now;
@@ -247,7 +245,7 @@ bool SNTPClient::doQuery()
boost::bind(&SNTPClient::resolveComplete, this,
boost::asio::placeholders::error, boost::asio::placeholders::iterator));
#ifdef SNTP_DEBUG
Log(lsTRACE) << "SNTP: Resolve pending for " << best->first;
cLog(lsTRACE) << "SNTP: Resolve pending for " << best->first;
#endif
return true;
}