Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ build --java_language_version=17
build --tool_java_language_version=17
build --java_runtime_version=remotejdk_17
build --tool_java_runtime_version=remotejdk_17
build --@score_baselibs//score/json:base_library=nlohmann

test --test_output=errors

Expand Down
14 changes: 7 additions & 7 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module(
bazel_dep(name = "score_starpls_lsp", version = "0.1.0", dev_dependency = True)

# Python rules.
bazel_dep(name = "rules_python", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "rules_python", version = "1.7.0", dev_dependency = True)

PYTHON_VERSION = "3.12"

Expand All @@ -36,13 +36,13 @@ python.toolchain(
use_repo(python)

# C++ GoogleTest dependencies.
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True)
bazel_dep(name = "googletest", version = "1.17.0", dev_dependency = True)

# Rust rules.
bazel_dep(name = "rules_rust", version = "0.56.0")
bazel_dep(name = "rules_rust", version = "0.67.0")

# C/C++ rules.
bazel_dep(name = "rules_cc", version = "0.1.1", dev_dependency = True)
bazel_dep(name = "rules_cc", version = "0.2.14")

# Rust module dependencies.
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
Expand All @@ -51,8 +51,8 @@ rust.toolchain(
versions = ["1.85.0"],
)

# C++ base libs.
bazel_dep(name = "score_baselibs", version = "0.1.2", dev_dependency = True)
# Json for C++.
bazel_dep(name = "nlohmann_json", version = "3.12.0")

# Score Rust crates.
bazel_dep(name = "score_crates", version = "0.0.4")
bazel_dep(name = "score_crates", version = "0.0.6")
2 changes: 1 addition & 1 deletion test_scenarios_cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cc_library(
],
includes = ["include/"],
visibility = ["//visibility:public"],
deps = ["@score_baselibs//score/json:json_parser"],
deps = ["@nlohmann_json//:json"],
)

cc_test(
Expand Down
17 changes: 8 additions & 9 deletions test_scenarios_cpp/include/tracing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <string>

#include "monotonic_clock.hpp"
#include "score/json/json_writer.h"
#include <nlohmann/json.hpp>

#define _TRACING(target, level, fields...) \
do { \
Expand Down Expand Up @@ -58,8 +58,7 @@ class Subscriber {
template <typename... T>
void event(const std::optional<std::string>& target, const Level& level,
std::pair<std::string, T>... fields) const {
using namespace score::json;
Object fields_object{object_create(fields...)};
nlohmann::json fields_object = object_create(fields...);
handle_event(target, level, std::move(fields_object));
}

Expand All @@ -69,15 +68,15 @@ class Subscriber {
MonotonicClock timer_;

void handle_event(const std::optional<std::string>& target, const Level& level,
score::json::Object&& fields) const;
nlohmann::json&& fields) const;

score::json::Object object_create() const { return score::json::Object{}; }
nlohmann::json object_create() const { return nlohmann::json::object(); }

template <typename HeadT, typename... TailT>
score::json::Object object_create(std::pair<std::string, HeadT> field,
std::pair<std::string, TailT>... fields) const {
auto object{object_create(fields...)};
object.insert(field);
nlohmann::json object_create(std::pair<std::string, HeadT> field,
std::pair<std::string, TailT>... fields) const {
auto object = object_create(fields...);
object[field.first] = field.second;
return object;
}
};
Expand Down
14 changes: 4 additions & 10 deletions test_scenarios_cpp/src/tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ Subscriber::Subscriber(Level max_level, bool thread_ids)
: max_level_{max_level}, thread_ids_{thread_ids} {}

void Subscriber::handle_event(const std::optional<std::string>& target, const Level& level,
score::json::Object&& fields) const {
using namespace score::json;

nlohmann::json&& fields) const {
// Drop handling if below max level.
if (level < max_level_) {
return;
}

Object event;
nlohmann::json event;

// Add timestamp.
event.emplace("timestamp", timer_.format_time());
Expand All @@ -98,17 +96,13 @@ void Subscriber::handle_event(const std::optional<std::string>& target, const Le
}

// Make JSON string.
JsonWriter writer;
auto buffer_result{writer.ToBuffer(event)};
if (!buffer_result) {
throw std::runtime_error{"Failed to stringify JSON"};
}
std::string json_str = event.dump();

// Minify JSON and add "\n".
// "\n" + 'std::flush' is used instead of 'std::endl'.
// This is to avoid message mangling in multithreaded scenarios.
std::stringstream ss;
ss << minify_json(*buffer_result) << "\n";
ss << minify_json(json_str) << "\n";

// Print output.
std::cout << ss.str() << std::flush;
Expand Down
Loading