Newer
Older
Import / applications / HighwayDash / ports / Platform / Qt / SystemLogger.cpp
@John John on 29 Dec 2020 772 bytes bulk import from macbookpro checkouts
//
//  SystemLogger.cpp
//  HighwayDash
//
//  Created by John Ryland on 18/02/2016.
//  Copyright © 2016 John Ryland. All rights reserved.
//

#include <ctime>
#include <cstdio>


void SystemLogger(const char* a_tag, const char* a_fmt, va_list a_args)
{
    int ms = 0;
#ifdef __linux__
    struct timespec ts;
    clock_gettime(CLOCK_REALTIME, &ts);
    time_t now = ts.tv_sec;
    ms = ts.tv_nsec / 1000000;
#else
    time_t now = time(0);
#endif
    struct tm tstruct = *localtime(&now);
    fprintf(stderr, "%04d-%02d-%02d %02d:%02d:%02d.%03d [%s] ", 1900+tstruct.tm_year, 1+tstruct.tm_mon,
                              tstruct.tm_mday, tstruct.tm_hour, tstruct.tm_min, tstruct.tm_sec, ms, a_tag);
    vfprintf(stderr, a_fmt, a_args);
    fprintf(stderr, "\n");
}