From 1c654db378bc1040ecb969b68c1eafbc52ee4fca Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Sun, 12 Jan 2025 15:39:33 -0500 Subject: [PATCH] refactor: replace `iguana::Logger` with `spdlog` --- meson.build | 18 ++++++++++++++---- src/iguana/services/Object.cc | 5 ++++- src/iguana/services/Object.h | 2 ++ subprojects/spdlog.wrap | 13 +++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 subprojects/spdlog.wrap diff --git a/meson.build b/meson.build index 50a6bb97..4eb2f677 100644 --- a/meson.build +++ b/meson.build @@ -39,6 +39,14 @@ fmt_dep = dependency( method: 'pkg-config', version: '>=' + run_command(prog_minver, 'fmt', check: true).stdout().strip(), ) +spdlog_dep = dependency( + 'spdlog', + method: 'pkg-config', + version: '>=1.15', + default_options: { + 'compile_library': 'true', ### FIXME: library libspdlog is not being installed, only the headers are + }, +) yamlcpp_dep = dependency( 'yaml-cpp', method: 'pkg-config', @@ -76,7 +84,7 @@ thread_dep = dependency( # themselves are listed last (see FIXME in meson/this_iguana.sh.in) # NOTE: omit ROOT (handled differently, and most ROOT users already have it in their environment) dep_list = [] -foreach dep : [ hipo_dep, fmt_dep, yamlcpp_dep, rcdb_dep ] +foreach dep : [ hipo_dep, fmt_dep, spdlog_dep, yamlcpp_dep, rcdb_dep ] if dep.found() dep_list += dep endif @@ -98,14 +106,16 @@ foreach dep : dep_list libdirs += run_command('dirname', lib, check: true).stdout().strip() endforeach incdirs = ROOT_dep.get_variable(cmake: 'PACKAGE_INCLUDE_DIRS').split(';') - else + elif dep.type_name() == 'internal' name = dep.get_variable(internal: 'name', default_value: dep.name()) if name == 'rcdb' incdirs = [ dep.get_variable(internal: 'includedir') ] else - warning(f'Unknown dependency "@name@"') + # warning(f'Unknown internal dependency "@name@"') continue endif + else + error('Dependency type "' + dep.type_name() + '" is unknown') endif # append to `dep_*_dirs` arrays, uniquely @@ -241,7 +251,7 @@ pkg.generate( name: meson.project_name(), description: project_description, libraries: project_libs, - requires: [ fmt_dep, yamlcpp_dep, hipo_dep ], # pkg-config dependencies only + requires: [ fmt_dep, yamlcpp_dep, hipo_dep ], # pkg-config dependencies only # FIXME # FIXME # FIXME variables: project_pkg_vars_nonempty, ) diff --git a/src/iguana/services/Object.cc b/src/iguana/services/Object.cc index e0bacef0..64a474b7 100644 --- a/src/iguana/services/Object.cc +++ b/src/iguana/services/Object.cc @@ -5,7 +5,10 @@ namespace iguana { Object::Object(std::string_view name, Logger::Level lev) : m_name(name) , m_log(std::make_unique(m_name, lev)) - {} + , m_spdlog(spdlog::default_logger()->clone(m_name)) + { + m_spdlog->set_level(spdlog::level::trace); + } std::unique_ptr& Object::Log() { diff --git a/src/iguana/services/Object.h b/src/iguana/services/Object.h index a4e23a2e..2411dd98 100644 --- a/src/iguana/services/Object.h +++ b/src/iguana/services/Object.h @@ -4,6 +4,7 @@ #include #include "Logger.h" +#include namespace iguana { @@ -50,5 +51,6 @@ namespace iguana { /// `Logger` instance for this object std::unique_ptr m_log; + std::shared_ptr m_spdlog; }; } diff --git a/subprojects/spdlog.wrap b/subprojects/spdlog.wrap new file mode 100644 index 00000000..c02f407d --- /dev/null +++ b/subprojects/spdlog.wrap @@ -0,0 +1,13 @@ +[wrap-file] +directory = spdlog-1.15.0 +source_url = https://github.com/gabime/spdlog/archive/refs/tags/v1.15.0.tar.gz +source_filename = spdlog-1.15.0.tar.gz +source_hash = 9962648c9b4f1a7bbc76fd8d9172555bad1871fdb14ff4f842ef87949682caa5 +patch_filename = spdlog_1.15.0-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/spdlog_1.15.0-1/get_patch +patch_hash = 72bd578ff0eb4f5a84e5bd63ddc7b2ece84aad5abb516b54c8750306ae78df28 +source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/spdlog_1.15.0-1/spdlog-1.15.0.tar.gz +wrapdb_version = 1.15.0-1 + +[provide] +spdlog = spdlog_dep