GitWatcherBot  1.0.0
A Telegram Bot that notifies you when a new change is made in your repositories (issues, pull requests, stars, forks, and watches)
All Classes Namespaces Files Functions Variables Typedefs Macros
Logger.hpp File Reference
#include <ctime>
#include <fstream>
#include <iostream>
#include <sstream>
#include "db/models/Log.hpp"

Go to the source code of this file.

Macros

#define KNRM   "\x1B[0m"
 
#define KRED   "\x1B[31m"
 
#define KGRN   "\x1B[32m"
 
#define KYEL   "\x1B[33m"
 
#define KBLU   "\x1B[34m"
 
#define KMAG   "\x1B[35m"
 
#define KCYN   "\x1B[36m"
 
#define KWHT   "\x1B[37m"
 
#define LOG(level, txt, longTxt, color)
 Logs to console on Debug mode and saves log to db. More...
 
#define LOGT(txt)   LOG("trace", txt, "", KNRM)
 
#define LOGI(txt)   LOG("info", txt, "", KGRN)
 
#define LOGW(txt)   LOG("warn", txt, "", KYEL)
 
#define LOGE(txt)   LOG("error", txt, "", KRED)
 
#define LOGT2(txt, longTxt)   LOG("trace", txt, longTxt, KNRM)
 
#define LOGI2(txt, longTxt)   LOG("info", txt, longTxt, KGRN)
 
#define LOGW2(txt, longTxt)   LOG("warn", txt, longTxt, KYEL)
 
#define LOGE2(txt, longTxt)   LOG("error", txt, longTxt, KRED)
 

Variables

static constexpr bool kLogToConsole = true
 

Macro Definition Documentation

◆ KBLU

#define KBLU   "\x1B[34m"

Definition at line 13 of file Logger.hpp.

◆ KCYN

#define KCYN   "\x1B[36m"

Definition at line 15 of file Logger.hpp.

◆ KGRN

#define KGRN   "\x1B[32m"

Definition at line 11 of file Logger.hpp.

◆ KMAG

#define KMAG   "\x1B[35m"

Definition at line 14 of file Logger.hpp.

◆ KNRM

#define KNRM   "\x1B[0m"

Definition at line 9 of file Logger.hpp.

◆ KRED

#define KRED   "\x1B[31m"

Definition at line 10 of file Logger.hpp.

◆ KWHT

#define KWHT   "\x1B[37m"

Definition at line 16 of file Logger.hpp.

◆ KYEL

#define KYEL   "\x1B[33m"

Definition at line 12 of file Logger.hpp.

◆ LOG

#define LOG (   level,
  txt,
  longTxt,
  color 
)
Value:
try \
{ \
std::ostringstream logoss{}, logosslng{}; \
logoss << txt; \
logosslng << longTxt; \
models::Log newLog(level, logoss.str(), logosslng.str()); \
if constexpr (kLogToConsole) \
{ \
std::cout << color << newLog.toString() << std::endl; \
} \
} \
catch (const std::exception &e) \
{ \
std::cerr << "Failed to log [" << txt << "]: " << e.what(); \
}
static constexpr bool kLogToConsole
Definition: Logger.hpp:21
static std::int64_t addLog(const models::Log &newLog)
Adds a new Log object to the database.

Logs to console on Debug mode and saves log to db.

Definition at line 25 of file Logger.hpp.

◆ LOGE

#define LOGE (   txt)    LOG("error", txt, "", KRED)

Definition at line 47 of file Logger.hpp.

◆ LOGE2

#define LOGE2 (   txt,
  longTxt 
)    LOG("error", txt, longTxt, KRED)

Definition at line 52 of file Logger.hpp.

◆ LOGI

#define LOGI (   txt)    LOG("info", txt, "", KGRN)

Definition at line 45 of file Logger.hpp.

◆ LOGI2

#define LOGI2 (   txt,
  longTxt 
)    LOG("info", txt, longTxt, KGRN)

Definition at line 50 of file Logger.hpp.

◆ LOGT

#define LOGT (   txt)    LOG("trace", txt, "", KNRM)

Definition at line 44 of file Logger.hpp.

◆ LOGT2

#define LOGT2 (   txt,
  longTxt 
)    LOG("trace", txt, longTxt, KNRM)

Definition at line 49 of file Logger.hpp.

◆ LOGW

#define LOGW (   txt)    LOG("warn", txt, "", KYEL)

Definition at line 46 of file Logger.hpp.

◆ LOGW2

#define LOGW2 (   txt,
  longTxt 
)    LOG("warn", txt, longTxt, KYEL)

Definition at line 51 of file Logger.hpp.

Variable Documentation

◆ kLogToConsole

constexpr bool kLogToConsole = true
staticconstexpr

Definition at line 21 of file Logger.hpp.