-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from StrataSource/refactor/simplify-logging
Simplify the logging system
- Loading branch information
Showing
20 changed files
with
122 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
run | ||
.idea | ||
cmake-build-* | ||
cmake-build-* | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "log.hpp" | ||
#include <iostream> | ||
|
||
bool g_bUIReportMode = false; | ||
|
||
void Log_Message( LogSeverity severity, const std::string_view message ) | ||
{ | ||
// Don't log in report only mode! | ||
const char* prefixes[] = { | ||
"Info", | ||
"Warn", | ||
"Error", | ||
}; | ||
const char* prefix = prefixes[(int)severity]; | ||
|
||
if ( g_bUIReportMode ) | ||
{ | ||
// Print for UI to read | ||
const auto line{ fmt::format( R"("message","{}","{}",,)", prefix, message ) }; | ||
std::printf( "%s\n", line.c_str() ); | ||
} | ||
else | ||
{ | ||
// Standard print | ||
std::cout << prefix << ": " << message << "\n"; | ||
} | ||
} | ||
|
||
void Log_Report( const std::string_view file, const std::string_view message, const std::string_view got, const std::string_view expected ) | ||
{ | ||
if ( g_bUIReportMode ) | ||
{ | ||
const auto line{ fmt::format( R"("report","{}","{}","{}","{}")", file, message, got, expected ) }; | ||
std::printf( "%s\n", line.c_str() ); | ||
} | ||
else | ||
{ | ||
const auto line{ fmt::format( "In file `{}`: {}", file, message ) }; | ||
std::fprintf( stderr, "%s\n", line.c_str() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <fmt/format.h> | ||
#include <fmt/chrono.h> | ||
|
||
enum class LogSeverity | ||
{ | ||
Info, | ||
Warn, | ||
Error, | ||
}; | ||
|
||
// Base logging function | ||
void Log_Message( LogSeverity severity, const std::string_view message ); | ||
|
||
// Report | ||
extern bool g_bUIReportMode; | ||
void Log_Report( const std::string_view file, const std::string_view message, const std::string_view got, const std::string_view expected ); | ||
|
||
// Logging helpers | ||
template <typename... Ts> | ||
inline void Log_Info( const fmt::format_string<Ts...> fmt, Ts&&... args ) | ||
{ | ||
Log_Message( LogSeverity::Info, fmt::format( fmt, std::forward<Ts>( args )... ) ); | ||
} | ||
|
||
template <typename... Ts> | ||
inline void Log_Warn( const fmt::format_string<Ts...> fmt, Ts&&... args ) | ||
{ | ||
Log_Message( LogSeverity::Warn, fmt::format( fmt, std::forward<Ts>( args )... ) ); | ||
} | ||
|
||
template <typename... Ts> | ||
inline void Log_Error( const fmt::format_string<Ts...> fmt, Ts&&... args ) | ||
{ | ||
Log_Message( LogSeverity::Error, fmt::format( fmt, std::forward<Ts>(args)... ) ); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.