Subversion Repositories Projects

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "FlightLog.h"
//TODO: real logging with
//    * more log levels (arent info, warning and error enough?)
//    * logging in file
//    * the current timestamp
//    * normal difference between log and error messages
//    * and so on
#include <iostream>
#include "Colors.h"
#include <string>

//#include <ctime>
#include <sys/time.h>

void print_data(char * data, std::string type, char * color) {
    char buffer [100];
    timeval timestamp;
    gettimeofday(&timestamp, 0);
    sprintf(buffer, "%i.%03i", timestamp.tv_sec, (timestamp.tv_usec+500)/1000);
/*
    time_t rawtime;
    struct tm * timeinfo;
    time ( &rawtime );
    timeinfo = localtime ( &rawtime );

    strftime(buffer, 100, "%x %X", timeinfo);
*/


    #ifdef USE_COLOR
        std::cout << color << buffer << " " << type << ": " << data << COLOR_NORMAL << std::endl;
    #else
        std::cout  << buffer << " " << type << ": " << data << std::endl;
    #endif
}

void FlightLog::info(char * data) {
    print_data(data, "INFO", INFO_COLOR);
}

void FlightLog::warning(char * data) {
    print_data(data, "WARNING", WARNING_COLOR);
}

void FlightLog::error(char * data) {
    print_data(data, "ERROR", ERROR_COLOR);
}