Bug 242 (yes, that old).

Add date to alarms (and console/syslog messages through Logger). Timestamp
was already there.
This commit is contained in:
dgotwisner 2014-03-31 12:12:35 +02:00 committed by Michael Iedema
parent 7b0e351a23
commit b21473440f
3 changed files with 10 additions and 4 deletions

View File

@ -61,7 +61,7 @@ extern pid_t gPid;
#define _LOG(level) \
Log(LOG_##level).get() << "pid(" << gPid << "), " \
<< "tid(" << gettid() << ") " \
<< Utils::timestr() << " " __FILE__ ":" << __LINE__ << ":" << __FUNCTION__ << ": "
<< Utils::timestr(21, true) << " " __FILE__ ":" << __LINE__ << ":" << __FUNCTION__ << ": "
// (pat) If you '#define LOG_GROUP groupname' before including Logger.h, then you can set Log.Level.groupname as well as Log.Level.filename.
#ifdef LOG_GROUP

View File

@ -265,14 +265,20 @@ double timef()
return tv.tv_usec / 1000000.0 + tv.tv_sec;
}
const std::string timestr(unsigned fieldwidth) // Use to pick the number of chars in the output.
const std::string timestr(unsigned fieldwidth, bool addDate) // Use to pick the number of chars in the output.
{
struct timeval tv;
struct tm tm;
gettimeofday(&tv,NULL);
localtime_r(&tv.tv_sec,&tm);
unsigned tenths = tv.tv_usec / 100000; // Rounding down is ok.
std::string result = format(" %02d:%02d:%02d.%1d",tm.tm_hour,tm.tm_min,tm.tm_sec,tenths);
std::string result;
if (addDate)
result = format(" %04d/%02d/%02d %02d:%02d:%02d.%1d",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tenths);
else
result = format(" %02d:%02d:%02d.%1d",tm.tm_hour,tm.tm_min,tm.tm_sec,tenths);
return result.substr(fieldwidth >= result.size() ? 0 : result.size() - fieldwidth);
//switch (maxfield) {
//case 'h': case 'H': return format("%02d:%02d:%02d.%1d",tm.tm_hour,tm.tm_min,tm.tm_sec,tenths);

View File

@ -32,7 +32,7 @@ using namespace std;
extern double timef(); // high resolution time
// We dont use a default arg here timestr(unsigned fieldwidth=12) because g++ complains about duplicate decl in Logger.h
extern const std::string timestr(); // A timestamp to print in messages.
extern const std::string timestr(unsigned fieldwidth); // A timestamp to print in messages.
extern const std::string timestr(unsigned fieldwidth, bool addDate = false); // A timestamp to print in messages.
extern void sleepf(double howlong); // high resolution sleep
extern int gcd(int x, int y);