Примеры журналирования

This commit is contained in:
Andrei Astafev 2019-10-03 16:47:38 +03:00
parent 746777a822
commit 890272409b
6 changed files with 136 additions and 0 deletions

View File

@ -46,6 +46,7 @@ add_subdirectory(src/log)
# Примеры
add_subdirectory(examples/filesystem)
add_subdirectory(examples/log)
add_breathe_target(
TARGET_NAME doc-breathe

View 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})

View 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 );
}

View 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
View 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 );
}

View File

@ -0,0 +1,3 @@
add_subdirectory(01_minimal)
add_subdirectory(02_qt)