#ifndef UTILS_LOGS_HPP
#define UTILS_LOGS_HPP
#include <string>
#include <chrono>
#include <iostream>
#include <iomanip>
#include <ctime>
using std::setfill, std::setw;
enum level { INFO, WARNING, ERROR };
enum type { WEBSOCKET, NETWORK };
class Logs {
public:
static void create(level lvl, type t, const std::string& message) {
std::string color;
switch (lvl) {
case INFO:
color = "\033[34m";
break;
case WARNING:
color = "\033[33m";
case ERROR:
color = "\033[31m";
default:
color = "\033[0m";
}
std::cout << color << "[" << getCurrentTime() << "][" << str(t) << "][" << str(lvl) << "] \033[37m" << message << "\033[0m" << std::endl;
private:
static std::string getCurrentTime() {
std::time_t now_c = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm* timer = std::localtime(&now_c);
std::ostringstream oss;
oss << setfill('0') << setw(2) << timer->tm_hour << ":" << setfill('0') << setw(2) << timer->tm_min << ":" << setfill('0') << setw(2) << timer->tm_sec;
return oss.str();
static std::string str(level lvl) {
case INFO: return "INFO";
case WARNING: return "WARNING";
case ERROR: return "ERROR";
default: return "UNKNOWN";
static std::string str(type t) {
switch (t) {
case WEBSOCKET: return "WEBSOCKET";
case NETWORK: return "NETWORK";
};
#endif