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 <cstdarg>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
@ -29,16 +32,20 @@ mutex m;
|
||||
|
||||
void print_timestamp()
|
||||
{
|
||||
// retrieve accurate time for milliseconds display
|
||||
struct timeval secs;
|
||||
(void)gettimeofday(&secs, NULL);
|
||||
time_t now = time(NULL);
|
||||
char dtstamp[32];
|
||||
strftime(dtstamp, 32, "%F %T", localtime(&now));
|
||||
long millisecs = (long)((double)secs.tv_usec / 1000.0 + 0.5) % 1000;
|
||||
(void)::gettimeofday(&secs, nullptr);
|
||||
int ms = static_cast<int>(std::roundf(secs.tv_usec / 1000.0)) % 1000;
|
||||
|
||||
// create a date/time stamp
|
||||
char dtstamp[20];
|
||||
std::strftime(dtstamp, 20, "%F %T", std::localtime(&secs.tv_sec));
|
||||
|
||||
std::cerr << dtstamp << "." << std::setw(3) << ms << " ";
|
||||
#if __APPLE__
|
||||
fprintf(stderr, "%s.%03ld %s[%ld] ", dtstamp, millisecs, getprogname(), (long)getpid());
|
||||
std::cerr << getprogname() << "[" << getpid() << "] ";
|
||||
#elif __linux__
|
||||
fprintf(stderr, "%s.%03ld %s[%ld] ", dtstamp, millisecs, program_invocation_name, (long)getpid());
|
||||
std::cerr << program_invocation_name << "[" << getpid() << "] ";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
10
logger.cpp
10
logger.cpp
@ -31,13 +31,13 @@ void logger::msg(loglevel level, const char* file, int line, const char* func) {
|
||||
|
||||
void logger::write_prefix(loglevel level, const char* file, int line, const char* func) {
|
||||
// retrieve accurate time for milliseconds display
|
||||
struct timeval secs;
|
||||
(void)::gettimeofday(&secs, nullptr);
|
||||
int ms = static_cast<int>(std::roundf(secs.tv_usec / 1000.0)) % 1000;
|
||||
struct timeval secs;
|
||||
(void)::gettimeofday(&secs, nullptr);
|
||||
int ms = static_cast<int>(std::roundf(secs.tv_usec / 1000.0)) % 1000;
|
||||
|
||||
// create a date/time stamp
|
||||
char dtstamp[20];
|
||||
std::strftime(dtstamp, 20, "%F %T", std::localtime(&secs.tv_sec));
|
||||
char dtstamp[20];
|
||||
std::strftime(dtstamp, 20, "%F %T", std::localtime(&secs.tv_sec));
|
||||
|
||||
std::cerr << dtstamp << "." << std::setw(3) << ms << " ";
|
||||
std::cerr << _name << "[" << ::getpid() << "] ";
|
||||
|
Loading…
x
Reference in New Issue
Block a user