commit 26ce684fb74841958582ba506214bb6b7f4e423e Author: James Pace Date: Mon Aug 4 08:23:37 2025 -0400 Init commit. diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0a74252 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.8) +project(logging_debug) + +add_compile_options(-Wall -Wextra -Wpedantic) + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(rclcpp REQUIRED) +find_package(spdlog REQUIRED) + +add_executable(roslog src/roslog.cpp) +target_link_libraries(roslog rclcpp::rclcpp) +target_compile_features(roslog PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 + +add_executable(spdlog src/spdlog.cpp) +target_link_libraries(spdlog rclcpp::rclcpp spdlog::spdlog) +target_compile_features(spdlog PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 + +add_executable(nolog src/nolog.cpp) +target_link_libraries(nolog rclcpp::rclcpp) +target_compile_features(nolog PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 + +add_executable(spdlog_macro src/spdlog_macro.cpp) +target_link_libraries(spdlog_macro rclcpp::rclcpp spdlog::spdlog) +target_compile_features(spdlog_macro PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 +target_compile_definitions(spdlog_macro PRIVATE SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO) + + +install(TARGETS + roslog + spdlog + spdlog_macro + nolog + DESTINATION lib/${PROJECT_NAME}) + +ament_package() diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..e45288b --- /dev/null +++ b/package.xml @@ -0,0 +1,18 @@ + + + + logging_debug + 0.0.0 + TODO: Package description + jimmy + MPL-2.0 + + rclcpp + spdlog + + ament_cmake + + + ament_cmake + + diff --git a/src/nolog.cpp b/src/nolog.cpp new file mode 100644 index 0000000..d6b8fe2 --- /dev/null +++ b/src/nolog.cpp @@ -0,0 +1,56 @@ +/* Copyright 2025 James Pace + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. + */ + +#include +#include +#include + +#include "rclcpp/rclcpp.hpp" + +using namespace std::chrono_literals; + +class Publisher : public rclcpp::Node +{ + public: + Publisher(): + Node("roslog") + { + timer_ = this->create_wall_timer(100ms, [this]() + { + timer_->cancel(); + + volatile double val = 0; + const auto start = std::chrono::steady_clock::now(); + for(int i = 0; i < 10000; i++) + { + val = val + 0.001*(1.0 - val); + } + const auto end = std::chrono::steady_clock::now(); + + const std::chrono::duration diff = end - start; + RCLCPP_INFO_STREAM(this->get_logger(), "val: " << val); + RCLCPP_INFO_STREAM(this->get_logger(), "Time delta: " << diff.count()); + + + std::exit(0); + }); + } + + private: + rclcpp::TimerBase::SharedPtr timer_; +}; + +int main(int argc, char * argv[]) +{ + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +} diff --git a/src/roslog.cpp b/src/roslog.cpp new file mode 100644 index 0000000..bdcd4a4 --- /dev/null +++ b/src/roslog.cpp @@ -0,0 +1,56 @@ +/* Copyright 2025 James Pace + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. + */ + +#include +#include +#include + +#include "rclcpp/rclcpp.hpp" + +using namespace std::chrono_literals; + +class Publisher : public rclcpp::Node +{ + public: + Publisher(): + Node("roslog") + { + timer_ = this->create_wall_timer(100ms, [this]() + { + timer_->cancel(); + + double val = 0; + const auto start = std::chrono::steady_clock::now(); + for(int i = 0; i < 10000; i++) + { + val = val + 0.001*(1.0 - val); + RCLCPP_DEBUG_STREAM(this->get_logger(), "Val is " << val); + } + const auto end = std::chrono::steady_clock::now(); + + const std::chrono::duration diff = end - start; + RCLCPP_WARN_STREAM(this->get_logger(), "Time delta: " << diff.count()); + + + std::exit(0); + }); + } + + private: + rclcpp::TimerBase::SharedPtr timer_; +}; + +int main(int argc, char * argv[]) +{ + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +} diff --git a/src/spdlog.cpp b/src/spdlog.cpp new file mode 100644 index 0000000..94a162a --- /dev/null +++ b/src/spdlog.cpp @@ -0,0 +1,58 @@ +/* Copyright 2025 James Pace + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. + */ + +#include +#include +#include + +#include "rclcpp/rclcpp.hpp" +#include "spdlog/spdlog.h" +#include "spdlog/cfg/env.h" + +using namespace std::chrono_literals; + +class Publisher : public rclcpp::Node +{ + public: + Publisher(): + Node("spdlog") + { + timer_ = this->create_wall_timer(100ms, [this]() + { + timer_->cancel(); + + double val = 0; + const auto start = std::chrono::steady_clock::now(); + for(int i = 0; i < 10000; i++) + { + val = val + 0.001*(1.0 - val); + spdlog::info("Val is {}", val); + } + const auto end = std::chrono::steady_clock::now(); + + const std::chrono::duration diff = end - start; + spdlog::error("Time delta: {}", diff.count()); + + std::exit(0); + }); + } + + private: + rclcpp::TimerBase::SharedPtr timer_; +}; + +int main(int argc, char * argv[]) +{ + spdlog::cfg::load_env_levels(); + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +} diff --git a/src/spdlog_macro.cpp b/src/spdlog_macro.cpp new file mode 100644 index 0000000..43cb0ad --- /dev/null +++ b/src/spdlog_macro.cpp @@ -0,0 +1,58 @@ +/* Copyright 2025 James Pace + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. + */ + +#include +#include +#include + +#include "rclcpp/rclcpp.hpp" +#include "spdlog/spdlog.h" +#include "spdlog/cfg/env.h" + +using namespace std::chrono_literals; + +class Publisher : public rclcpp::Node +{ + public: + Publisher(): + Node("spdlog") + { + timer_ = this->create_wall_timer(100ms, [this]() + { + timer_->cancel(); + + volatile double val = 0; + const auto start = std::chrono::steady_clock::now(); + for(int i = 0; i < 10000; i++) + { + val = val + 0.001*(1.0 - val); + SPDLOG_INFO("Val is {}", val); + } + const auto end = std::chrono::steady_clock::now(); + + const std::chrono::duration diff = end - start; + SPDLOG_ERROR("Time delta: {}", diff.count()); + + std::exit(0); + }); + } + + private: + rclcpp::TimerBase::SharedPtr timer_; +}; + +int main(int argc, char * argv[]) +{ + spdlog::cfg::load_env_levels(); + rclcpp::init(argc, argv); + rclcpp::spin(std::make_shared()); + rclcpp::shutdown(); + return 0; +}