logging: Add a timestamp to the log messages we emit

This commit is contained in:
nick
2013-06-06 11:57:05 +01:00
parent 26c7f1b1c4
commit 24858fcde5
5 changed files with 38 additions and 7 deletions

View File

@@ -6,10 +6,11 @@
#include <errno.h>
#include <malloc.h>
#include <unistd.h>
#include <time.h>
#include "util.h"
pthread_key_t cleanup_handler_key;
pthread_key_t cleanup_handler_key;
int log_level = 2;
@@ -21,10 +22,10 @@ void error_init(void)
void error_handler(int fatal)
{
DECLARE_ERROR_CONTEXT(context);
if (context) {
longjmp(context->jmp, fatal ? 1 : 2 );
}
}
else {
if ( fatal ) { abort(); }
else { pthread_exit((void*) 1); }
@@ -50,6 +51,25 @@ void mylog(int line_level, const char* format, ...)
va_end(argptr);
}
uint64_t monotonic_time_ms()
{
struct timespec ts;
uint64_t seconds_ms, nanoseconds_ms;
FATAL_IF_NEGATIVE(
clock_gettime(CLOCK_MONOTONIC, &ts),
SHOW_ERRNO( "clock_gettime failed" )
);
seconds_ms = ts.tv_sec;
seconds_ms = seconds_ms * 1000;
nanoseconds_ms = ts.tv_nsec;
nanoseconds_ms = nanoseconds_ms / 1000000;
return seconds_ms + nanoseconds_ms;
}
void* xrealloc(void* ptr, size_t size)
{