Merge pull request 'Allow disabling of console output for logging. New macro CONSOLELOGGING set to true/false to enable/disable.' (#13) from mcolortest into main
Reviewed-on: #13
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
namespace jlog
|
||||
{
|
||||
|
||||
/// Severity levels for logging. Higher numbers filter less messages out.
|
||||
/// @see LOG_LEVEL macro
|
||||
enum class severity : uint8_t
|
||||
@@ -34,6 +35,7 @@ namespace jlog
|
||||
};
|
||||
|
||||
inline severity loglevel = severity::debug; // Default log level always debug
|
||||
inline bool console_logging = true;
|
||||
|
||||
struct LogEntry
|
||||
{
|
||||
@@ -235,5 +237,7 @@ namespace jlog
|
||||
|
||||
#define LOGLEVEL(i) jlog::loglevel = i;
|
||||
|
||||
#define CONSOLELOGGING(i) jlog::console_logging = i
|
||||
|
||||
#define LOGTEST(i) if (jlog::loglevel >= jlog::severity::none) { jlog::ltlog(jlog::info_detailed_format(i, FUNCTION, __FILE__, __LINE__)); }
|
||||
|
||||
|
1
main.cpp
1
main.cpp
@@ -23,6 +23,7 @@
|
||||
int main()
|
||||
{
|
||||
LOGLEVEL(jlog::severity::debug); // <- see jlog::severity for full list of log levels
|
||||
CONSOLELOGGING(true); // <- Set to true or false to enable/disable logging to console. Useful for release builds of a program.
|
||||
|
||||
INFO("This is barely useful information.");
|
||||
DEBUG("Debugging Information");
|
||||
|
@@ -37,24 +37,9 @@ namespace jlog
|
||||
|
||||
void log_to_console(const std::string& message)
|
||||
{
|
||||
|
||||
// Beat windows into submission and make it use ANSI color codes
|
||||
// This also looks fugly, but it works
|
||||
/*
|
||||
#ifdef WIN32
|
||||
HANDLE handleOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD consoleMode;
|
||||
GetConsoleMode( handleOut, &consoleMode);
|
||||
consoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
consoleMode |= DISABLE_NEWLINE_AUTO_RETURN;
|
||||
SetConsoleMode( handleOut , consoleMode );
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
#endif
|
||||
*/
|
||||
#ifdef WIN32
|
||||
mcolor::windowsSaneify();
|
||||
#endif
|
||||
|
||||
std::cout << message;
|
||||
}
|
||||
|
||||
@@ -119,8 +104,10 @@ namespace jlog
|
||||
|
||||
void log(const std::vector<token>& tokens, const std::string& filename)
|
||||
{
|
||||
log_to_console(toks2consoleMsg(tokens));
|
||||
log_to_console("\n");
|
||||
if (console_logging) {
|
||||
log_to_console(toks2consoleMsg(tokens));
|
||||
log_to_console("\n");
|
||||
}
|
||||
log_to_file(filename, toks2logfileMsg(tokens));
|
||||
log_to_file(filename, "\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user