7 changed files with 97 additions and 33 deletions
@ -0,0 +1,38 @@
|
||||
|
||||
#include <ctime> |
||||
#include <chrono> |
||||
|
||||
#include "dumbLog.h" |
||||
|
||||
void dumbLog::setOutputStream(std::ostream* out) |
||||
{ |
||||
this->OUT = out; |
||||
} |
||||
|
||||
const char* |
||||
dumbLog::logLevelToString(log_level level) |
||||
{ |
||||
switch (level) { |
||||
case log_level::Error: return "Error"; |
||||
case log_level::Warning: return "Warning"; |
||||
case log_level::Info: return "Info"; |
||||
default: return "Potato"; |
||||
} |
||||
}; |
||||
|
||||
std::tm* |
||||
dumbLog::getCurrentTime() |
||||
{ |
||||
auto now = std::chrono::system_clock::now(); |
||||
auto t_c = std::chrono::system_clock::to_time_t(now); |
||||
return std::localtime(&t_c); |
||||
} |
||||
|
||||
int |
||||
dumbLog::getCurrentMS() |
||||
{ |
||||
auto now = std::chrono::system_clock::now(); |
||||
long long total_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count(); |
||||
return int(total_ms % 1000); |
||||
} |
||||
|
||||
@ -0,0 +1,28 @@
|
||||
|
||||
#include <iomanip> |
||||
#include <iostream> |
||||
|
||||
|
||||
enum log_level { |
||||
Error, |
||||
Warning, |
||||
Info, |
||||
Debug |
||||
}; |
||||
|
||||
struct dumbLog |
||||
{ |
||||
std::ostream* OUT = &std::cout; |
||||
void setOutputStream(std::ostream* out); |
||||
const char* logLevelToString(log_level level); |
||||
std::tm* getCurrentTime(); |
||||
int getCurrentMS(); |
||||
}; |
||||
|
||||
static dumbLog logger; |
||||
|
||||
#define LOG(level) *logger.OUT \ |
||||
<< std::put_time(logger.getCurrentTime(), "%F %T.") << logger.getCurrentMS() << " " \
|
||||
<< "[" << logger.logLevelToString(level) << "] " \
|
||||
<< "(" << __FUNCTION__ << ") " |
||||
|
||||
Loading…
Reference in new issue