From b3acf81398f7d4d996329db50c50ae51428f5acd Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Wed, 18 Oct 2023 20:02:46 +0200 Subject: [PATCH] boost logger --- .gitignore | 1 + CMakeLists.txt | 4 ++-- src/main.cpp | 29 ++++++++++++++++------------- src/main.hpp | 3 +++ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 21e35dd..f5b4d09 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ CMakeDoxygenDefaults.cmake Makefile cmake_install.cmake bin/loader/loader +lib/glfw diff --git a/CMakeLists.txt b/CMakeLists.txt index f161bb5..c5b3afe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ source_group("sources" FILES ${PROJECT_SOURCES}) source_group("vendors" FILES ${VENDORS_SOURCES}) find_package(Boost 1.56 REQUIRED COMPONENTS - program_options) + program_options log) set(EXE_1_NAME loader) file( @@ -41,7 +41,7 @@ set(CMAKE_BINARY_DIR "bin") add_executable(${EXE_1_NAME} ${EXE_1_SOURCES} ${PROJECT_HEADERS} ${PROJECT_SHADERS} ${VENDORS_SOURCES}) -target_link_libraries(${EXE_1_NAME} glfw Boost::program_options) +target_link_libraries(${EXE_1_NAME} glfw Boost::program_options Boost::log) target_include_directories(${EXE_1_NAME} PRIVATE include) set_target_properties(${EXE_1_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${EXE_1_NAME}) diff --git a/src/main.cpp b/src/main.cpp index 2ad608c..e2f74c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,3 @@ - #include #include @@ -33,16 +32,22 @@ int main(int argc, char **argv) { return 1; } } catch (po::error &e) { - cout << e.what() << endl << endl; + BOOST_LOG_TRIVIAL(fatal) << e.what() << endl << endl; help(argv[0], desc); return EXIT_USAGE; } - /* setup the shader program */ + // set boost log level to trace on verbose + // TODO: -v should decrease the default log level by 1 but be repeatable. + // (default should be info) if (vm.count("verbose")) { - // TODO: make verbose flag somehow global? - printf("Reading shader files\n"); + boost::log::core::get()->set_filter(boost::log::trivial::severity >= + boost::log::trivial::trace); + BOOST_LOG_TRIVIAL(trace) << "verbose flag found, setting log level to trace"; } + + /* setup the shader program */ + BOOST_LOG_TRIVIAL(trace) << "Reading shader files"; ifstream vertexFileStream(vm["vert"].as()); ifstream fragFileStream(vm["frag"].as()); std::stringstream vertexSource; @@ -51,28 +56,26 @@ int main(int argc, char **argv) { fragSource << fragFileStream.rdbuf(); if (vertexFileStream.fail()) { - cout << "Error while reading the vertex shader file." << endl; + BOOST_LOG_TRIVIAL(fatal) + << "Error while reading the vertex shader file."; return EXIT_IO; } if (fragFileStream.fail()) { - cout << "Error while reading the frag shader file." << endl; + BOOST_LOG_TRIVIAL(fatal) + << "Error while reading the frag shader file."; return EXIT_IO; } vertexFileStream.close(); fragFileStream.close(); - if (vm.count("verbose")) { - printf("Creating ShaderProgram\n"); - } + BOOST_LOG_TRIVIAL(trace) << "Creating ShaderProgram"; // TODO: determinde ShaderProgram::Base with a CLI arg ShaderProgram shaderProgram(ShaderProgram::Base::Empty, vertexSource.str(), fragSource.str()); /* Run our main program */ - if (vm.count("verbose")) { - printf("Starting mainWindow\n"); - } + BOOST_LOG_TRIVIAL(trace) << "Starting mainWindow"; int result = mainWindow(&shaderProgram); return result; diff --git a/src/main.hpp b/src/main.hpp index 7fd719f..de0a69f 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include #include "graphics.hpp"