Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use colored log output and timestamps in default log handler #267

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/default_log_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,34 @@

#include "ur_client_library/default_log_handler.h"
#include <stdio.h>
#include <chrono>
#include <string>

namespace urcl
{

DefaultLogHandler::DefaultLogHandler() = default;

void DefaultLogHandler::log(const char* file, int line, LogLevel loglevel, const char* log)
{
auto timestamp = std::chrono::duration<double>(std::chrono::system_clock::now().time_since_epoch());

switch (loglevel)
{
case LogLevel::INFO:
printf("%s%s %i: %s \n", "INFO ", file, line, log);
printf("[%f] %s%s %i: %s \n", timestamp.count(), "INFO ", file, line, log);
break;
case LogLevel::DEBUG:
printf("%s%s %i: %s \n", "DEBUG ", file, line, log);
printf("\033[36m[%f] %s%s %i: %s \033[0m\n", timestamp.count(), "DEBUG ", file, line, log);
break;
case LogLevel::WARN:
printf("%s%s %i: %s \n", "WARN ", file, line, log);
printf("\033[33m[%f] %s%s %i: %s \033[0m\n", timestamp.count(), "WARN ", file, line, log);
break;
case LogLevel::ERROR:
printf("%s%s %i: %s \n", "ERROR ", file, line, log);
printf("\033[31m[%f] %s%s %i: %s \033[0m\n", timestamp.count(), "ERROR ", file, line, log);
break;
case LogLevel::FATAL:
printf("%s%s %i: %s \n", "FATAL ", file, line, log);
printf("\033[31m[%f] %s%s %i: %s \033[0m\n", timestamp.count(), "FATAL ", file, line, log);
break;
default:
break;
Expand Down
Loading