Added cmd arg handling to set log level
Some checks failed
PR Check / on-push-commit-check (push) Has been cancelled
Some checks failed
PR Check / on-push-commit-check (push) Has been cancelled
This commit is contained in:
parent
5ca486bf0a
commit
1834696290
5 changed files with 108 additions and 20 deletions
|
@ -144,7 +144,7 @@ jobs:
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
run: |
|
run: |
|
||||||
cd ${{ github.workspace }}/build_gcc
|
cd ${{ github.workspace }}/build_gcc
|
||||||
./larra_xmpp_tests
|
./larra_xmpp_tests --log_level=0
|
||||||
|
|
||||||
- name: Clang build (only configuring)
|
- name: Clang build (only configuring)
|
||||||
id: clang_build
|
id: clang_build
|
||||||
|
@ -204,4 +204,4 @@ jobs:
|
||||||
# export LLVM_VER=19.1.3
|
# export LLVM_VER=19.1.3
|
||||||
# export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
|
# export PATH="/home/LLVM-${LLVM_VER}/bin:${PATH}"
|
||||||
# cd ${{ github.workspace }}/build_clang
|
# cd ${{ github.workspace }}/build_clang
|
||||||
# ASAN_SYMBOLIZER_PATH=llvm-symbolizer ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=1:detect_leaks=1:atexit=1:abort_on_error=1 ./larra_xmpp_tests
|
# ASAN_SYMBOLIZER_PATH=llvm-symbolizer ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=1:detect_leaks=1:atexit=1:abort_on_error=1 ./larra_xmpp_tests --log_level=0
|
||||||
|
|
6
.vscode/tasks.json
vendored
6
.vscode/tasks.json
vendored
|
@ -193,7 +193,7 @@
|
||||||
"command": [
|
"command": [
|
||||||
"cd ${workspaceFolder} &&",
|
"cd ${workspaceFolder} &&",
|
||||||
"mkdir -p build_clang && cd build_clang &&",
|
"mkdir -p build_clang && cd build_clang &&",
|
||||||
"ASAN_SYMBOLIZER_PATH=llvm-symbolizer ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=1:detect_leaks=1:atexit=1:abort_on_error=1 ./larra_xmpp_tests ; echo \"exit code: $?\"",
|
"ASAN_SYMBOLIZER_PATH=llvm-symbolizer ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=1:detect_leaks=1:atexit=1:abort_on_error=1 ./larra_xmpp_tests --log_level=0 ; echo \"exit code: $?\"",
|
||||||
],
|
],
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"clear": true
|
"clear": true
|
||||||
|
@ -239,7 +239,7 @@
|
||||||
"command": [
|
"command": [
|
||||||
"cd ${workspaceFolder} &&",
|
"cd ${workspaceFolder} &&",
|
||||||
"mkdir -p build_clang && cd build_clang &&",
|
"mkdir -p build_clang && cd build_clang &&",
|
||||||
"MSAN_SYMBOLIZER_PATH=llvm-symbolizer MSAN_OPTIONS=abort_on_error=1 ./larra_xmpp_tests ; echo \"exit code: $?\"",
|
"MSAN_SYMBOLIZER_PATH=llvm-symbolizer MSAN_OPTIONS=abort_on_error=1 ./larra_xmpp_tests --log_level=0 ; echo \"exit code: $?\"",
|
||||||
],
|
],
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"clear": true
|
"clear": true
|
||||||
|
@ -273,7 +273,7 @@
|
||||||
"command": [
|
"command": [
|
||||||
"cd ${workspaceFolder} &&",
|
"cd ${workspaceFolder} &&",
|
||||||
"mkdir -p build_clang && cd build_clang &&",
|
"mkdir -p build_clang && cd build_clang &&",
|
||||||
"MSAN_SYMBOLIZER_PATH=llvm-symbolizer MSAN_OPTIONS=abort_on_error=1 ./larra_xmpp_tests ; echo \"exit code: $?\"",
|
"MSAN_SYMBOLIZER_PATH=llvm-symbolizer MSAN_OPTIONS=abort_on_error=1 ./larra_xmpp_tests --log_level=0 ; echo \"exit code: $?\"",
|
||||||
],
|
],
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"clear": true
|
"clear": true
|
||||||
|
|
|
@ -18,7 +18,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
set(FMT_MODULE OFF)
|
set(FMT_MODULE OFF)
|
||||||
set(UTEMPL_MODULE OFF)
|
set(UTEMPL_MODULE OFF)
|
||||||
set(CXX_EXTENSIONS NO)
|
set(CXX_EXTENSIONS NO)
|
||||||
set(BOOST_INCLUDE_LIBRARIES "pfr;asio;serialization")
|
set(BOOST_INCLUDE_LIBRARIES "pfr;asio;serialization;program_options")
|
||||||
option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON)
|
option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON)
|
||||||
option(UTEMPL_USE_LOCAL_PACKAGE "Use utempl local package" OFF)
|
option(UTEMPL_USE_LOCAL_PACKAGE "Use utempl local package" OFF)
|
||||||
option(BUILD_EXECUTABLE ON)
|
option(BUILD_EXECUTABLE ON)
|
||||||
|
@ -177,11 +177,11 @@ target_include_directories(larra_xmpp PUBLIC
|
||||||
|
|
||||||
if(TARGET Boost::pfr)
|
if(TARGET Boost::pfr)
|
||||||
target_link_libraries(larra_xmpp PUBLIC
|
target_link_libraries(larra_xmpp PUBLIC
|
||||||
Boost::asio Boost::serialization utempl::utempl
|
Boost::asio Boost::serialization Boost::program_options utempl::utempl
|
||||||
OpenSSL::SSL nameof::nameof fmt::fmt
|
OpenSSL::SSL nameof::nameof fmt::fmt
|
||||||
OpenSSL::Crypto spdlog xmlplusplus ${LIBXML2_LIBRARIES})
|
OpenSSL::Crypto spdlog xmlplusplus ${LIBXML2_LIBRARIES})
|
||||||
else()
|
else()
|
||||||
find_package(Boost 1.85.0 COMPONENTS serialization REQUIRED)
|
find_package(Boost 1.85.0 COMPONENTS serialization program_options REQUIRED)
|
||||||
target_link_libraries(larra_xmpp PUBLIC
|
target_link_libraries(larra_xmpp PUBLIC
|
||||||
utempl::utempl ${Boost_LIBRARIES} OpenSSL::SSL
|
utempl::utempl ${Boost_LIBRARIES} OpenSSL::SSL
|
||||||
nameof::nameof fmt::fmt
|
nameof::nameof fmt::fmt
|
||||||
|
|
|
@ -3,11 +3,28 @@
|
||||||
|
|
||||||
#include <boost/asio/co_spawn.hpp>
|
#include <boost/asio/co_spawn.hpp>
|
||||||
#include <boost/asio/detached.hpp>
|
#include <boost/asio/detached.hpp>
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
#include <larra/client/client.hpp>
|
#include <larra/client/client.hpp>
|
||||||
#include <larra/presence.hpp>
|
#include <larra/presence.hpp>
|
||||||
#include <larra/printer_stream.hpp>
|
#include <larra/printer_stream.hpp>
|
||||||
#include <print>
|
#include <print>
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
constexpr auto ToString(spdlog::level::level_enum e) {
|
||||||
|
switch (e) {
|
||||||
|
case spdlog::level::trace: return "TRACE";
|
||||||
|
case spdlog::level::debug: return "DEBUG";
|
||||||
|
case spdlog::level::info: return "INFO";
|
||||||
|
case spdlog::level::warn: return "WARNING";
|
||||||
|
case spdlog::level::err: return "ERROR";
|
||||||
|
case spdlog::level::critical: return "CRITICAL";
|
||||||
|
case spdlog::level::off: return "OFF";
|
||||||
|
default:
|
||||||
|
return "INVALID";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
namespace iq = larra::xmpp::iq;
|
namespace iq = larra::xmpp::iq;
|
||||||
|
|
||||||
auto Coroutine() -> boost::asio::awaitable<void> {
|
auto Coroutine() -> boost::asio::awaitable<void> {
|
||||||
|
@ -50,8 +67,39 @@ auto Coroutine() -> boost::asio::awaitable<void> {
|
||||||
SPDLOG_INFO("Done connecting client!");
|
SPDLOG_INFO("Done connecting client!");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto main() -> int {
|
namespace po = boost::program_options;
|
||||||
spdlog::set_level(spdlog::level::trace);
|
|
||||||
|
auto main(int argc, char** argv) -> int {
|
||||||
|
// Define options
|
||||||
|
po::options_description desc("Allowed options");
|
||||||
|
desc.add_options()("help,h", "Print help message")("log_level,l",
|
||||||
|
po::value<int>()->default_value(SPDLOG_LEVEL_INFO),
|
||||||
|
"Set log level: 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=CRITICAL, 6=OFF");
|
||||||
|
|
||||||
|
// Parse command-line arguments
|
||||||
|
po::variables_map vm;
|
||||||
|
try {
|
||||||
|
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||||
|
po::notify(vm);
|
||||||
|
|
||||||
|
if(vm["log_level"].as<int>() < spdlog::level::level_enum::trace || vm["log_level"].as<int>() > spdlog::level::level_enum::off) {
|
||||||
|
throw std::invalid_argument{
|
||||||
|
std::format("Invalid argument value for '--log_level' option. Check option description for more details")};
|
||||||
|
}
|
||||||
|
if(vm["log_level"].as<int>() < SPDLOG_ACTIVE_LEVEL) {
|
||||||
|
SPDLOG_WARN("Specified log_level '{}' is lower than max available one '{}'. Log level will be changed according to the maximum one",
|
||||||
|
vm["log_level"].as<int>(),
|
||||||
|
SPDLOG_ACTIVE_LEVEL);
|
||||||
|
}
|
||||||
|
} catch(const std::exception& e) {
|
||||||
|
SPDLOG_CRITICAL("Cmd parse error: {}", e.what());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cmd options handling
|
||||||
|
spdlog::set_level(static_cast<spdlog::level::level_enum>(vm["log_level"].as<int>()));
|
||||||
|
std::println("\nEnvironment setup:\n\tCurrently set log level: {}\n", ToString(spdlog::get_level()));
|
||||||
|
|
||||||
boost::asio::io_context io_context;
|
boost::asio::io_context io_context;
|
||||||
boost::asio::co_spawn(io_context, Coroutine(), boost::asio::detached);
|
boost::asio::co_spawn(io_context, Coroutine(), boost::asio::detached);
|
||||||
io_context.run();
|
io_context.run();
|
||||||
|
|
|
@ -1,21 +1,61 @@
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
#include <exception>
|
||||||
#include <print>
|
#include <print>
|
||||||
#include <utility>
|
#include <stdexcept>
|
||||||
|
|
||||||
class PreconfigureEnvironment : public ::testing::Environment {
|
// clang-format off
|
||||||
public:
|
constexpr auto ToString(spdlog::level::level_enum e) {
|
||||||
void SetUp() override {
|
switch (e) {
|
||||||
spdlog::set_level(spdlog::level::trace);
|
case spdlog::level::trace: return "TRACE";
|
||||||
std::println("\nPreconfigureEnvironment setup:\n\tCompiled max availabel log level: {}\n\tCurrently set log level: {}",
|
case spdlog::level::debug: return "DEBUG";
|
||||||
SPDLOG_ACTIVE_LEVEL,
|
case spdlog::level::info: return "INFO";
|
||||||
std::to_underlying(spdlog::get_level()));
|
case spdlog::level::warn: return "WARNING";
|
||||||
|
case spdlog::level::err: return "ERROR";
|
||||||
|
case spdlog::level::critical: return "CRITICAL";
|
||||||
|
case spdlog::level::off: return "OFF";
|
||||||
|
default:
|
||||||
|
return "INVALID";
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
auto main(int argc, char** argv) -> int {
|
auto main(int argc, char** argv) -> int {
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
::testing::AddGlobalTestEnvironment(new PreconfigureEnvironment); // NOLINT GTest takes ownership
|
|
||||||
|
// Define options
|
||||||
|
po::options_description desc("Allowed options");
|
||||||
|
desc.add_options()("help,h", "Print help message")("log_level,l",
|
||||||
|
po::value<int>()->default_value(SPDLOG_LEVEL_INFO),
|
||||||
|
"Set log level: 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=CRITICAL, 6=OFF");
|
||||||
|
|
||||||
|
// Parse command-line arguments
|
||||||
|
po::variables_map vm;
|
||||||
|
try {
|
||||||
|
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||||
|
po::notify(vm);
|
||||||
|
|
||||||
|
if(vm["log_level"].as<int>() < spdlog::level::level_enum::trace || vm["log_level"].as<int>() > spdlog::level::level_enum::off) {
|
||||||
|
throw std::invalid_argument{
|
||||||
|
std::format("Invalid argument value for '--log_level' option. Check option description for more details")};
|
||||||
|
}
|
||||||
|
if(vm["log_level"].as<int>() < SPDLOG_ACTIVE_LEVEL) {
|
||||||
|
SPDLOG_WARN("Specified log_level '{}' is lower than max available one '{}'. Log level will be changed according to the maximum one",
|
||||||
|
vm["log_level"].as<int>(),
|
||||||
|
SPDLOG_ACTIVE_LEVEL);
|
||||||
|
}
|
||||||
|
} catch(const std::exception& e) {
|
||||||
|
SPDLOG_CRITICAL("Cmd parse error: {}", e.what());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cmd options handling
|
||||||
|
spdlog::set_level(static_cast<spdlog::level::level_enum>(vm["log_level"].as<int>()));
|
||||||
|
std::println("\nEnvironment setup:\n\tCurrently set log level: {}\n", ToString(spdlog::get_level()));
|
||||||
|
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
Loading…
Reference in a new issue