Skip to content

Commit 04b7ebf

Browse files
committed
REVERT_ME: Add color to default log handler
1 parent b4bbabf commit 04b7ebf

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/default_log_handler.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,39 @@
3030

3131
#include "ur_client_library/default_log_handler.h"
3232
#include <stdio.h>
33+
#include <chrono>
3334

3435
namespace urcl
3536
{
3637
DefaultLogHandler::DefaultLogHandler() = default;
3738

3839
void DefaultLogHandler::log(const char* file, int line, LogLevel loglevel, const char* log)
3940
{
41+
time_t timestamp = time(NULL);
42+
double time =
43+
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch())
44+
.count() /
45+
1000.0;
46+
47+
const char color_red[] = "\033[31m";
48+
const char color_orange[] = "\033[93m";
49+
const char color_none[] = "\033[39m";
4050
switch (loglevel)
4151
{
4252
case LogLevel::INFO:
43-
printf("%s%s %i: %s \n", "INFO ", file, line, log);
53+
printf("%f: %s%s %i: %s \n", time, "INFO ", file, line, log);
4454
break;
4555
case LogLevel::DEBUG:
4656
printf("%s%s %i: %s \n", "DEBUG ", file, line, log);
4757
break;
4858
case LogLevel::WARN:
49-
printf("%s%s %i: %s \n", "WARN ", file, line, log);
59+
printf("%s%f: %s%s %i: %s%s\n", color_orange, time, "WARN ", file, line, log, color_none);
5060
break;
5161
case LogLevel::ERROR:
52-
printf("%s%s %i: %s \n", "ERROR ", file, line, log);
62+
printf("%s%f: %s%s %i: %s%s\n", color_red, time, "ERROR ", file, line, log, color_none);
5363
break;
5464
case LogLevel::FATAL:
55-
printf("%s%s %i: %s \n", "FATAL ", file, line, log);
65+
printf("%s%s%s %i: %s%s\n", "FATAL ", color_red, file, line, log, color_none);
5666
break;
5767
default:
5868
break;

0 commit comments

Comments
 (0)