mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-11 06:47:14 +02:00
add logger class (#29)
* add logger class * add LOCATION macro for logger * added printing in files
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
add_executable(json_example json_file_read.cpp)
|
||||
add_executable(numpy_example numpy_file_read.cpp)
|
||||
|
||||
set(EXAMPLE_LIST "json_example;logger_example;numpy_example")
|
||||
foreach(example ${EXAMPLE_LIST})
|
||||
add_executable(${example} ${example}.cpp)
|
||||
target_link_libraries(${example} PUBLIC aare PRIVATE aare_compiler_flags)
|
||||
|
||||
|
||||
endforeach()
|
||||
|
||||
|
||||
target_link_libraries(json_example PRIVATE aare_compiler_flags)
|
||||
target_link_libraries(numpy_example PRIVATE aare_compiler_flags)
|
||||
|
||||
target_link_libraries(json_example PUBLIC aare)
|
||||
target_link_libraries(numpy_example PUBLIC aare)
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Your First C++ Program
|
||||
#include "aare/ContextManager.hpp"
|
||||
#include <iostream>
|
||||
#include "aare/utils/logger.hpp"
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
|
||||
@ -26,4 +27,9 @@ int main() {
|
||||
test(file, 2);
|
||||
test(file, 9);
|
||||
|
||||
aare::logger::debug(LOCATION,"Hello", "World");
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
36
examples/logger_example.cpp
Normal file
36
examples/logger_example.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
int main() {
|
||||
aare::logger::debug(LOCATION, "hello", 1, "world", std::vector<long>{1, 2, 3, 4, 5});
|
||||
aare::logger::debug(LOCATION, "setting verbosity to INFO");
|
||||
aare::logger::set_verbosity(aare::logger::INFO);
|
||||
aare::logger::debug(LOCATION, "NOTHING SHOULD BE PRINTED");
|
||||
aare::logger::info(LOCATION, "info printed");
|
||||
|
||||
|
||||
// writing to file
|
||||
std::ofstream textfile;
|
||||
textfile.open("Test.txt");
|
||||
aare::logger::set_streams(textfile.rdbuf());
|
||||
aare::logger::info(LOCATION, "info printed to file");
|
||||
|
||||
|
||||
|
||||
// writing with a local logger instance
|
||||
aare::logger::Logger logger;
|
||||
logger.set_verbosity(aare::logger::WARNING);
|
||||
logger.debug(LOCATION, "NOTHING SHOULD BE PRINTED");
|
||||
logger.info(LOCATION, "NOTHING SHOULD BE PRINTED");
|
||||
logger.warn(LOCATION, "warning printed in std::cout");
|
||||
aare::logger::info(LOCATION, "info printed in file ##");
|
||||
textfile.close();
|
||||
|
||||
|
||||
// setting file output by path
|
||||
// user doesn't have to close file
|
||||
aare::logger::set_output_file("Test2.txt");
|
||||
aare::logger::info(LOCATION, "info printed to Test2.txt");
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user