parent tracing plus other nice stuff

This commit is contained in:
2024-08-12 13:54:20 -04:00
parent c17a34f0f1
commit 2795756235
4 changed files with 20 additions and 7 deletions

View File

@@ -59,6 +59,7 @@ namespace jlog {
Logger(const std::string& context);
public:
virtual void Log(const std::string &message);
//virtual void Log(const std::vector<token> tokens);
//virtual void Log(const std::string& context, const std::string &message);
virtual void LogTrace(const std::string &message, const std::source_location& location = std::source_location::current());
public:

View File

@@ -12,7 +12,7 @@ namespace jlog {
};
/// These are helper functions designed to be wrapped around for easier custom logger building.
std::string toks2msg(std::vector<token> tokens, std::function<std::string(token)> formatter);
std::string toks2msg(std::vector<token> tokens, std::function<std::string(token)>);
std::string consoleMsgFormatter(token t);
std::string logfileMsgFormatter(token t);
std::string toks2consoleMsg(std::vector<token> tokens);

View File

@@ -101,6 +101,7 @@ int main()
jlog::Logger cock{"COCK"};
//jlog::Logger info{"I"};
jlog::Logger error{"E"};
error.ColorCode(mcolor::ansiColors::Colors::FG_BRIGHT_RED);
//cock.AddChild(&info);
cock.AddChild(&error);
@@ -109,9 +110,9 @@ int main()
error.Log("dick ass");
error.LogTrace("dick ass" " " + error.Parent()->Context());
cock.DelChild("E");
//cock.DelChild("E");
error.LogTrace("dick ass" " " + error.Parent()->Context());
//error.LogTrace("dick ass" " " + error.Parent()->Context());
return 0;

View File

@@ -41,8 +41,13 @@ namespace jlog
std::vector<jlog::token> fmt = log_format(this->context, message, this->colorcode);
jlog::log_to_console(jlog::toks2consoleMsg(fmt) + '\n');
jlog::log_to_file(this->logfile, jlog::toks2logfileMsg(fmt) + '\n');
if (this == this->parent) {
jlog::log_to_console(jlog::toks2consoleMsg(fmt) + '\n');
jlog::log_to_file(this->logfile, jlog::toks2logfileMsg(fmt) + '\n');
} else {
// Using toks2consoleMsg is hacky, but it's a simple solution and it's generic enough
this->parent->Log(jlog::toks2consoleMsg(fmt));
}
}
/*
@@ -59,8 +64,13 @@ namespace jlog
//std::vector<jlog::token> fmt = log_format(this->context, message, func, file, line,this->colorcode);
std::vector<jlog::token> fmt = log_format(this->context, message, location.function_name(), location.file_name(), location.line(),this->colorcode);
jlog::log_to_console(jlog::toks2consoleMsg(fmt) + '\n');
jlog::log_to_file(this->logfile, jlog::toks2logfileMsg(fmt) + '\n');
if (this == this->parent) {
jlog::log_to_console(jlog::toks2consoleMsg(fmt) + '\n');
jlog::log_to_file(this->logfile, jlog::toks2logfileMsg(fmt) + '\n');
} else {
// Using toks2consoleMsg is hacky, but it's a simple solution and it's generic enough
this->parent->Log(jlog::toks2consoleMsg(fmt));
}
}
void Logger::Enabled(bool state) {
@@ -90,6 +100,7 @@ namespace jlog
this->parent = p;
// We make the child inherit the parents traits.
// Is this strictly required? No.
// Should probably mention this may cause side effects.
this->Enabled(p->Enabled());
this->LogFile(p->LogFile());
//p->AddChild(this);