diff --git a/.pkg b/.pkg index bcd2ff684..eb4f70fbd 100644 --- a/.pkg +++ b/.pkg @@ -13,7 +13,7 @@ [utl] url=git@github.com:motis-project/utl.git branch=master - commit=368fdcb8326ced5bb151b60c09a07c2e5f09bf55 + commit=2d8b992e23ecf7dcd0742420e92fac4a7c290d4e [miniz] url=git@github.com:motis-project/miniz.git branch=master diff --git a/.pkg.lock b/.pkg.lock index aaac8691b..0fc357522 100644 --- a/.pkg.lock +++ b/.pkg.lock @@ -1,11 +1,12 @@ -8143833587396253561 +9188511793150230166 cista fabfc0cbcf07343a2e0c2def3009555b22f0ae46 PEGTL 1c1aa6e650e4d26f10fa398f148ec0cdc5f0808d res b759b93316afeb529b6cb5b2548b24c41e382fb0 date ce88cc33b5551f66655614eeebb7c5b7189025fb googletest 7b64fca6ea0833628d6f86255a81424365f7cc0c +docs 75dc89a53e9c2d78574fc0ffda698e69f1682ed2 fmt dc10f83be70ac2873d5f8d1ce317596f1fd318a2 -utl 368fdcb8326ced5bb151b60c09a07c2e5f09bf55 +utl 2d8b992e23ecf7dcd0742420e92fac4a7c290d4e oh d21c30f40e52a83d6dc09bcffd0067598b5ec069 zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3 boost 73549ebca677fe6214202a1ab580362b4f80e653 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..5149f197d 100644 --- a/include/nigiri/footpath.h +++ b/include/nigiri/footpath.h @@ -2,11 +2,11 @@ #include "fmt/ostream.h" +#include "utl/logging.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::log_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/loader/hrd/service/expand_local_to_utc.h b/include/nigiri/loader/hrd/service/expand_local_to_utc.h index 8aa8625bf..5ac50c543 100644 --- a/include/nigiri/loader/hrd/service/expand_local_to_utc.h +++ b/include/nigiri/loader/hrd/service/expand_local_to_utc.h @@ -1,5 +1,7 @@ #pragma once +#include "utl/logging.h" + #include "nigiri/loader/hrd/service/ref_service.h" #include "nigiri/loader/hrd/service/service.h" #include "nigiri/loader/hrd/stamm/timezone.h" @@ -55,7 +57,8 @@ std::optional build_utc_time_seq( stop_timezones.front(), day, local_times.front(), true); if (!first_valid) { - log(log_lvl::error, "loader.hrd.service.utc", + utl::log_error( + "loader.hrd.service.utc", "first departure local to utc failed for {}: local_time={}, day={}", origin, local_times.front(), day); return std::nullopt; @@ -67,7 +70,8 @@ std::optional build_utc_time_seq( auto const [utc_mam, day_offset, valid] = local_mam_to_utc_mam( tz, day + first_day_offset, local_time - first_day_offset); if (day_offset != 0_days || pred > utc_mam || !valid) { - log(log_lvl::error, "loader.hrd.service.utc", + utl::log_error( + "loader.hrd.service.utc", "local to utc failed, ignoring: {}, day={}, time={}, offset={}, " "pred={}, utc_mam={}, valid={}", origin, day, local_time, day_offset, pred, utc_mam, valid); diff --git a/include/nigiri/loader/hrd/service/read_services.h b/include/nigiri/loader/hrd/service/read_services.h index dbcf5cb93..e1d5b9aa7 100644 --- a/include/nigiri/loader/hrd/service/read_services.h +++ b/include/nigiri/loader/hrd/service/read_services.h @@ -1,5 +1,6 @@ #pragma once +#include "utl/logging.h" #include "utl/parser/cstr.h" #include "nigiri/loader/hrd/service/expand_local_to_utc.h" @@ -55,16 +56,16 @@ void parse_services(config const& c, } if (!spec.valid()) { - log(log_lvl::error, "loader.hrd.service", - "skipping invalid service at {}:{}", filename, line_number); + utl::log_error("loader.hrd.service", "skipping invalid service at {}:{}", + filename, line_number); } else if (!spec.ignore()) { // Store if relevant. try { expand_service(store.add(service{c, st, source_file_idx, spec})); } catch (std::exception const& e) { - log(log_lvl::error, "loader.hrd.service.expand", - "unable to build service at {}:{}: {}", filename, line_number, - e.what()); + utl::log_error("loader.hrd.service.expand", + "unable to build service at {}:{}: {}", filename, + line_number, e.what()); } } 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..ce979490d 100644 --- a/include/nigiri/timetable.h +++ b/include/nigiri/timetable.h @@ -8,6 +8,7 @@ #include "cista/memory_holder.h" #include "cista/reflection/printable.h" +#include "utl/logging.h" #include "utl/verify.h" #include "utl/zip.h" @@ -16,7 +17,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 +53,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::log_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..5fc31266c 100644 --- a/src/abi.cc +++ b/src/abi.cc @@ -4,35 +4,33 @@ #include #include +#include "cista/memory_holder.h" + #include "date/date.h" #include "utl/helpers/algorithm.h" +#include "utl/logging.h" #include "utl/overloaded.h" #include "utl/progress_tracker.h" #include "utl/verify.h" -#include "nigiri/abi.h" - #include "nigiri/loader/dir.h" #include "nigiri/loader/gtfs/loader.h" #include "nigiri/loader/hrd/loader.h" #include "nigiri/loader/init_finish.h" -#include "nigiri/logging.h" +#include "nigiri/abi.h" +#include "nigiri/common/interval.h" +#include "nigiri/routing/journey.h" +#include "nigiri/routing/raptor/raptor.h" +#include "nigiri/routing/search.h" #include "nigiri/rt/create_rt_timetable.h" +#include "nigiri/rt/frun.h" #include "nigiri/rt/gtfsrt_update.h" #include "nigiri/rt/rt_timetable.h" #include "nigiri/shapes_storage.h" #include "nigiri/timetable.h" #include "nigiri/types.h" -#include "nigiri/routing/journey.h" -#include "nigiri/routing/raptor/raptor.h" -#include "nigiri/routing/search.h" -#include "nigiri/rt/frun.h" - -#include "nigiri/common/interval.h" -#include "cista/memory_holder.h" - using namespace date; struct nigiri_timetable { @@ -61,8 +59,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::log_info("main", "loading nigiri timetable with configuration {}", + (*c)->name()); auto t = new nigiri_timetable_t; t->tt = std::make_unique(); @@ -267,11 +265,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::log_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::log_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..e65eaac31 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/assistance.cc b/src/loader/assistance.cc index 3276c1487..efa522171 100644 --- a/src/loader/assistance.cc +++ b/src/loader/assistance.cc @@ -2,6 +2,7 @@ #include "geo/point_rtree.h" +#include "utl/logging.h" #include "utl/parser/buf_reader.h" #include "utl/parser/csv_range.h" #include "utl/parser/line_range.h" @@ -22,16 +23,17 @@ assistance_times read_assistance(std::string_view file_content) { auto a = assistance_times{}; utl::line_range{utl::make_buf_reader(file_content)} // | utl::csv() // - | utl::for_each([&](assistance const& x) { - a.names_.emplace_back(x.name_->trim().view()); - a.pos_.emplace_back(*x.lat_, *x.lng_); - try { - a.rules_.emplace_back(oh::parse(x.time_->trim().view())); - } catch (std::exception const& e) { - log(log_lvl::error, "loader.assistance", - "bad assistance time \"{}\": {}", x.time_->view(), e.what()); - } - }); + | + utl::for_each([&](assistance const& x) { + a.names_.emplace_back(x.name_->trim().view()); + a.pos_.emplace_back(*x.lat_, *x.lng_); + try { + a.rules_.emplace_back(oh::parse(x.time_->trim().view())); + } catch (std::exception const& e) { + utl::log_error("loader.assistance", "bad assistance time \"{}\": {}", + x.time_->view(), e.what()); + } + }); a.rtree_ = geo::make_point_rtree(a.pos_); return a; } diff --git a/src/loader/build_footpaths.cc b/src/loader/build_footpaths.cc index ca6e6083e..1231d0413 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,9 +18,9 @@ #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/rt/frun.h" +#include "nigiri/scoped_timer.h" #include "nigiri/types.h" namespace nigiri::loader { @@ -301,8 +302,8 @@ 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", - "too long after adjust: {}>256", adjusted_int); + 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..cbf72ab69 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,8 +73,8 @@ 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", - p.generic_string(), mmap_.size()); + utl::log_info("loader.fs_dir", "loaded {}: {} bytes", p.generic_string(), + mmap_.size()); } ~mmap_content() final = default; std::string_view get() const final { return mmap_.view(); } diff --git a/src/loader/gtfs/load_timetable.cc b/src/loader/gtfs/load_timetable.cc index 2aa622a24..871ba9972 100644 --- a/src/loader/gtfs/load_timetable.cc +++ b/src/loader/gtfs/load_timetable.cc @@ -31,7 +31,7 @@ #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..f14b34dee 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,8 @@ 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..c5d2d4cd8 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,15 +132,15 @@ 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", - t.from_stop_id_->view()); + 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", - t.to_stop_id_->view()); + 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..d496985fd 100644 --- a/src/loader/gtfs/stop_time.cc +++ b/src/loader/gtfs/stop_time.cc @@ -4,11 +4,13 @@ #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" @@ -16,8 +18,7 @@ #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,8 +78,8 @@ 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", - "stop_times.txt:{} trip \"{}\" not found", i, t_id); + utl::log_error("loader.gtfs.stop_time", + "stop_times.txt:{} trip \"{}\" not found", i, t_id); return; } t = &trips.data_[trip_it->second]; @@ -119,8 +120,9 @@ void read_stop_times(timetable& tt, }); } } catch (...) { - log(log_lvl::error, "loader.gtfs.stop_time", - "stop_times.txt:{}: unknown stop \"{}\"", i, s.stop_id_->view()); + 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..ccd2c30f6 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,8 +34,8 @@ 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", - trips.data_[t].id_); + utl::log_error("loader.gtfs.trip", "trip \"{}\": no stop times", + trips.data_[t].id_); } return is_empty; }); @@ -329,17 +330,17 @@ 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", - R"(trip "{}": service_id "{}" not found)", t.trip_id_->view(), - t.service_id_->view()); + utl::log_error("loader.gtfs.trip", + R"(trip "{}": service_id "{}" not found)", + t.trip_id_->view(), t.service_id_->view()); return; } auto const route_it = routes.find(t.route_id_->view()); if (route_it == end(routes)) { - log(log_lvl::error, "loader.gtfs.trip", - R"(trip "{}": route_id "{}" not found)", t.trip_id_->view(), - t.route_id_->view()); + utl::log_error("loader.gtfs.trip", + R"(trip "{}": route_id "{}" not found)", + t.trip_id_->view(), t.route_id_->view()); return; } @@ -401,7 +402,8 @@ 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 +412,8 @@ 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..75c52de57 100644 --- a/src/loader/hrd/load_timetable.cc +++ b/src/loader/hrd/load_timetable.cc @@ -7,6 +7,7 @@ #include "utl/enumerate.h" #include "utl/helpers/algorithm.h" +#include "utl/logging.h" #include "utl/pipes.h" #include "utl/progress_tracker.h" @@ -25,10 +26,10 @@ 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", - "input={}, missing file for config {}: {}", - d.path().generic_string(), c.version_.view(), - path.generic_string()); + utl::log_info("loader.hrd", + "input={}, missing file for config {}: {}", + d.path().generic_string(), c.version_.view(), + path.generic_string()); } return exists; }); @@ -92,8 +93,7 @@ void load_timetable(source_idx_t const src, continue; } - log(log_lvl::info, "loader.hrd.services", "loading {}", - path.generic_string()); + utl::log_info("loader.hrd.services", "loading {}", path.generic_string()); auto const file = d.get_file(path); sb.add_services( c, relative(path, c.fplan_).string().c_str(), file.data(), diff --git a/src/loader/hrd/service/service_builder.cc b/src/loader/hrd/service/service_builder.cc index 93d643dbe..a1fedd77d 100644 --- a/src/loader/hrd/service/service_builder.cc +++ b/src/loader/hrd/service/service_builder.cc @@ -4,6 +4,7 @@ #include "utl/erase_duplicates.h" #include "utl/get_or_create.h" #include "utl/helpers/algorithm.h" +#include "utl/logging.h" #include "nigiri/loader/get_index.h" #include "nigiri/loader/hrd/service/read_services.h" @@ -217,8 +218,8 @@ void service_builder::write_services(source_idx_t const src) { .stop_seq_numbers_ = stop_seq_numbers_, .route_colors_ = route_colors_}); } catch (std::exception const& e) { - log(log_lvl::error, "loader.hrd.service", - "unable to load service {}: {}", ref.origin_, e.what()); + utl::log_error("loader.hrd.service", "unable to load service {}: {}", + ref.origin_, e.what()); continue; } } diff --git a/src/loader/hrd/stamm/attribute.cc b/src/loader/hrd/stamm/attribute.cc index b4bcc86cf..e2f2949d9 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,8 +21,8 @@ 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", - "invalid attribute line - skipping {}", line_number); + 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..b69945d9a 100644 --- a/src/loader/hrd/stamm/category.cc +++ b/src/loader/hrd/stamm/category.cc @@ -1,10 +1,9 @@ -#include "nigiri/loader/hrd/stamm/category.h" - #include "utl/parser/arg_parser.h" +#include "nigiri/loader/hrd/stamm/category.h" #include "nigiri/loader/hrd/util.h" #include "nigiri/clasz.h" -#include "nigiri/logging.h" +#include "nigiri/scoped_timer.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/stamm.cc b/src/loader/hrd/stamm/stamm.cc index 593174cc0..0ce40731d 100644 --- a/src/loader/hrd/stamm/stamm.cc +++ b/src/loader/hrd/stamm/stamm.cc @@ -102,8 +102,8 @@ bitfield stamm::resolve_bitfield(unsigned i) const { provider_idx_t stamm::resolve_provider(utl::cstr s) { auto const it = providers_.find(s.view()); if (it == end(providers_)) { - log(log_lvl::error, "nigiri.loader.hrd.provider", - "creating new provider for missing {}", s.view()); + utl::log_error("nigiri.loader.hrd.provider", + "creating new provider for missing {}", s.view()); auto const idx = provider_idx_t{tt_.providers_.size()}; tt_.providers_.emplace_back( provider{.short_name_ = s.view(), .long_name_ = s.view(), .url_ = ""}); diff --git a/src/loader/hrd/stamm/station.cc b/src/loader/hrd/stamm/station.cc index 4d8b3d95d..12bfd227c 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,8 @@ 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 +45,8 @@ 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; @@ -62,46 +63,46 @@ void parse_equivilant_stations(config const& c, std::string_view file_content) { auto const is_5_20_26 = c.version_ == "hrd_5_20_26"; - utl::for_each_line_numbered( - file_content, [&](utl::cstr line, unsigned const line_number) { - if (line.length() < 16 || line[0] == '%' || line[0] == '*') { + utl::for_each_line_numbered(file_content, [&](utl::cstr line, + unsigned const line_number) { + if (line.length() < 16 || line[0] == '%' || line[0] == '*') { + return; + } + + if (line[7] == ':') { // equivalent stations + try { + auto const eva = + parse_eva_number(line.substr(c.meta_.meta_stations_.eva_)); + auto const station_it = stations.find(eva); + if (station_it == end(stations)) { + utl::log_error("loader.hrd.meta", "line {}: {} not found", + line_number, eva); return; } - - if (line[7] == ':') { // equivalent stations - try { - auto const eva = - 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", - line_number, eva); - return; - } - auto& station = station_it->second; - utl::for_each_token(line.substr(8), ' ', [&](utl::cstr token) { - if (token.empty() || (is_5_20_26 && token.starts_with("F"))) { - return; - } - if (token.starts_with("H") // Hauptmast - || token.starts_with("B") // Bahnhofstafel - || token.starts_with("V") // Virtueller Umstieg - || token.starts_with("S") // Start-Ziel-Aequivalenz - || token.starts_with("F") // Fußweg-Aequivalenz - ) { - return; - } - if (auto const meta = parse_eva_number(token); meta != 0) { - station.equivalent_.emplace(meta); - } - }); - } catch (std::exception const& e) { - log(log_lvl::error, "loader.hrd.equivalent", - "could not parse line {}: {}", line_number, e.what()); + auto& station = station_it->second; + utl::for_each_token(line.substr(8), ' ', [&](utl::cstr token) { + if (token.empty() || (is_5_20_26 && token.starts_with("F"))) { + return; } - } else { // footpaths - } - }); + if (token.starts_with("H") // Hauptmast + || token.starts_with("B") // Bahnhofstafel + || token.starts_with("V") // Virtueller Umstieg + || token.starts_with("S") // Start-Ziel-Aequivalenz + || token.starts_with("F") // Fußweg-Aequivalenz + ) { + return; + } + if (auto const meta = parse_eva_number(token); meta != 0) { + station.equivalent_.emplace(meta); + } + }); + } catch (std::exception const& e) { + utl::log_error("loader.hrd.equivalent", "could not parse line {}: {}", + line_number, e.what()); + } + } else { // footpaths + } + }); } void parse_footpaths(config const& c, @@ -134,8 +135,8 @@ 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", - "footpath line={}: {} not found", line_number, to_idx(from_eva)); + utl::log_error("loader.hrd.footpath", "footpath line={}: {} not found", + line_number, to_idx(from_eva)); return; } auto& from = from_it->second; @@ -143,8 +144,8 @@ 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", - "footpath line={}: {} not found", line_number, to_idx(to_eva)); + utl::log_error("loader.hrd.footpath", "footpath line={}: {} not found", + line_number, to_idx(to_eva)); return; } auto& to = to_it->second; @@ -203,7 +204,7 @@ location_map_t parse_stations(config const& c, if (auto const it = stations.find(e); it != end(stations)) { tt.locations_.equivalences_[s.idx_].emplace_back(it->second.idx_); } else { - log(log_lvl::error, "loader.hrd.meta", "station {} not found", e); + utl::log_error("loader.hrd.meta", "station {} not found", e); } } diff --git a/src/loader/hrd/stamm/timezone.cc b/src/loader/hrd/stamm/timezone.cc index 62329610a..d27dc1364 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 { @@ -67,8 +66,8 @@ timezone_map_t parse_timezones(config const& c, if (it != end(tz)) { tz[parse_eva_number(line.substr(c.tz_.type1_eva_))] = it->second; } else { - log(log_lvl::error, "loader.hrd.timezone", - "no timezone for eva number: {}", first_valid_eva_number); + utl::log_error("loader.hrd.timezone", "no timezone for eva number: {}", + first_valid_eva_number); } return; } diff --git a/src/loader/hrd/stamm/track.cc b/src/loader/hrd/stamm/track.cc index 8d38219db..0ecec67a6 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/stamm.h" +#include "nigiri/loader/hrd/stamm/track.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..79888c92d 100644 --- a/src/loader/load.cc +++ b/src/loader/load.cc @@ -3,6 +3,7 @@ #include "fmt/std.h" #include "utl/enumerate.h" +#include "utl/logging.h" #include "nigiri/loader/dir.h" #include "nigiri/loader/gtfs/loader.h" @@ -47,7 +48,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::log_info("loader.load", "loading {}", path); } try { (*it)->load(local_config, src, *dir, tt, bitfields, a, shapes); @@ -57,7 +58,7 @@ timetable load(std::vector> const& paths, } else if (!ignore) { throw utl::fail("no loader for {} found", path); } else { - log(log_lvl::error, "loader.load", "no loader for {} found", path); + utl::log_error("loader.load", "no loader for {} found", path); } } diff --git a/src/query_generator/generator.cc b/src/query_generator/generator.cc index 9b9759537..37e7d2575 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,9 +168,9 @@ std::optional generator::random_query() { return sdq; } - log(log_lvl::info, "query_generator.random_pretrip", - "WARNING: failed to generate a valid query after {} attempts", - kMaxGenAttempts); + utl::log_info("query_generator.random_pretrip", + "WARNING: failed to generate a valid query after {} attempts", + kMaxGenAttempts); return std::nullopt; } @@ -196,8 +197,8 @@ 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", - "no locations in bounding box: using all locations instead"); + utl::log_info("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..c618ae7c0 100644 --- a/src/routing/dijkstra.cc +++ b/src/routing/dijkstra.cc @@ -1,6 +1,7 @@ #include "nigiri/routing/dijkstra.h" #include "fmt/core.h" +#include "utl/logging.h" #include "utl/get_or_create.h" @@ -13,7 +14,7 @@ // #define NIGIRI_DIJKSTRA_TRACING #ifdef NIGIRI_DIJKSTRA_TRACING -#define trace(...) fmt::print(__VA_ARGS__) +#define trace(...) utl::log_debug("nigiri.routing.dijkstra", __VA_ARGS__) #else #define trace(...) #endif diff --git a/src/routing/ontrip_train.cc b/src/routing/ontrip_train.cc index a60968574..92df48d5a 100644 --- a/src/routing/ontrip_train.cc +++ b/src/routing/ontrip_train.cc @@ -1,5 +1,6 @@ #include "nigiri/routing/ontrip_train.h" +#include "utl/logging.h" #include "utl/verify.h" #include "nigiri/routing/query.h" @@ -12,7 +13,8 @@ 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::log_debug("nigiri.routing.ontrip_train", fmt_str, + std::forward(args)...); } } diff --git a/src/routing/start_times.cc b/src/routing/start_times.cc index 3a42c6547..2fbab8c0b 100644 --- a/src/routing/start_times.cc +++ b/src/routing/start_times.cc @@ -6,6 +6,7 @@ #include "utl/enumerate.h" #include "utl/equal_ranges_linear.h" #include "utl/get_or_create.h" +#include "utl/logging.h" #include "utl/overloaded.h" namespace nigiri::routing { @@ -32,7 +33,8 @@ 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::log_debug("nigiri.routing.start_times", fmt::runtime(fmt_str), + std::forward(args)...); } } diff --git a/src/rt/frun.cc b/src/rt/frun.cc index a16384bc9..1591178a0 100644 --- a/src/rt/frun.cc +++ b/src/rt/frun.cc @@ -4,6 +4,7 @@ #include #include +#include "utl/logging.h" #include "utl/overloaded.h" #include "utl/verify.h" @@ -316,8 +317,8 @@ stop_idx_t frun::first_valid(stop_idx_t const from) const { return i; } } - log(log_lvl::error, "frun", "no first valid found: id={}, name={}, dbg={}", - fmt::streamed(id()), name(), fmt::streamed(dbg())); + utl::log_error("frun", "no first valid found: id={}, name={}, dbg={}", + fmt::streamed(id()), name(), fmt::streamed(dbg())); return stop_range_.to_; } @@ -330,8 +331,8 @@ stop_idx_t frun::last_valid() const { return i; } } - log(log_lvl::error, "frun", "no last valid found: id={}, name={}, dbg={}", - fmt::streamed(id()), name(), fmt::streamed(dbg())); + utl::log_error("frun", "no last valid found: id={}, name={}, dbg={}", + fmt::streamed(id()), name(), fmt::streamed(dbg())); return stop_range_.to_; } diff --git a/src/rt/gtfsrt_update.cc b/src/rt/gtfsrt_update.cc index a745b2423..0298c9695 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,8 +213,9 @@ 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", - "stop assignment: src={}, stop_id=\"{}\" not found", src, new_id); + utl::log_error("gtfsrt.stop_assignment", + "stop assignment: src={}, stop_id=\"{}\" not found", + src, new_id); } } else { // Just reset in case a track change / skipped stop got reversed. @@ -308,9 +308,9 @@ 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", - R"(ignoring unsupported "{}" field (tag={}, id={}))", field, tag, - entity.id()); + utl::log_error("rt.gtfs.unsupported", + R"(ignoring unsupported "{}" field (tag={}, id={}))", + field, tag, entity.id()); ++stat; } }; @@ -321,7 +321,8 @@ 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 +330,8 @@ 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 +339,8 @@ 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 +351,8 @@ 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,8 +367,8 @@ 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={}) {}", - tag, remove_nl(td.DebugString())); + utl::log_error("rt.gtfs.resolve", "could not resolve (tag={}) {}", tag, + remove_nl(td.DebugString())); span->AddEvent( "unresolved trip", { @@ -395,7 +399,8 @@ 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 +426,8 @@ 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..198c91d81 100644 --- a/src/rt/vdv/vdv_update.cc +++ b/src/rt/vdv/vdv_update.cc @@ -8,6 +8,7 @@ #include "utl/enumerate.h" #include "utl/get_or_create.h" +#include "utl/logging.h" #include "utl/parser/arg_parser.h" #include "utl/verify.h" @@ -26,7 +27,7 @@ namespace nigiri::rt::vdv { // #define VDV_DEBUG #ifdef VDV_DEBUG -#define vdv_trace(...) fmt::print(__VA_ARGS__) +#define vdv_trace(...) utl::log_debug("nigiri.vdv_trace", __VA_ARGS__) #else #define vdv_trace(...) #endif @@ -89,8 +90,8 @@ std::optional updater::get_opt_time(pugi::xml_node const& node, try { return std::optional{parse_time_no_tz(xpath.node().child_value())}; } catch (std::exception const& e) { - log(log_lvl::error, "vdv_update.get_opt_time", - "{}, invalid time input: {}", e.what(), xpath.node().child_value()); + utl::log_error("vdv_update.get_opt_time", "{}, invalid time input: {}", + e.what(), xpath.node().child_value()); } } return std::nullopt; diff --git a/src/logging.cc b/src/scoped_timer.cc similarity index 64% rename from src/logging.cc rename to src/scoped_timer.cc index b09c62b43..435bbdad2 100644 --- a/src/logging.cc +++ b/src/scoped_timer.cc @@ -1,10 +1,12 @@ -#include "nigiri/logging.h" +#include "utl/logging.h" + +#include "nigiri/scoped_timer.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,8 +15,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_}, - t); + utl::log_info(name_.c_str(), "finished {} {}ms", std::string_view{name_}, t); } } // namespace nigiri