From d7958373c29d2b4d8aa839242c3d2d3971b5a08d Mon Sep 17 00:00:00 2001 From: Lucas Cimon <925560+Lucas-C@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:40:25 +0100 Subject: [PATCH] Adopting utl::log() --- .pkg | 2 +- .pkg.lock | 48 +++++++++--------- include/nigiri/footpath.h | 6 +-- include/nigiri/logging.h | 72 --------------------------- include/nigiri/routing/raptor/debug.h | 10 ++-- include/nigiri/timetable.h | 4 +- src/abi.cc | 8 ++- src/routing/dijkstra.cc | 2 +- src/routing/ontrip_train.cc | 2 +- src/routing/start_times.cc | 2 +- src/rt/vdv/vdv_update.cc | 2 +- 11 files changed, 42 insertions(+), 116 deletions(-) delete mode 100644 include/nigiri/logging.h diff --git a/.pkg b/.pkg index bcd2ff684..33ddd8515 100644 --- a/.pkg +++ b/.pkg @@ -13,7 +13,7 @@ [utl] url=git@github.com:motis-project/utl.git branch=master - commit=368fdcb8326ced5bb151b60c09a07c2e5f09bf55 + commit=69e700e03ae3d385304d754cf57877528bc591ef [miniz] url=git@github.com:motis-project/miniz.git branch=master diff --git a/.pkg.lock b/.pkg.lock index aaac8691b..5f1aff157 100644 --- a/.pkg.lock +++ b/.pkg.lock @@ -1,24 +1,24 @@ -8143833587396253561 -cista fabfc0cbcf07343a2e0c2def3009555b22f0ae46 -PEGTL 1c1aa6e650e4d26f10fa398f148ec0cdc5f0808d -res b759b93316afeb529b6cb5b2548b24c41e382fb0 -date ce88cc33b5551f66655614eeebb7c5b7189025fb -googletest 7b64fca6ea0833628d6f86255a81424365f7cc0c -fmt dc10f83be70ac2873d5f8d1ce317596f1fd318a2 -utl 368fdcb8326ced5bb151b60c09a07c2e5f09bf55 -oh d21c30f40e52a83d6dc09bcffd0067598b5ec069 -zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3 -boost 73549ebca677fe6214202a1ab580362b4f80e653 -doctest 70e8f76437b76dd5e9c0a2eb9b907df190ab71a0 -geo cee17208dba98f5f3ddaf78d0bfff9c083557ba3 -miniz 1edbdece9d71dc65c6ff405572ee37cbdcef7af4 -libressl 24acd9e710fbe842e863572da9d738715fbc74b8 -curl 39c8a51e8ee0ab7ea712886df79c068405a2e008 -json 410c74782230daaa15054d6ee0975c0607091cb3 -opentelemetry-proto 1624689398a3226c45994d70cb544a1e781dc032 -abseil-cpp ba5240842d352b4b67a32092453a2fe5fe53a62e -protobuf df2dd518c68b882c9dce5346393f8c388108e733 -opentelemetry-cpp 60770dc9dc63e3543fc87d605b2e88fd53d7a414 -pugixml 60175e80e2f5e97e027ac78f7e14c5acc009ce50 -unordered_dense 77e91016354e6d8cba24a86c5abb807de2534c02 -wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99 +11666447591127991742 +cista fabfc0cbcf07343a2e0c2def3009555b22f0ae46 +PEGTL 1c1aa6e650e4d26f10fa398f148ec0cdc5f0808d +res b759b93316afeb529b6cb5b2548b24c41e382fb0 +date ce88cc33b5551f66655614eeebb7c5b7189025fb +googletest 7b64fca6ea0833628d6f86255a81424365f7cc0c +fmt dc10f83be70ac2873d5f8d1ce317596f1fd318a2 +utl 69e700e03ae3d385304d754cf57877528bc591ef +oh d21c30f40e52a83d6dc09bcffd0067598b5ec069 +zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3 +boost 73549ebca677fe6214202a1ab580362b4f80e653 +doctest 70e8f76437b76dd5e9c0a2eb9b907df190ab71a0 +geo cee17208dba98f5f3ddaf78d0bfff9c083557ba3 +miniz 1edbdece9d71dc65c6ff405572ee37cbdcef7af4 +libressl 24acd9e710fbe842e863572da9d738715fbc74b8 +curl 39c8a51e8ee0ab7ea712886df79c068405a2e008 +json 410c74782230daaa15054d6ee0975c0607091cb3 +opentelemetry-proto 1624689398a3226c45994d70cb544a1e781dc032 +abseil-cpp ba5240842d352b4b67a32092453a2fe5fe53a62e +protobuf df2dd518c68b882c9dce5346393f8c388108e733 +opentelemetry-cpp 60770dc9dc63e3543fc87d605b2e88fd53d7a414 +pugixml 60175e80e2f5e97e027ac78f7e14c5acc009ce50 +unordered_dense 77e91016354e6d8cba24a86c5abb807de2534c02 +wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99 diff --git a/include/nigiri/footpath.h b/include/nigiri/footpath.h index c0d024f2d..447caa65d 100644 --- a/include/nigiri/footpath.h +++ b/include/nigiri/footpath.h @@ -34,9 +34,9 @@ struct footpath { kDurationBits, "station index overflow"); if (duration > kMaxDuration) { - [[unlikely]] nigiri::log(log_lvl::error, "footpath", - "footpath overflow: {} > {} adjusted to {}", - duration, kMaxDuration, this->duration()); + [[unlikely]] utl::error("footpath", + "footpath overflow: {} > {} adjusted to {}", + duration, kMaxDuration, this->duration()); } } diff --git a/include/nigiri/logging.h b/include/nigiri/logging.h deleted file mode 100644 index e8d8edfca..000000000 --- a/include/nigiri/logging.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "fmt/core.h" -#include "fmt/ostream.h" - -namespace nigiri { - -enum class log_lvl { debug, info, error }; - -constexpr char const* to_str(log_lvl const lvl) { - switch (lvl) { - case log_lvl::debug: return "debug"; - case log_lvl::info: return "info"; - case log_lvl::error: return "error"; - } - return ""; -} - -static log_lvl s_verbosity; - -inline std::string now() { - using clock = std::chrono::system_clock; - auto const now = clock::to_time_t(clock::now()); - struct tm tmp {}; -#if _MSC_VER >= 1400 - gmtime_s(&tmp, &now); -#else - gmtime_r(&now, &tmp); -#endif - - std::stringstream ss; - ss << std::put_time(&tmp, "%FT%TZ"); - return ss.str(); -} - -#ifndef NIGIRI_LOG_HEADER -template -void log(log_lvl const lvl, - char const* ctx, - fmt::format_string fmt_str, - Args&&... args) { - if (lvl >= ::nigiri::s_verbosity) { - fmt::print(std::clog, "{time} | [{lvl}][{ctx:30}] {msg}\n", - fmt::arg("time", now()), fmt::arg("lvl", to_str(lvl)), - fmt::arg("ctx", ctx), - fmt::arg("msg", fmt::format(fmt::runtime(fmt_str), - std::forward(args)...))); - } -} -#else -#include NIGIRI_LOG_HEADER -#endif - -struct scoped_timer final { - explicit scoped_timer(std::string name); - scoped_timer(scoped_timer const&) = delete; - scoped_timer(scoped_timer&&) = delete; - scoped_timer& operator=(scoped_timer const&) = delete; - scoped_timer& operator=(scoped_timer&&) = delete; - ~scoped_timer(); - - std::string name_; - std::chrono::time_point start_; -}; - -} // namespace nigiri diff --git a/include/nigiri/routing/raptor/debug.h b/include/nigiri/routing/raptor/debug.h index b55a21447..4a0607cbd 100644 --- a/include/nigiri/routing/raptor/debug.h +++ b/include/nigiri/routing/raptor/debug.h @@ -8,25 +8,25 @@ // #define NIGIRI_RAPTOR_TRACING_ONLY_UPDATES // #define NIGIRI_RAPTOR_INTERVAL_TRACING -#define trace_upd(...) fmt::print(__VA_ARGS__) +#define trace_upd(...) utl::debug(__VA_ARGS__) #ifdef NIGIRI_RAPTOR_TRACING_ONLY_UPDATES #define trace(...) #else -#define trace(...) fmt::print(__VA_ARGS__) +#define trace(...) utl::debug(__VA_ARGS__) #endif #define NIGIRI_TRACE_RECONSTRUCT #ifdef NIGIRI_TRACE_RECONSTRUCT -#define trace_reconstruct(...) fmt::print(__VA_ARGS__) +#define trace_reconstruct(...) utl::debug(__VA_ARGS__) #else #define trace_reconstruct(...) #endif #define trace_print_state(...) \ - fmt::print(__VA_ARGS__); \ + utl::debug(__VA_ARGS__); \ state_.print(tt_, base(), kInvalid); \ - fmt::print("\n") + utl::debug("\n") #define trace_print_state_after_round() \ trace_print_state("STATE AFTER ROUND {}\n", k) diff --git a/include/nigiri/timetable.h b/include/nigiri/timetable.h index 243139435..c90fff806 100644 --- a/include/nigiri/timetable.h +++ b/include/nigiri/timetable.h @@ -52,8 +52,8 @@ struct timetable { transfer_time_.emplace_back(l.transfer_time_); parents_.emplace_back(l.parent_); } else { - log(log_lvl::error, "timetable.register_location", - "duplicate station {}", l.id_); + utl::error("timetable.register_location", "duplicate station {}", + l.id_); } assert(names_.size() == next_idx + 1); diff --git a/src/abi.cc b/src/abi.cc index ccdcdd345..14fe755f8 100644 --- a/src/abi.cc +++ b/src/abi.cc @@ -61,7 +61,7 @@ nigiri_timetable_t* nigiri_load_from_dir(nigiri::loader::dir const& d, auto const c = utl::find_if(loaders, [&](auto&& l) { return l->applicable(d); }); utl::verify(c != end(loaders), "no loader applicable to the given file(s)"); - nigiri::log(nigiri::log_lvl::info, "main", + utl::info("main", "loading nigiri timetable with configuration {}", (*c)->name()); auto t = new nigiri_timetable_t; @@ -267,11 +267,9 @@ void nigiri_update_with_rt_from_buf(const nigiri_timetable_t* t, try { nigiri::rt::gtfsrt_update_buf(*t->tt, *t->rtt, src, tag, protobuf); } catch (std::exception const& e) { - nigiri::log(nigiri::log_lvl::error, "main", - "GTFS-RT update error (tag={}) {}", tag, e.what()); + utl::error("main", "GTFS-RT update error (tag={}) {}", tag, e.what()); } catch (...) { - nigiri::log(nigiri::log_lvl::error, "main", - "Unknown GTFS-RT update error (tag={})", tag); + utl::error("main", "Unknown GTFS-RT update error (tag={})", tag); } t->rtt->reset_change_callback(); } diff --git a/src/routing/dijkstra.cc b/src/routing/dijkstra.cc index 19a414a9a..53970886a 100644 --- a/src/routing/dijkstra.cc +++ b/src/routing/dijkstra.cc @@ -13,7 +13,7 @@ // #define NIGIRI_DIJKSTRA_TRACING #ifdef NIGIRI_DIJKSTRA_TRACING -#define trace(...) fmt::print(__VA_ARGS__) +#define trace(...) utl::debug(__VA_ARGS__) #else #define trace(...) #endif diff --git a/src/routing/ontrip_train.cc b/src/routing/ontrip_train.cc index a60968574..22a499faf 100644 --- a/src/routing/ontrip_train.cc +++ b/src/routing/ontrip_train.cc @@ -12,7 +12,7 @@ constexpr auto const kTracing = true; template void trace(fmt::format_string fmt_str, Args... args) { if constexpr (kTracing) { - fmt::print(std::cout, fmt_str, std::forward(args)...); + utl::debug(fmt_str, std::forward(args)...); } } diff --git a/src/routing/start_times.cc b/src/routing/start_times.cc index 3a42c6547..3c50cdf77 100644 --- a/src/routing/start_times.cc +++ b/src/routing/start_times.cc @@ -32,7 +32,7 @@ duration_t get_duration(direction const search_dir, template void trace_start(char const* fmt_str, Args... args) { if constexpr (kTracing) { - fmt::print(std::cout, fmt::runtime(fmt_str), std::forward(args)...); + utl::debug(fmt::runtime(fmt_str), std::forward(args)...); } } diff --git a/src/rt/vdv/vdv_update.cc b/src/rt/vdv/vdv_update.cc index c060e5fbe..c11ec6893 100644 --- a/src/rt/vdv/vdv_update.cc +++ b/src/rt/vdv/vdv_update.cc @@ -26,7 +26,7 @@ namespace nigiri::rt::vdv { // #define VDV_DEBUG #ifdef VDV_DEBUG -#define vdv_trace(...) fmt::print(__VA_ARGS__) +#define vdv_trace(...) utl::debug(__VA_ARGS__) #else #define vdv_trace(...) #endif