Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 499 → Rev 500

/QMK-Groundstation/branches/libMK/libMK/FlightLog.cpp
0,0 → 1,46
#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);
}