diff --git a/.pkg b/.pkg index bcd2ff684..bf82e5f91 100644 --- a/.pkg +++ b/.pkg @@ -13,7 +13,7 @@ [utl] url=git@github.com:motis-project/utl.git branch=master - commit=368fdcb8326ced5bb151b60c09a07c2e5f09bf55 + commit=492a0e3ae2d69d13b43141fff5d12b767d6155df [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/exe/benchmark.cc b/exe/benchmark.cc index daafbd999..5f379c2aa 100644 --- a/exe/benchmark.cc +++ b/exe/benchmark.cc @@ -8,12 +8,12 @@ #include "utl/parallel_for.h" #include "utl/progress_tracker.h" -#include "nigiri/logging.h" #include "nigiri/qa/qa.h" #include "nigiri/query_generator/generator.h" #include "nigiri/routing/raptor/raptor.h" #include "nigiri/routing/raptor_search.h" #include "nigiri/routing/search.h" +#include "nigiri/scoped_timer.h" #include "nigiri/timetable.h" #include "nigiri/types.h" diff --git a/include/nigiri/footpath.h b/include/nigiri/footpath.h index c0d024f2d..608a5c2c2 100644 --- a/include/nigiri/footpath.h +++ b/include/nigiri/footpath.h @@ -2,11 +2,11 @@ #include "fmt/ostream.h" +#include "nigiri/footpath.h" #include "utl/verify.h" #include "cista/reflection/printable.h" -#include "nigiri/logging.h" #include "nigiri/types.h" namespace nigiri { @@ -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/loader/build_lb_graph.h b/include/nigiri/loader/build_lb_graph.h index d189c3e51..650ef49e1 100644 --- a/include/nigiri/loader/build_lb_graph.h +++ b/include/nigiri/loader/build_lb_graph.h @@ -2,7 +2,6 @@ #include "utl/pairwise.h" -#include "nigiri/logging.h" #include "nigiri/timetable.h" #include "nigiri/types.h" 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/search.h b/include/nigiri/routing/search.h index a97480baa..3aeeebc54 100644 --- a/include/nigiri/routing/search.h +++ b/include/nigiri/routing/search.h @@ -5,12 +5,12 @@ #include "utl/enumerate.h" #include "utl/equal_ranges_linear.h" #include "utl/erase_if.h" +#include "utl/logging.h" #include "utl/timing.h" #include "utl/to_vec.h" #include "nigiri/for_each_meta.h" #include "nigiri/get_otel_tracer.h" -#include "nigiri/logging.h" #include "nigiri/routing/dijkstra.h" #include "nigiri/routing/get_fastest_direct.h" #include "nigiri/routing/interval_estimate.h" @@ -420,8 +420,7 @@ struct search { algo_.reconstruct(q_, j); } catch (std::exception const& e) { j.error_ = true; - log(log_lvl::error, "search", "reconstruct failed: {}", - e.what()); + utl::log_error("search", "reconstruct failed: {}", e.what()); span->SetStatus(opentelemetry::trace::StatusCode::kError, "exception"); span->AddEvent( diff --git a/include/nigiri/scoped_timer.h b/include/nigiri/scoped_timer.h new file mode 100644 index 000000000..03f07596a --- /dev/null +++ b/include/nigiri/scoped_timer.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace nigiri { + +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 \ No newline at end of file diff --git a/include/nigiri/timetable.h b/include/nigiri/timetable.h index 243139435..377b073b3 100644 --- a/include/nigiri/timetable.h +++ b/include/nigiri/timetable.h @@ -16,7 +16,7 @@ #include "nigiri/common/interval.h" #include "nigiri/footpath.h" #include "nigiri/location.h" -#include "nigiri/logging.h" +#include "nigiri/scoped_timer.h" #include "nigiri/stop.h" #include "nigiri/td_footpath.h" #include "nigiri/types.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..cdabdd6a9 100644 --- a/src/abi.cc +++ b/src/abi.cc @@ -17,7 +17,6 @@ #include "nigiri/loader/gtfs/loader.h" #include "nigiri/loader/hrd/loader.h" #include "nigiri/loader/init_finish.h" -#include "nigiri/logging.h" #include "nigiri/rt/create_rt_timetable.h" #include "nigiri/rt/gtfsrt_update.h" #include "nigiri/rt/rt_timetable.h" @@ -61,8 +60,8 @@ 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", - "loading nigiri timetable with configuration {}", (*c)->name()); + utl::info("main", "loading nigiri timetable with configuration {}", + (*c)->name()); auto t = new nigiri_timetable_t; t->tt = std::make_unique(); @@ -267,11 +266,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/clasz.cc b/src/clasz.cc index 8bdc5acdf..c45bc89ec 100644 --- a/src/clasz.cc +++ b/src/clasz.cc @@ -2,10 +2,9 @@ #include "cista/hash.h" +#include "utl/logging.h" #include "utl/verify.h" -#include "nigiri/logging.h" - namespace nigiri { clasz get_clasz(std::string_view s) { @@ -206,7 +205,7 @@ clasz get_clasz(std::string_view s) { case hash("Elevator"): [[fallthrough]]; case hash("ASC"): return clasz::kOther; default: - log(log_lvl::error, "loader.hrd.clasz", "cannot assign {}", s); + utl:log_error("loader.hrd.clasz", "cannot assign {}", s); return clasz::kOther; } } diff --git a/src/loader/build_footpaths.cc b/src/loader/build_footpaths.cc index ca6e6083e..ae1d7582d 100644 --- a/src/loader/build_footpaths.cc +++ b/src/loader/build_footpaths.cc @@ -8,6 +8,7 @@ #include "utl/equal_ranges_linear.h" #include "utl/erase_duplicates.h" #include "utl/erase_if.h" +#include "utl/logging.h" #include "utl/pairwise.h" #include "utl/parallel_for.h" #include "utl/progress_tracker.h" @@ -17,8 +18,8 @@ #include "nigiri/loader/merge_duplicates.h" #include "nigiri/common/day_list.h" #include "nigiri/constants.h" -#include "nigiri/logging.h" #include "nigiri/routing/dijkstra.h" +#include "nigiri/scoped_timer.h" #include "nigiri/rt/frun.h" #include "nigiri/types.h" @@ -301,7 +302,7 @@ void connect_components(timetable& tt, std::max(static_cast(duration.count()), static_cast(distance / kWalkSpeed / 60)); if (adjusted_int > std::numeric_limits::max()) { - log(log_lvl::error, "loader.footpath.adjust", + utl::log_error("loader.footpath.adjust", "too long after adjust: {}>256", adjusted_int); } adjusted = u8_minutes{adjusted_int}; diff --git a/src/loader/dir.cc b/src/loader/dir.cc index 222476e93..b7cda2276 100644 --- a/src/loader/dir.cc +++ b/src/loader/dir.cc @@ -10,11 +10,11 @@ #include "cista/mmap.h" +#include "utl/logging.h" #include "utl/parser/cstr.h" #include "utl/to_vec.h" #include "utl/verify.h" -#include "nigiri/logging.h" #include "wyhash.h" template <> @@ -73,7 +73,7 @@ file fs_dir::get_file(std::filesystem::path const& p) const { mmap_content& operator=(mmap_content const&) = delete; explicit mmap_content(std::filesystem::path const& p) : mmap_{p.string().c_str(), cista::mmap::protection::READ} { - log(log_lvl::info, "loader.fs_dir", "loaded {}: {} bytes", + utl::log_info("loader.fs_dir", "loaded {}: {} bytes", p.generic_string(), mmap_.size()); } ~mmap_content() final = default; diff --git a/src/loader/gtfs/load_timetable.cc b/src/loader/gtfs/load_timetable.cc index 2aa622a24..1d89e2e29 100644 --- a/src/loader/gtfs/load_timetable.cc +++ b/src/loader/gtfs/load_timetable.cc @@ -13,6 +13,7 @@ #include "wyhash.h" +#include "nigiri/common/sort_by.h" #include "nigiri/loader/get_index.h" #include "nigiri/loader/gtfs/agency.h" #include "nigiri/loader/gtfs/calendar.h" @@ -30,8 +31,7 @@ #include "nigiri/loader/gtfs/stop_time.h" #include "nigiri/loader/gtfs/trip.h" #include "nigiri/loader/loader_interface.h" -#include "nigiri/common/sort_by.h" -#include "nigiri/logging.h" +#include "nigiri/scoped_timer.h" #include "nigiri/timetable.h" namespace fs = std::filesystem; diff --git a/src/loader/gtfs/route.cc b/src/loader/gtfs/route.cc index 7cb74f670..cfd5ccf31 100644 --- a/src/loader/gtfs/route.cc +++ b/src/loader/gtfs/route.cc @@ -1,6 +1,7 @@ #include "nigiri/loader/gtfs/route.h" #include "utl/get_or_create.h" +#include "utl/logging.h" #include "utl/parser/buf_reader.h" #include "utl/parser/csv_range.h" #include "utl/parser/line_range.h" @@ -8,7 +9,7 @@ #include "utl/pipes/vec.h" #include "utl/progress_tracker.h" -#include "nigiri/logging.h" +#include "nigiri/scoped_timer.h" #include "nigiri/timetable.h" namespace nigiri::loader::gtfs { @@ -176,7 +177,7 @@ route_map_t read_routes(timetable& tt, agencies.size() == 1U ? agencies.begin()->second : utl::get_or_create(agencies, r.agency_id_->view(), [&]() { - log(log_lvl::error, "gtfs.route", + utl::log_error("gtfs.route", "agency {} not found, using UNKNOWN with local " "timezone", r.agency_id_->view()); diff --git a/src/loader/gtfs/services.cc b/src/loader/gtfs/services.cc index 4b91dd9ee..3b4cdc5c4 100644 --- a/src/loader/gtfs/services.cc +++ b/src/loader/gtfs/services.cc @@ -1,9 +1,8 @@ -#include "nigiri/loader/gtfs/services.h" - #include "utl/get_or_create.h" #include "utl/progress_tracker.h" -#include "nigiri/logging.h" +#include "nigiri/loader/gtfs/services.h" +#include "nigiri/scoped_timer.h" namespace nigiri::loader::gtfs { diff --git a/src/loader/gtfs/shape.cc b/src/loader/gtfs/shape.cc index b1d4d0163..aad38fc5c 100644 --- a/src/loader/gtfs/shape.cc +++ b/src/loader/gtfs/shape.cc @@ -10,7 +10,6 @@ #include "utl/sort_by.h" #include "nigiri/common/cached_lookup.h" -#include "nigiri/logging.h" #include "nigiri/shapes_storage.h" namespace nigiri::loader::gtfs { diff --git a/src/loader/gtfs/stop.cc b/src/loader/gtfs/stop.cc index 3170fd113..e6b681576 100644 --- a/src/loader/gtfs/stop.cc +++ b/src/loader/gtfs/stop.cc @@ -7,6 +7,7 @@ #include "geo/point_rtree.h" #include "utl/get_or_create.h" +#include "utl/logging.h" #include "utl/parallel_for.h" #include "utl/parser/buf_reader.h" #include "utl/parser/csv_range.h" @@ -15,7 +16,7 @@ #include "utl/progress_tracker.h" #include "utl/to_vec.h" -#include "nigiri/logging.h" +#include "nigiri/scoped_timer.h" #include "nigiri/timetable.h" namespace nigiri::loader::gtfs { @@ -131,14 +132,14 @@ void read_transfers(stop_map_t& stops, std::string_view file_content) { utl::for_each([&](csv_transfer const& t) { auto const from_stop_it = stops.find(t.from_stop_id_->view()); if (from_stop_it == end(stops)) { - log(log_lvl::error, "loader.gtfs.transfers", "stop {} not found\n", + utl::log_error("loader.gtfs.transfers", "stop {} not found\n", t.from_stop_id_->view()); return; } auto const to_stop_it = stops.find(t.to_stop_id_->view()); if (to_stop_it == end(stops)) { - log(log_lvl::error, "loader.gtfs.transfers", "stop {} not found\n", + utl::log_error("loader.gtfs.transfers", "stop {} not found\n", t.to_stop_id_->view()); return; } diff --git a/src/loader/gtfs/stop_time.cc b/src/loader/gtfs/stop_time.cc index 7bfdfa06e..0868f4fde 100644 --- a/src/loader/gtfs/stop_time.cc +++ b/src/loader/gtfs/stop_time.cc @@ -4,20 +4,21 @@ #include #include "utl/enumerate.h" +#include "utl/logging.h" #include "utl/parser/arg_parser.h" #include "utl/parser/buf_reader.h" #include "utl/parser/csv.h" #include "utl/parser/csv_range.h" #include "utl/parser/line_range.h" +#include "utl/pipes/for_each.h" #include "utl/pipes/transform.h" #include "utl/pipes/vec.h" #include "utl/progress_tracker.h" +#include "nigiri/common/cached_lookup.h" #include "nigiri/loader/gtfs/parse_time.h" #include "nigiri/loader/gtfs/trip.h" -#include "nigiri/common/cached_lookup.h" -#include "nigiri/logging.h" -#include "utl/pipes/for_each.h" +#include "nigiri/scoped_timer.h" namespace nigiri::loader::gtfs { @@ -77,7 +78,7 @@ void read_stop_times(timetable& tt, auto const trip_it = trips.trips_.find(t_id); if (trip_it == end(trips.trips_)) { - log(log_lvl::error, "loader.gtfs.stop_time", + utl::log_error("loader.gtfs.stop_time", "stop_times.txt:{} trip \"{}\" not found", i, t_id); return; } @@ -119,7 +120,7 @@ void read_stop_times(timetable& tt, }); } } catch (...) { - log(log_lvl::error, "loader.gtfs.stop_time", + utl::log_error("loader.gtfs.stop_time", "stop_times.txt:{}: unknown stop \"{}\"", i, s.stop_id_->view()); } }); diff --git a/src/loader/gtfs/trip.cc b/src/loader/gtfs/trip.cc index e04bec24f..5fd4d9859 100644 --- a/src/loader/gtfs/trip.cc +++ b/src/loader/gtfs/trip.cc @@ -10,6 +10,7 @@ #include "utl/erase_if.h" #include "utl/get_or_create.h" #include "utl/helpers/algorithm.h" +#include "utl/logging.h" #include "utl/parser/buf_reader.h" #include "utl/parser/csv.h" #include "utl/parser/csv_range.h" @@ -20,7 +21,7 @@ #include "utl/verify.h" #include "nigiri/loader/gtfs/parse_time.h" -#include "nigiri/logging.h" +#include "nigiri/scoped_timer.h" #include "nigiri/timetable.h" #include "nigiri/types.h" @@ -33,7 +34,7 @@ block::rule_services(trip_data& trips) { utl::erase_if(trips_, [&](gtfs_trip_idx_t const& t) { auto const is_empty = trips.data_[t].stop_seq_.empty(); if (is_empty) { - log(log_lvl::error, "loader.gtfs.trip", "trip \"{}\": no stop times", + utl::log_error("loader.gtfs.trip", "trip \"{}\": no stop times", trips.data_[t].id_); } return is_empty; @@ -329,7 +330,7 @@ trip_data read_trips( | utl::for_each([&](csv_trip const& t) { auto const traffic_days_it = services.find(t.service_id_->view()); if (traffic_days_it == end(services)) { - log(log_lvl::error, "loader.gtfs.trip", + utl::log_error("loader.gtfs.trip", R"(trip "{}": service_id "{}" not found)", t.trip_id_->view(), t.service_id_->view()); return; @@ -337,7 +338,7 @@ trip_data read_trips( auto const route_it = routes.find(t.route_id_->view()); if (route_it == end(routes)) { - log(log_lvl::error, "loader.gtfs.trip", + utl::log_error("loader.gtfs.trip", R"(trip "{}": route_id "{}" not found)", t.trip_id_->view(), t.route_id_->view()); return; @@ -401,7 +402,7 @@ void read_frequencies(trip_data& trips, std::string_view file_content) { auto const t = freq.trip_id_->trim().view(); auto const trip_it = trips.trips_.find(t); if (trip_it == end(trips.trips_)) { - log(log_lvl::error, "loader.gtfs.frequencies", + utl::log_error("loader.gtfs.frequencies", "frequencies.txt: skipping frequency (trip \"{}\" not found)", t); return; @@ -410,7 +411,7 @@ void read_frequencies(trip_data& trips, std::string_view file_content) { auto const headway_secs_str = *freq.headway_secs_; auto const headway_secs = parse(headway_secs_str, -1); if (headway_secs == -1) { - log(log_lvl::error, "loader.gtfs.frequencies", + utl::log_error("loader.gtfs.frequencies", R"(frequencies.txt: skipping frequency (invalid headway secs "{}"))", headway_secs_str.view()); return; diff --git a/src/loader/hrd/load_timetable.cc b/src/loader/hrd/load_timetable.cc index 587937902..8a72fec0e 100644 --- a/src/loader/hrd/load_timetable.cc +++ b/src/loader/hrd/load_timetable.cc @@ -25,7 +25,7 @@ bool applicable(config const& c, dir const& d) { (c.prefix(d) / c.core_data_ / file).lexically_normal(); auto const exists = d.exists(path); if (!exists) { - log(log_lvl::info, "loader.hrd", + utl::info_log("loader.hrd", "input={}, missing file for config {}: {}", d.path().generic_string(), c.version_.view(), path.generic_string()); @@ -92,7 +92,7 @@ void load_timetable(source_idx_t const src, continue; } - log(log_lvl::info, "loader.hrd.services", "loading {}", + utl::info_log("loader.hrd.services", "loading {}", path.generic_string()); auto const file = d.get_file(path); sb.add_services( diff --git a/src/loader/hrd/stamm/attribute.cc b/src/loader/hrd/stamm/attribute.cc index b4bcc86cf..029e5a269 100644 --- a/src/loader/hrd/stamm/attribute.cc +++ b/src/loader/hrd/stamm/attribute.cc @@ -1,9 +1,9 @@ -#include "nigiri/loader/hrd/stamm/attribute.h" - -#include "nigiri/logging.h" +#include "utl/logging.h" +#include "utl/parser/cstr.h" +#include "nigiri/loader/hrd/stamm/attribute.h" #include "nigiri/loader/hrd/util.h" -#include "utl/parser/cstr.h" +#include "nigiri/scoped_timer.h" namespace nigiri::loader::hrd { @@ -21,7 +21,7 @@ attribute_map_t parse_attributes(config const& c, if (line.len == 0 || line.str[0] == '#') { return; } else if (line.len < 13 || (is_multiple_spaces(line) && line.len < 22)) { - log(log_lvl::error, "loader.hrd.attribute", + utl::log_error("loader.hrd.attribute", "invalid attribute line - skipping {}", line_number); return; } diff --git a/src/loader/hrd/stamm/basic_info.cc b/src/loader/hrd/stamm/basic_info.cc index 8f75bf062..2146a6029 100644 --- a/src/loader/hrd/stamm/basic_info.cc +++ b/src/loader/hrd/stamm/basic_info.cc @@ -1,9 +1,8 @@ -#include "nigiri/loader/hrd/stamm/basic_info.h" +#include "utl/parser/arg_parser.h" +#include "nigiri/loader/hrd/stamm/basic_info.h" #include "nigiri/loader/hrd/util.h" -#include "nigiri/logging.h" #include "nigiri/types.h" -#include "utl/parser/arg_parser.h" namespace nigiri::loader::hrd { diff --git a/src/loader/hrd/stamm/category.cc b/src/loader/hrd/stamm/category.cc index 938d7e890..7095bfac9 100644 --- a/src/loader/hrd/stamm/category.cc +++ b/src/loader/hrd/stamm/category.cc @@ -1,10 +1,8 @@ -#include "nigiri/loader/hrd/stamm/category.h" - #include "utl/parser/arg_parser.h" -#include "nigiri/loader/hrd/util.h" #include "nigiri/clasz.h" -#include "nigiri/logging.h" +#include "nigiri/loader/hrd/stamm/category.h" +#include "nigiri/loader/hrd/util.h" namespace nigiri::loader::hrd { diff --git a/src/loader/hrd/stamm/direction.cc b/src/loader/hrd/stamm/direction.cc index 5af1ec729..48e6546e5 100644 --- a/src/loader/hrd/stamm/direction.cc +++ b/src/loader/hrd/stamm/direction.cc @@ -1,10 +1,8 @@ -#include "nigiri/loader/hrd/stamm/direction.h" - #include "utl/parser/cstr.h" #include "utl/verify.h" +#include "nigiri/loader/hrd/stamm/direction.h" #include "nigiri/loader/hrd/util.h" -#include "nigiri/logging.h" namespace nigiri::loader::hrd { diff --git a/src/loader/hrd/stamm/station.cc b/src/loader/hrd/stamm/station.cc index 4d8b3d95d..6836004a0 100644 --- a/src/loader/hrd/stamm/station.cc +++ b/src/loader/hrd/stamm/station.cc @@ -1,12 +1,11 @@ -#include "nigiri/loader/hrd/stamm/station.h" - +#include "utl/logging.h" #include "utl/parser/arg_parser.h" #include "utl/pipes.h" #include "nigiri/loader/hrd/stamm/stamm.h" +#include "nigiri/loader/hrd/stamm/station.h" #include "nigiri/loader/hrd/stamm/timezone.h" #include "nigiri/loader/hrd/util.h" -#include "nigiri/logging.h" namespace nigiri::loader::hrd { @@ -18,7 +17,7 @@ void parse_station_names(config const& c, if (line.len == 0 || line[0] == '%') { return; } else if (line.len < 13) { - log(log_lvl::error, "loader.hrd.station.coordinates", + utl::log_error("loader.hrd.station.coordinates", "station name file unknown line format line={} content=\"{}\"", line_number, line.view()); return; @@ -45,7 +44,7 @@ void parse_station_coordinates(config const& c, if (line.len == 0 || line[0] == '%') { return; } else if (line.len < 30) { - log(log_lvl::error, "loader.hrd.station.coordinates", + utl::log_error("loader.hrd.station.coordinates", "station coordinate file unknown line format line={} content=\"{}\"", line_number, line.view()); return; @@ -74,7 +73,7 @@ void parse_equivilant_stations(config const& c, parse_eva_number(line.substr(c.meta_.meta_stations_.eva_)); auto const station_it = stations.find(eva); if (station_it == end(stations)) { - log(log_lvl::error, "loader.hrd.meta", "line {}: {} not found", + utl::log_error("loader.hrd.meta", "line {}: {} not found", line_number, eva); return; } @@ -96,7 +95,7 @@ void parse_equivilant_stations(config const& c, } }); } catch (std::exception const& e) { - log(log_lvl::error, "loader.hrd.equivalent", + utl::log_error("loader.hrd.equivalent", "could not parse line {}: {}", line_number, e.what()); } } else { // footpaths @@ -134,7 +133,7 @@ void parse_footpaths(config const& c, parse_eva_number(line.substr(c.meta_.footpaths_.from_)); auto const from_it = stations.find(from_eva); if (from_it == end(stations)) { - log(log_lvl::error, "loader.hrd.footpath", + utl::log_error("loader.hrd.footpath", "footpath line={}: {} not found", line_number, to_idx(from_eva)); return; } @@ -143,7 +142,7 @@ void parse_footpaths(config const& c, auto const to_eva = parse_eva_number(line.substr(c.meta_.footpaths_.to_)); auto const to_it = stations.find(to_eva); if (to_it == end(stations)) { - log(log_lvl::error, "loader.hrd.footpath", + url::log_error("loader.hrd.footpath", "footpath line={}: {} not found", line_number, to_idx(to_eva)); return; } diff --git a/src/loader/hrd/stamm/timezone.cc b/src/loader/hrd/stamm/timezone.cc index 62329610a..2feb9d008 100644 --- a/src/loader/hrd/stamm/timezone.cc +++ b/src/loader/hrd/stamm/timezone.cc @@ -1,9 +1,8 @@ -#include "nigiri/loader/hrd/stamm/timezone.h" - +#include "utl/logging.h" #include "utl/parser/arg_parser.h" +#include "nigiri/loader/hrd/stamm/timezone.h" #include "nigiri/loader/hrd/util.h" -#include "nigiri/logging.h" namespace nigiri::loader::hrd { diff --git a/src/loader/hrd/stamm/track.cc b/src/loader/hrd/stamm/track.cc index 8d38219db..460c99429 100644 --- a/src/loader/hrd/stamm/track.cc +++ b/src/loader/hrd/stamm/track.cc @@ -1,10 +1,8 @@ -#include "nigiri/loader/hrd/stamm/track.h" - #include "utl/get_or_create.h" +#include "nigiri/loader/hrd/stamm/track.h" #include "nigiri/loader/hrd/stamm/stamm.h" #include "nigiri/loader/hrd/util.h" -#include "nigiri/logging.h" #include "nigiri/types.h" namespace nigiri::loader::hrd { diff --git a/src/loader/load.cc b/src/loader/load.cc index b9d3f9b3e..acf8b3c94 100644 --- a/src/loader/load.cc +++ b/src/loader/load.cc @@ -47,7 +47,7 @@ timetable load(std::vector> const& paths, utl::find_if(loaders, [&](auto&& l) { return l->applicable(*dir); }); if (it != end(loaders)) { if (!is_in_memory) { - log(log_lvl::info, "loader.load", "loading {}", path); + utl::info_log("loader.load", "loading {}", path); } try { (*it)->load(local_config, src, *dir, tt, bitfields, a, shapes); diff --git a/src/query_generator/generator.cc b/src/query_generator/generator.cc index 9b9759537..83635a9f5 100644 --- a/src/query_generator/generator.cc +++ b/src/query_generator/generator.cc @@ -1,7 +1,8 @@ +#include "utl/logging.h" + #include "nigiri/query_generator/generator.h" #include "nigiri/location_match_mode.h" -#include "nigiri/logging.h" #include "nigiri/routing/ontrip_train.h" #include "nigiri/special_stations.h" #include "nigiri/timetable.h" @@ -167,7 +168,7 @@ std::optional generator::random_query() { return sdq; } - log(log_lvl::info, "query_generator.random_pretrip", + utl::info_log("query_generator.random_pretrip", "WARNING: failed to generate a valid query after {} attempts", kMaxGenAttempts); @@ -196,7 +197,7 @@ location_idx_t generator::random_location() { if (!locs_in_bbox.empty()) { return location_idx_t{locs_in_bbox[locs_in_bbox_d_(rng_)]}; } - log(log_lvl::info, "query_generator.random_location", + utl::info_log("query_generator.random_location", "no locations in bounding box: using all locations instead"); } return location_idx_t{location_d_(rng_)}; 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/gtfsrt_update.cc b/src/rt/gtfsrt_update.cc index a745b2423..09bd215aa 100644 --- a/src/rt/gtfsrt_update.cc +++ b/src/rt/gtfsrt_update.cc @@ -1,12 +1,11 @@ -#include "nigiri/rt/gtfsrt_update.h" - +#include "utl/logging.h" #include "utl/pairwise.h" #include "nigiri/loader/gtfs/stop_seq_number_encoding.h" #include "nigiri/get_otel_tracer.h" -#include "nigiri/logging.h" #include "nigiri/rt/frun.h" #include "nigiri/rt/gtfsrt_resolve_run.h" +#include "nigiri/rt/gtfsrt_update.h" #include "nigiri/rt/run.h" namespace gtfsrt = transit_realtime; @@ -214,7 +213,7 @@ void update_run( rtt.dispatch_stop_change(r, stop_idx, event_type::kDep, l_it->second, s.in_allowed()); } else { - log(log_lvl::error, "gtfsrt.stop_assignment", + utl::log_error("gtfsrt.stop_assignment", "stop assignment: src={}, stop_id=\"{}\" not found", src, new_id); } } else { @@ -308,7 +307,7 @@ statistics gtfsrt_update_msg(timetable const& tt, auto const unsupported = [&](bool const is_set, char const* field, int& stat) { if (is_set) { - log(log_lvl::error, "rt.gtfs.unsupported", + utl::log_error("rt.gtfs.unsupported", R"(ignoring unsupported "{}" field (tag={}, id={}))", field, tag, entity.id()); ++stat; @@ -321,7 +320,7 @@ statistics gtfsrt_update_msg(timetable const& tt, stats.unsupported_deleted_); if (!entity.has_trip_update()) { - log(log_lvl::error, "rt.gtfs.unsupported", + utl::log_error("rt.gtfs.unsupported", R"(unsupported: no "trip_update" field (tag={}, id={}), skipping message)", tag, entity.id()); ++stats.no_trip_update_; @@ -329,7 +328,7 @@ statistics gtfsrt_update_msg(timetable const& tt, } if (!entity.trip_update().has_trip()) { - log(log_lvl::error, "rt.gtfs.unsupported", + utl::log_error("rt.gtfs.unsupported", R"(unsupported: no "trip" field in "trip_update" field (tag={}, id={}), skipping message)", tag, entity.id()); ++stats.trip_update_without_trip_; @@ -337,7 +336,7 @@ statistics gtfsrt_update_msg(timetable const& tt, } if (!entity.trip_update().trip().has_trip_id()) { - log(log_lvl::error, "rt.gtfs.unsupported", + utl::log_error("rt.gtfs.unsupported", R"(unsupported: no "trip_id" field in "trip_update.trip" (tag={}, id={}), skipping message)", tag, entity.id()); ++stats.unsupported_no_trip_id_; @@ -348,7 +347,7 @@ statistics gtfsrt_update_msg(timetable const& tt, gtfsrt::TripDescriptor_ScheduleRelationship_SCHEDULED && entity.trip_update().trip().schedule_relationship() != gtfsrt::TripDescriptor_ScheduleRelationship_CANCELED) { - log(log_lvl::error, "rt.gtfs.unsupported", + utl::log_error("rt.gtfs.unsupported", "unsupported schedule relationship {} (tag={}, id={}), skipping " "message", TripDescriptor_ScheduleRelationship_Name( @@ -363,7 +362,7 @@ statistics gtfsrt_update_msg(timetable const& tt, auto [r, trip] = gtfsrt_resolve_run(today, tt, &rtt, src, td); if (!r.valid()) { - log(log_lvl::error, "rt.gtfs.resolve", "could not resolve (tag={}) {}", + utl::log_error("rt.gtfs.resolve", "could not resolve (tag={}) {}", tag, remove_nl(td.DebugString())); span->AddEvent( "unresolved trip", @@ -395,7 +394,7 @@ statistics gtfsrt_update_msg(timetable const& tt, ++stats.total_entities_success_; } catch (const std::exception& e) { ++stats.total_entities_fail_; - log(log_lvl::error, "rt.gtfs", + utl::log_error("rt.gtfs", "GTFS-RT error (tag={}): time={}, entity={}, message={}, error={}", tag, date::format("%T", message_time), entity.id(), remove_nl(entity.DebugString()), e.what()); @@ -421,7 +420,7 @@ statistics gtfsrt_update_buf(timetable const& tt, msg.ParseFromArray(reinterpret_cast(protobuf.data()), static_cast(protobuf.size())); if (!success) { - log(log_lvl::error, "rt.gtfs", + utl::log_error("rt.gtfs", "GTFS-RT error (tag={}): unable to parse protobuf message: {}", tag, protobuf.substr(0, std::min(protobuf.size(), size_t{1000U}))); return {.parser_error_ = true}; 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 diff --git a/src/logging.cc b/src/scoped_timer.cc similarity index 67% rename from src/logging.cc rename to src/scoped_timer.cc index b09c62b43..2c95134cf 100644 --- a/src/logging.cc +++ b/src/scoped_timer.cc @@ -1,10 +1,10 @@ -#include "nigiri/logging.h" +#include "utl/logging.h" namespace nigiri { scoped_timer::scoped_timer(std::string name) : name_{std::move(name)}, start_{std::chrono::steady_clock::now()} { - log(log_lvl::info, name_.c_str(), "starting {}", std::string_view{name_}); + utl::log_info(name_.c_str(), "starting {}", std::string_view{name_}); } scoped_timer::~scoped_timer() { @@ -13,7 +13,7 @@ scoped_timer::~scoped_timer() { auto const t = static_cast(duration_cast(stop - start_).count()) / 1000.0; - log(log_lvl::info, name_.c_str(), "finished {} {}ms", std::string_view{name_}, + utl::log_info(name_.c_str(), "finished {} {}ms", std::string_view{name_}, t); }