Implemented ability to specify custom logfile globally and per-function. Wrote helper functions to make writing custom loggers easier. Still need to work on the windows side of things, but that should be easy.

This commit is contained in:
2024-06-28 12:59:07 -04:00
parent e5d8ea5faa
commit 3e414abc8d
4 changed files with 72 additions and 10 deletions

View File

@@ -72,13 +72,24 @@ namespace jlog
/// @note Does not append a newline to the message.
void log_to_stream(std::ostream stream, const std::string& message);
/// These are helper functions designed to be wrapped around for easier custom logger building.
/// @note This file is implemented differently per-platform to handle differences in console color handling.
/// @see windows/jlog.cpp linux/jlog.cpp
std::string toks2msg(std::vector<token> tokens, std::string (*formatter)(token));
std::string consoleMsgFormatter(token t);
std::string logfileMsgFormatter(token t);
std::string toks2consoleMsg(std::vector<token> tokens);
std::string toks2logfileMsg(std::vector<token> tokens);
/// Parses a sequence of tokens into a printable message, and logs to the following destinations:
/// standard output (console)
/// output file (default)
/// 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
// Generic formatters for building loggers.
@@ -164,3 +175,5 @@ namespace jlog
#define LOGLEVEL(i) jlog::loglevel = i;
#define LOGTEST(i) if (jlog::loglevel >= jlog::severity::none) { jlog::ltlog(jlog::info_detailed_format(i, FUNCTION, __FILE__, __LINE__)); }