Примеры журналирования
This commit is contained in:
parent
746777a822
commit
890272409b
@ -46,6 +46,7 @@ add_subdirectory(src/log)
|
||||
|
||||
# Примеры
|
||||
add_subdirectory(examples/filesystem)
|
||||
add_subdirectory(examples/log)
|
||||
|
||||
add_breathe_target(
|
||||
TARGET_NAME doc-breathe
|
||||
|
42
examples/log/01_minimal/CMakeLists.txt
Normal file
42
examples/log/01_minimal/CMakeLists.txt
Normal file
@ -0,0 +1,42 @@
|
||||
# Название основной цели в текущем каталоге
|
||||
set(current_target minimal)
|
||||
|
||||
# Список файлов исходных текстов
|
||||
set(current_target_sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/minimal.cpp
|
||||
)
|
||||
|
||||
# Путь поиска библиотек внутри проекта
|
||||
link_directories(${CMAKE_INSTALL_LIBDIR})
|
||||
link_directories(${CMAKE_BINARY_DIR}/src/log/lib)
|
||||
|
||||
# Цель для создания исполняемого файла
|
||||
add_executable(${current_target} ${current_target_sources})
|
||||
common_target_properties(${current_target})
|
||||
add_clang_tidy_check(${current_target} ${current_target_sources})
|
||||
add_clang_analyze_check(${current_target} ${current_target_sources})
|
||||
add_clazy_check(${current_target} ${current_target_sources})
|
||||
add_uncrustify_format(${current_target} ${current_target_sources})
|
||||
add_pvs_check(${current_target})
|
||||
|
||||
# Qt5
|
||||
# qt_translation(TARGET ${current_target} TS_DIR ${CMAKE_SOURCE_DIR}/l10n LANGUAGES ru_RU)
|
||||
target_include_directories(${current_target} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${FMT_INCLUDE_DIRS})
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${SPDLOG_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(${current_target} log_static)
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${current_target}
|
||||
PROPERTIES
|
||||
OUTPUT_NAME minimal
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
add_sanitizers(${current_target})
|
||||
|
||||
# cotire(${current_target})
|
||||
|
||||
# Правила для установки
|
||||
install(TARGETS ${current_target} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
21
examples/log/01_minimal/minimal.cpp
Normal file
21
examples/log/01_minimal/minimal.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "log/spdlog.hpp"
|
||||
|
||||
namespace ML = myx::log;
|
||||
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
ML::defaultLogger.enableStdoutSink();
|
||||
|
||||
spdlog::register_logger( ML::defaultLogger.logger() );
|
||||
spdlog::set_default_logger( ML::defaultLogger.logger() );
|
||||
|
||||
ML::info( "aaaa" );
|
||||
ML::trace( "bbbb" );
|
||||
|
||||
spdlog::set_pattern( "[%H:%M:%S %z] %v" );
|
||||
|
||||
ML::info( "aaaa 111" );
|
||||
ML::trace( "bbbb 111" );
|
||||
return( 0 );
|
||||
}
|
45
examples/log/02_qt/CMakeLists.txt
Normal file
45
examples/log/02_qt/CMakeLists.txt
Normal file
@ -0,0 +1,45 @@
|
||||
# Название основной цели в текущем каталоге
|
||||
set(current_target qt)
|
||||
|
||||
# Список файлов исходных текстов
|
||||
set(current_target_sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/qt.cpp
|
||||
)
|
||||
|
||||
# Путь поиска библиотек внутри проекта
|
||||
link_directories(${CMAKE_INSTALL_LIBDIR})
|
||||
link_directories(${CMAKE_BINARY_DIR}/src/log/lib)
|
||||
|
||||
# Цель для создания исполняемого файла
|
||||
add_executable(${current_target} ${current_target_sources})
|
||||
common_target_properties(${current_target})
|
||||
add_clang_tidy_check(${current_target} ${current_target_sources})
|
||||
add_clang_analyze_check(${current_target} ${current_target_sources})
|
||||
add_clazy_check(${current_target} ${current_target_sources})
|
||||
add_uncrustify_format(${current_target} ${current_target_sources})
|
||||
add_pvs_check(${current_target})
|
||||
|
||||
# Qt5
|
||||
# qt_translation(TARGET ${current_target} TS_DIR ${CMAKE_SOURCE_DIR}/l10n LANGUAGES ru_RU)
|
||||
target_include_directories(${current_target} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${FMT_INCLUDE_DIRS})
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${SPDLOG_INCLUDE_DIRS})
|
||||
target_include_directories(${current_target} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
target_compile_options(${current_target} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
|
||||
|
||||
target_link_libraries(${current_target} log_static)
|
||||
target_link_libraries(${current_target} Qt5::Core)
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${current_target}
|
||||
PROPERTIES
|
||||
OUTPUT_NAME qt
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
add_sanitizers(${current_target})
|
||||
|
||||
# cotire(${current_target})
|
||||
|
||||
# Правила для установки
|
||||
install(TARGETS ${current_target} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
24
examples/log/02_qt/qt.cpp
Normal file
24
examples/log/02_qt/qt.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "log/spdlog.hpp"
|
||||
#include "log/spdlog_qt.hpp"
|
||||
|
||||
namespace ML = myx::log;
|
||||
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
ML::defaultLogger.enableStdoutSink();
|
||||
|
||||
spdlog::register_logger( ML::defaultLogger.logger() );
|
||||
spdlog::set_default_logger( ML::defaultLogger.logger() );
|
||||
|
||||
qInstallMessageHandler( ML::spdlog_qt_message_handler );
|
||||
|
||||
qInfo() << "aaaa";
|
||||
qDebug() << "bbbb";
|
||||
|
||||
spdlog::set_pattern( "[%H:%M:%S %z] %v" );
|
||||
|
||||
qInfo( "aaaa 111" );
|
||||
qDebug( "bbbb 111" );
|
||||
return( 0 );
|
||||
}
|
3
examples/log/CMakeLists.txt
Normal file
3
examples/log/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
add_subdirectory(01_minimal)
|
||||
add_subdirectory(02_qt)
|
||||
|
Loading…
Reference in New Issue
Block a user