got carried away with some debug logging infrastructure
This commit is contained in:
@@ -61,6 +61,11 @@ $ ./build/ouros
|
||||
# or on windows:
|
||||
.\build\Debug\ouros.exe
|
||||
```
|
||||
For control on debugging:
|
||||
```bash
|
||||
$ ./build/ouros --debug 0b00111111
|
||||
```
|
||||
where each bit in the mask corresponds to a debug level, in order: unused, unused, fatal, trace, error, warning, notice, and info. `0b1111111` enables all debug messages.
|
||||
|
||||
## Additional Resources
|
||||
- https://howtovulkan.com/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
App::App() {
|
||||
|
||||
utils::debugPrint(__FUNCTION__, __LINE__, "App constructor.");
|
||||
utils::debugPrint(__FUNCTION__, __LINE__, "App constructor.", utils::DebugLevel::Trace);
|
||||
|
||||
init();
|
||||
|
||||
@@ -13,7 +13,7 @@ App::App() {
|
||||
|
||||
void App::init() {
|
||||
|
||||
utils::debugPrint(__FUNCTION__, __LINE__, "Init app.");
|
||||
utils::debugPrint(__FUNCTION__, __LINE__, "Init app.", utils::DebugLevel::Trace);
|
||||
|
||||
window_ = new Window();
|
||||
|
||||
@@ -21,12 +21,11 @@ void App::init() {
|
||||
|
||||
int App::run() {
|
||||
|
||||
utils::debugPrint(__FUNCTION__, __LINE__, "Run app.");
|
||||
utils::debugPrint(__FUNCTION__, __LINE__, "Run app.", utils::DebugLevel::Trace);
|
||||
|
||||
bool quit = false;
|
||||
while (!quit) {
|
||||
// app loop for as long as the window is open
|
||||
// poll events here
|
||||
// other threads might be able to change quit to true to auto close
|
||||
|
||||
SDL_Event event;
|
||||
|
||||
16
src/main.cpp
16
src/main.cpp
@@ -1,13 +1,23 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#include "app/App.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
int main(int arg, char *argv[]) {
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
std::string message = "main()";
|
||||
utils::debugPrint(__FUNCTION__, __LINE__, message);
|
||||
// parsing executable arguments
|
||||
// TODO: move elsewhere
|
||||
// this is for the debug mask
|
||||
for(int i = 1; i < argc; i++) {
|
||||
if(std::strncmp(argv[i], "--debug=", 8) == 0) {
|
||||
std::string debugMaskString = argv[i] + 8;
|
||||
utils::parseDebugMaskString(debugMaskString);
|
||||
}
|
||||
}
|
||||
|
||||
utils::debugPrint(__FUNCTION__, __LINE__, "main()", utils::DebugLevel::Trace);
|
||||
|
||||
// maybe do some exceptions here
|
||||
App app = App();
|
||||
|
||||
@@ -1,22 +1,57 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
|
||||
// TODO: might move a lot of this into a debug.h file
|
||||
// TODO: logging ? but i dont care enough
|
||||
|
||||
namespace utils {
|
||||
|
||||
// TODO: implement
|
||||
enum class DebugLevel {
|
||||
enum DebugLevel : size_t {
|
||||
Info = 0,
|
||||
Notice,
|
||||
Error
|
||||
Warning,
|
||||
Error,
|
||||
Trace,
|
||||
Fatal,
|
||||
Extra1,
|
||||
Extra2
|
||||
};
|
||||
|
||||
static void debugPrint(const char* function, int line, std::string message) {
|
||||
static const char* debugTypeStrings[] = {
|
||||
"Info",
|
||||
"Notice",
|
||||
"Warning",
|
||||
"Error",
|
||||
"Trace",
|
||||
"Fatal",
|
||||
"Extra1",
|
||||
"Extra2"
|
||||
};
|
||||
// the idea is to have a debug bitmask, maybe 8 bits wide, where the bits can be set via compiler flags
|
||||
|
||||
std::cout << "[ " << std::left << std::setw(16) << function << ": " << std::right << std::setw(4) << line << " ] " << message << std::endl;
|
||||
inline uint8_t debugMask;
|
||||
|
||||
static void debugPrint(const char* function, int line, std::string message, size_t debugLevel) {
|
||||
|
||||
if(!(debugMask >> debugLevel)) return; // then ignore this debug level
|
||||
|
||||
std::cout << "[ " << std::left << std::setw(16) << function << ": " << std::right << std::setw(4) << line << ", " << std::left << std::setw(8) << debugTypeStrings[debugLevel] << " ] " << message << std::endl;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void parseDebugMaskString(std::string& debugMaskString) {
|
||||
std::string value = debugMaskString;
|
||||
if(value.rfind("0b", 0) == 0) {
|
||||
value = value.substr(2); // strip the binary literal identifier
|
||||
} else {
|
||||
std::cout << "Unsupported debug key." << std::endl;
|
||||
}
|
||||
debugMask = static_cast<uint8_t>(std::stoul(value, nullptr, 2)); // interpret a string as a uint
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user