Subversion Repositories Projects

Rev

Rev 513 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
500 Brean 1
#include "FlightLog.h"
2
//TODO: real logging with 
3
//    * more log levels (arent info, warning and error enough?)
4
//    * logging in file
5
//    * the current timestamp
6
//    * normal difference between log and error messages
7
//    * and so on
8
#include <iostream>
9
#include "Colors.h"
10
#include <string>
11
 
12
//#include <ctime>
13
#include <sys/time.h>
14
 
15
void print_data(char * data, std::string type, char * color) {
16
    char buffer [100];
17
    timeval timestamp;
18
    gettimeofday(&timestamp, 0);
19
    sprintf(buffer, "%i.%03i", timestamp.tv_sec, (timestamp.tv_usec+500)/1000);
20
/*
21
    time_t rawtime;
22
    struct tm * timeinfo;
23
    time ( &rawtime );
24
    timeinfo = localtime ( &rawtime );
25
 
26
    strftime(buffer, 100, "%x %X", timeinfo);
27
*/
28
 
29
    #ifdef USE_COLOR
30
        std::cout << color << buffer << " " << type << ": " << data << COLOR_NORMAL << std::endl;
31
    #else
32
        std::cout  << buffer << " " << type << ": " << data << std::endl;
33
    #endif
34
}
35
 
36
void FlightLog::info(char * data) {
37
    print_data(data, "INFO", INFO_COLOR);
38
}
39
 
40
void FlightLog::warning(char * data) {
41
    print_data(data, "WARNING", WARNING_COLOR);
42
}
43
 
44
void FlightLog::error(char * data) {
45
    print_data(data, "ERROR", ERROR_COLOR);
46
}