Made logger more platform agnostic. Hopefully supporting Windows properly for the message formatter functions.
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(std::vector<token> tokens, const std::string& filename);
|
||||
void log(std::vector<token> tokens);
|
||||
void ltlog(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
|
||||
|
||||
|
@@ -21,11 +21,13 @@ namespace jlog {
|
||||
return t.content + " ";
|
||||
}
|
||||
|
||||
void log(std::vector<token> tokens, const std::string& filename)
|
||||
/*
|
||||
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");
|
||||
}
|
||||
*/
|
||||
}
|
@@ -75,13 +75,21 @@ namespace jlog
|
||||
return toks2msg(tokens, logfileMsgFormatter);
|
||||
}
|
||||
|
||||
void log(std::vector<token> tokens)
|
||||
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)
|
||||
{
|
||||
log(tokens, default_logfile);
|
||||
}
|
||||
|
||||
// Mainly for debug purposes
|
||||
void ltlog(std::vector<token> tokens)
|
||||
void ltlog(const std::vector<token> tokens)
|
||||
{
|
||||
log(tokens);
|
||||
log_to_file("logtest.log", toks2logfileMsg(tokens) + "\n");
|
||||
|
@@ -9,6 +9,36 @@ inline void SetConsoleTextColor(WORD color) {
|
||||
|
||||
namespace jlog
|
||||
{
|
||||
// No fucking clue if this will work properly. Don't have a windows machine to test on right now.
|
||||
// - Maxine
|
||||
std::string consoleMsgFormatter(token t)
|
||||
{
|
||||
std::string ft;
|
||||
if (!t.delimiter.empty())
|
||||
{
|
||||
SetConsoleTextColor(t.colorCode.nt_code);
|
||||
ft = std::string(1, t.delimiter[0]) + t.content + std::string(1, t.delimiter[1]) + " "
|
||||
}
|
||||
|
||||
SetConsoleTextColor(t.colorCode.nt_code);
|
||||
ft = t.content + " ";
|
||||
SetConsoleTextColor(color_codes::FG_DEFAULT.nt_code);
|
||||
|
||||
return ft;
|
||||
}
|
||||
|
||||
std::string logfileMsgFormatter(token t)
|
||||
{
|
||||
if (!t.delimiter.empty())
|
||||
{
|
||||
return std::string(1, t.delimiter[0]) + t.content + std::string(1, t.delimiter[1]) + " ";
|
||||
}
|
||||
|
||||
return t.content + " ";
|
||||
}
|
||||
|
||||
// Commented out for now so we can bring it back later if need be
|
||||
/*
|
||||
void log(const std::vector<token> tokens) {
|
||||
for (const token& t : tokens) {
|
||||
if (!t.delimiter.empty()) {
|
||||
@@ -25,4 +55,5 @@ namespace jlog
|
||||
log_to_console("\n");
|
||||
log_to_file("\n");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user