boost logger

This commit is contained in:
Christoph J. Scherr 2023-10-18 20:02:46 +02:00
parent 001d795b73
commit b3acf81398
4 changed files with 22 additions and 15 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ CMakeDoxygenDefaults.cmake
Makefile Makefile
cmake_install.cmake cmake_install.cmake
bin/loader/loader bin/loader/loader
lib/glfw

View File

@ -30,7 +30,7 @@ source_group("sources" FILES ${PROJECT_SOURCES})
source_group("vendors" FILES ${VENDORS_SOURCES}) source_group("vendors" FILES ${VENDORS_SOURCES})
find_package(Boost 1.56 REQUIRED COMPONENTS find_package(Boost 1.56 REQUIRED COMPONENTS
program_options) program_options log)
set(EXE_1_NAME loader) set(EXE_1_NAME loader)
file( file(
@ -41,7 +41,7 @@ set(CMAKE_BINARY_DIR "bin")
add_executable(${EXE_1_NAME} ${EXE_1_SOURCES} ${PROJECT_HEADERS} add_executable(${EXE_1_NAME} ${EXE_1_SOURCES} ${PROJECT_HEADERS}
${PROJECT_SHADERS} ${VENDORS_SOURCES}) ${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) target_include_directories(${EXE_1_NAME} PRIVATE include)
set_target_properties(${EXE_1_NAME} PROPERTIES set_target_properties(${EXE_1_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${EXE_1_NAME}) RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${EXE_1_NAME})

View File

@ -1,4 +1,3 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@ -33,16 +32,22 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
} catch (po::error &e) { } catch (po::error &e) {
cout << e.what() << endl << endl; BOOST_LOG_TRIVIAL(fatal) << e.what() << endl << endl;
help(argv[0], desc); help(argv[0], desc);
return EXIT_USAGE; 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")) { if (vm.count("verbose")) {
// TODO: make verbose flag somehow global? boost::log::core::get()->set_filter(boost::log::trivial::severity >=
printf("Reading shader files\n"); 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<string>()); ifstream vertexFileStream(vm["vert"].as<string>());
ifstream fragFileStream(vm["frag"].as<string>()); ifstream fragFileStream(vm["frag"].as<string>());
std::stringstream vertexSource; std::stringstream vertexSource;
@ -51,28 +56,26 @@ int main(int argc, char **argv) {
fragSource << fragFileStream.rdbuf(); fragSource << fragFileStream.rdbuf();
if (vertexFileStream.fail()) { 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; return EXIT_IO;
} }
if (fragFileStream.fail()) { 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; return EXIT_IO;
} }
vertexFileStream.close(); vertexFileStream.close();
fragFileStream.close(); fragFileStream.close();
if (vm.count("verbose")) { BOOST_LOG_TRIVIAL(trace) << "Creating ShaderProgram";
printf("Creating ShaderProgram\n");
}
// TODO: determinde ShaderProgram::Base with a CLI arg // TODO: determinde ShaderProgram::Base with a CLI arg
ShaderProgram shaderProgram(ShaderProgram::Base::Empty, vertexSource.str(), ShaderProgram shaderProgram(ShaderProgram::Base::Empty, vertexSource.str(),
fragSource.str()); fragSource.str());
/* Run our main program */ /* Run our main program */
if (vm.count("verbose")) { BOOST_LOG_TRIVIAL(trace) << "Starting mainWindow";
printf("Starting mainWindow\n");
}
int result = mainWindow(&shaderProgram); int result = mainWindow(&shaderProgram);
return result; return result;

View File

@ -4,6 +4,9 @@
#include <boost/program_options/parsers.hpp> #include <boost/program_options/parsers.hpp>
#include <boost/program_options/positional_options.hpp> #include <boost/program_options/positional_options.hpp>
#include <boost/program_options/variables_map.hpp> #include <boost/program_options/variables_map.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include "graphics.hpp" #include "graphics.hpp"