Unfortunate regression to get Windows ColorCodes working again. Will clean up shortly. (Test On Linux Also)
This commit is contained in:
@@ -90,9 +90,9 @@ namespace jlog
|
||||
/// logging callback (Event)
|
||||
/// @note This file is implemented differently per-platform to handle differences in console color handling.
|
||||
/// @see windows/jlog.cpp linux/jlog.cpp
|
||||
void log(const std::vector<token> tokens, const std::string& filename);
|
||||
void log(const std::vector<token> tokens);
|
||||
void ltlog(const std::vector<token> tokens); // Just for debug purposes
|
||||
void log(const std::vector<token>& tokens, const std::string& filename);
|
||||
void log(const std::vector<token>& tokens);
|
||||
void ltlog(const std::vector<token>& tokens); // Just for debug purposes
|
||||
|
||||
#pragma region Generic Formatters
|
||||
|
||||
|
@@ -1,6 +1,26 @@
|
||||
#include <jlog/jlog.hpp>
|
||||
|
||||
namespace jlog {
|
||||
|
||||
void log(const std::vector<token>& tokens, const std::string& filename)
|
||||
{
|
||||
for (const token& t : tokens)
|
||||
{
|
||||
|
||||
if (!t.delimiter.empty()) {
|
||||
auto formatted_str = std::format("{}{}{}{}{} ", t.colorCode.ansi_code, t.delimiter[0], t.content, t.delimiter[1], ansi_escape_codes::FG_DEFAULT);
|
||||
log_to_console(formatted_str);
|
||||
log_to_file(filename, formatted_str);
|
||||
} else {
|
||||
auto formatted_str = std::format("{}{}{} ", t.colorCode.ansi_code, t.content, ansi_escape_codes::FG_DEFAULT);
|
||||
log_to_console(t.content);
|
||||
log_to_file(filename, t.content);
|
||||
}
|
||||
}
|
||||
log_to_file(filename, "\n");
|
||||
log_to_console("\n");
|
||||
}
|
||||
|
||||
std::string consoleMsgFormatter(token t)
|
||||
{
|
||||
if (!t.delimiter.empty())
|
||||
|
@@ -55,44 +55,36 @@ namespace jlog
|
||||
stream << message;
|
||||
}
|
||||
|
||||
std::string toks2msg(std::vector<token> tokens, std::function<std::string(token)> formatter)
|
||||
{
|
||||
std::string msg;
|
||||
for (const token& t: tokens)
|
||||
{
|
||||
msg += formatter(t);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
//std::string toks2msg(std::vector<token> tokens, std::function<std::string(token)> formatter)
|
||||
//{
|
||||
// std::string msg;
|
||||
// for (const token& t: tokens)
|
||||
// {
|
||||
// msg += formatter(t);
|
||||
// }
|
||||
// return msg;
|
||||
//}
|
||||
|
||||
std::string toks2consoleMsg(std::vector<token> tokens)
|
||||
{
|
||||
return toks2msg(tokens, consoleMsgFormatter);
|
||||
}
|
||||
//std::string toks2consoleMsg(std::vector<token> tokens)
|
||||
//{
|
||||
// return toks2msg(tokens, consoleMsgFormatter);
|
||||
//}
|
||||
|
||||
std::string toks2logfileMsg(std::vector<token> tokens)
|
||||
{
|
||||
return toks2msg(tokens, logfileMsgFormatter);
|
||||
}
|
||||
//std::string toks2logfileMsg(std::vector<token> tokens)
|
||||
//{
|
||||
// return toks2msg(tokens, logfileMsgFormatter);
|
||||
//}
|
||||
|
||||
void log(const std::vector<token> tokens, const std::string& filename)
|
||||
{
|
||||
log_to_console(toks2consoleMsg(tokens));
|
||||
log_to_console("\n");
|
||||
log_to_file(filename, toks2logfileMsg(tokens));
|
||||
log_to_file(filename, "\n");
|
||||
}
|
||||
|
||||
void log(const std::vector<token> tokens)
|
||||
void log(const std::vector<token>& tokens)
|
||||
{
|
||||
log(tokens, default_logfile);
|
||||
}
|
||||
|
||||
// Mainly for debug purposes
|
||||
void ltlog(const std::vector<token> tokens)
|
||||
void ltlog(const std::vector<token>& tokens)
|
||||
{
|
||||
log(tokens);
|
||||
log_to_file("logtest.log", toks2logfileMsg(tokens) + "\n");
|
||||
//log_to_file("logtest.log", toks2logfileMsg(tokens) + "\n");
|
||||
}
|
||||
|
||||
std::vector<token> trace_format(
|
||||
|
@@ -7,6 +7,30 @@ inline void SetConsoleTextColor(WORD color) {
|
||||
|
||||
namespace jlog
|
||||
{
|
||||
|
||||
void log(const std::vector<token>& tokens, const std::string& filename)
|
||||
{
|
||||
for (const token& t : tokens)
|
||||
{
|
||||
|
||||
std::string formatted_str;
|
||||
if (!t.delimiter.empty()) {
|
||||
formatted_str = std::format("{}{}{} ", t.delimiter[0], t.content, t.delimiter[1]);
|
||||
} else {
|
||||
formatted_str = t.content + " ";
|
||||
}
|
||||
|
||||
SetConsoleTextColor(t.colorCode.nt_code);
|
||||
log_to_console(formatted_str);
|
||||
SetConsoleTextColor(nt_color_codes::FG_DEFAULT);
|
||||
|
||||
log_to_file(filename, formatted_str);
|
||||
}
|
||||
log_to_file(filename, "\n");
|
||||
log_to_console("\n");
|
||||
}
|
||||
|
||||
|
||||
// No fucking clue if this will work properly. Don't have a windows machine to test on right now.
|
||||
// - Maxine
|
||||
// No for a number of reasons
|
||||
@@ -27,7 +51,7 @@ namespace jlog
|
||||
}
|
||||
|
||||
SetConsoleTextColor(t.colorCode.nt_code);
|
||||
return t.content;
|
||||
return t.content + " ";
|
||||
SetConsoleTextColor(color_codes::FG_DEFAULT.nt_code);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user