FUCK YOU C++
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <mcolor.h>
|
||||
#include <token.hpp>
|
||||
#include "Color4.hpp"
|
||||
#include "Colors.hpp"
|
||||
#include <source_location>
|
||||
#include <map>
|
||||
@@ -11,12 +13,40 @@ namespace jlog
|
||||
{
|
||||
using namespace mcolor;
|
||||
|
||||
class LogEntry {
|
||||
public:
|
||||
//LogEntry(Color4 context_color, const std::string &context, const std::string &message, const std::source_location &trace, const jlog::Timestamp ×tamp) {
|
||||
LogEntry()
|
||||
context_color = Colors::White;
|
||||
context = "FUCK";
|
||||
message = "YOU";
|
||||
trace = std::source_location::current();
|
||||
timestamp = Timestamp();
|
||||
};
|
||||
public:
|
||||
Color4 ContextColor() { return context_color; }
|
||||
std::string Context() { return context; }
|
||||
std::string Message() { return message; }
|
||||
std::source_location Trace() { return trace; }
|
||||
jlog::Timestamp GetTimeStamp() { return timestamp; };
|
||||
std::vector<token> Tokenize();
|
||||
public:
|
||||
bool IncludeTrace;
|
||||
bool IncludeTimestamp;
|
||||
private:
|
||||
Color4 context_color;
|
||||
std::string context;
|
||||
std::string message;
|
||||
std::source_location trace;
|
||||
Timestamp timestamp;
|
||||
};
|
||||
|
||||
///
|
||||
class Logger {
|
||||
public:
|
||||
explicit Logger(const std::string& context, const Color4& color = Colors::LightGray);
|
||||
public:
|
||||
Event<std::vector<token>> OnLogEvent;
|
||||
Event<std::vector<jlog::token>> OnLogEvent;
|
||||
public:
|
||||
void operator () (const std::string& message, const std::source_location& location = std::source_location::current());
|
||||
|
||||
|
@@ -38,6 +38,8 @@ namespace jlog {
|
||||
auto ms = time.subseconds();
|
||||
return std::format("{}-{}-{} {}:{}:{}.{}", y, m, d, h.count(), M.count(), s.count(), ms.count());
|
||||
}
|
||||
|
||||
|
||||
//[2024-Aug-14 12:0:58.815]
|
||||
std::vector<token> timestamp_format(Timestamp tstamp) {
|
||||
return std::vector<token>{{.content = std::format("{}-{}-{} {}:{}:{}.{}", tstamp.Year(), tstamp.Month(), tstamp.Day(), tstamp.Hour().count(), tstamp.Minute().count(), tstamp.Second().count(), tstamp.Millisecond().count())}};
|
||||
|
@@ -6,6 +6,45 @@
|
||||
|
||||
namespace jlog
|
||||
{
|
||||
//LogEntry::LogEntry(const std::string& message, const std::source_location& trace, const Timestamp& timestamp);
|
||||
|
||||
//}
|
||||
|
||||
/*
|
||||
LogEntry::LogEntry(Color4 context_color, const std::string &context, const std::string &message, const std::source_location &trace, const jlog::Timestamp ×tamp) {
|
||||
this->context_color = context_color;
|
||||
this->context = context;
|
||||
this->message = message;
|
||||
this->trace = trace;
|
||||
this->timestamp = timestamp;
|
||||
};
|
||||
*/
|
||||
|
||||
std::vector<token> LogEntry::Tokenize() {
|
||||
std::vector<token> tokens;
|
||||
|
||||
if (IncludeTimestamp)
|
||||
tokens.push_back({.content = std::format(
|
||||
"{}-{}-{} {}:{}:{}.{}",
|
||||
timestamp.Year(),
|
||||
timestamp.Month(),
|
||||
timestamp.Day(),
|
||||
timestamp.Hour().count(),
|
||||
timestamp.Minute().count(),
|
||||
timestamp.Second().count(),
|
||||
timestamp.Millisecond().count())}};)
|
||||
|
||||
tokens.push_back({.colorCode = context_color, .content = context});
|
||||
|
||||
if (IncludeTrace)
|
||||
tokens.push_back({.content = std::format("{}:{}", trace.function_name(), trace.file_name(), trace.line())});
|
||||
|
||||
tokens.push_back({.content = message});
|
||||
|
||||
//tokens.push_back(contextToken);
|
||||
//tokens.push_back(messageToken);
|
||||
}
|
||||
|
||||
Logger::Logger(const std::string& context, const Color4& color) {
|
||||
this->context = context;
|
||||
this->colorcode = color;
|
||||
@@ -15,23 +54,30 @@ namespace jlog
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
std::vector<jlog::token> fmt;
|
||||
LogEntry logentry = {colorcode, context, location, Timestamp()};
|
||||
logentry.IncludeTrace = trace;
|
||||
logentry.IncludeTimestamp = true;
|
||||
|
||||
//std::vector<jlog::token> fmt;
|
||||
|
||||
/*
|
||||
if (trace)
|
||||
fmt = log_format(this->context, message, location.function_name(), location.file_name(), location.line(),this->colorcode);
|
||||
else
|
||||
fmt = log_format(this->context, message, this->colorcode);
|
||||
*/
|
||||
|
||||
OnLogEvent(fmt);
|
||||
//OnLogEvent(fmt);
|
||||
OnLogEvent(logentry.Tokenize());
|
||||
|
||||
//jlog::log_to_console(jlog::toks2consoleMsg(fmt) + '\n');
|
||||
//jlog::log_to_file(this->logfile, jlog::toks2logfileMsg(fmt) + '\n');
|
||||
//jlog::log_to_console(jlog::TokensToString(fmt) + '\n');
|
||||
//jlog::log_to_file(logfile, jlog::TokensToString<WithoutColor>(fmt) + '\n');
|
||||
LogToConsole(fmt);
|
||||
LogToConsole(logentry.Tokenize());
|
||||
LogToConsole("\n");
|
||||
//LogToConsole(std::vector<token>{jlog::endl});
|
||||
LogToFile(logfile, fmt);
|
||||
LogToFile(logfile, logentry.Tokenize());
|
||||
LogToFile(logfile, "\n");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user