gave start of prefix output identical implementation
This commit is contained in:
parent
fb520c2260
commit
cfec8e9d3c
21
log4cpp.cpp
21
log4cpp.cpp
@ -16,6 +16,9 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <ctime>
|
||||||
|
#include <cmath>
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -29,16 +32,20 @@ mutex m;
|
|||||||
|
|
||||||
void print_timestamp()
|
void print_timestamp()
|
||||||
{
|
{
|
||||||
|
// retrieve accurate time for milliseconds display
|
||||||
struct timeval secs;
|
struct timeval secs;
|
||||||
(void)gettimeofday(&secs, NULL);
|
(void)::gettimeofday(&secs, nullptr);
|
||||||
time_t now = time(NULL);
|
int ms = static_cast<int>(std::roundf(secs.tv_usec / 1000.0)) % 1000;
|
||||||
char dtstamp[32];
|
|
||||||
strftime(dtstamp, 32, "%F %T", localtime(&now));
|
// create a date/time stamp
|
||||||
long millisecs = (long)((double)secs.tv_usec / 1000.0 + 0.5) % 1000;
|
char dtstamp[20];
|
||||||
|
std::strftime(dtstamp, 20, "%F %T", std::localtime(&secs.tv_sec));
|
||||||
|
|
||||||
|
std::cerr << dtstamp << "." << std::setw(3) << ms << " ";
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
fprintf(stderr, "%s.%03ld %s[%ld] ", dtstamp, millisecs, getprogname(), (long)getpid());
|
std::cerr << getprogname() << "[" << getpid() << "] ";
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
fprintf(stderr, "%s.%03ld %s[%ld] ", dtstamp, millisecs, program_invocation_name, (long)getpid());
|
std::cerr << program_invocation_name << "[" << getpid() << "] ";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user