From 012684bb15fcb454ec58ddabf7f94d1146d6169f Mon Sep 17 00:00:00 2001 From: Lia Stratopoulos <167905060+lia-viam@users.noreply.github.com> Date: Thu, 12 Mar 2026 15:52:25 -0400 Subject: [PATCH] Move caller info from message field to caller field in LogEntry Populate the dedicated `caller` field on `common::v1::LogEntry` with `Defined`, `File`, and `Line` from Boost.Log attributes, matching the structure of Go's zap EntryCaller. The raw message no longer includes the `[file:line]` prefix. Co-Authored-By: Claude Sonnet 4.6 --- src/viam/sdk/log/private/log_backend.cpp | 11 ++++------- src/viam/sdk/robot/client.cpp | 10 +++++++++- src/viam/sdk/robot/client.hpp | 4 +++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/viam/sdk/log/private/log_backend.cpp b/src/viam/sdk/log/private/log_backend.cpp index cde30a506..96e4b3e57 100644 --- a/src/viam/sdk/log/private/log_backend.cpp +++ b/src/viam/sdk/log/private/log_backend.cpp @@ -20,15 +20,12 @@ time_pt ptime_convert(const boost::posix_time::ptime& from) { } void LogBackend::consume(const boost::log::record_view& rec) const { - std::ostringstream os; - - os << "[" << *rec[attr_file_type{}] << ":" << rec[attr_line_type{}] << "] " - << *rec[boost::log::expressions::smessage]; - parent->log(*rec[attr_channel_type{}], to_string(*rec[attr_sev_type{}]), - os.str(), - ptime_convert(*rec[attr_time_type{}])); + std::string(*rec[boost::log::expressions::smessage]), + ptime_convert(*rec[attr_time_type{}]), + std::string(*rec[attr_file_type{}]), + *rec[attr_line_type{}]); } boost::shared_ptr LogBackend::create(RobotClient* p) { diff --git a/src/viam/sdk/robot/client.cpp b/src/viam/sdk/robot/client.cpp index a1779c9a2..f998fbe93 100644 --- a/src/viam/sdk/robot/client.cpp +++ b/src/viam/sdk/robot/client.cpp @@ -309,7 +309,9 @@ std::vector RobotClient::resource_names() const { void RobotClient::log(const std::string& name, const std::string& level, const std::string& message, - time_pt time) { + time_pt time, + const std::string& file, + unsigned int line) { if (!impl_) { throw std::runtime_error("Tried to send logs to robot when it was not connected"); } @@ -322,6 +324,12 @@ void RobotClient::log(const std::string& name, log.set_level(level); *log.mutable_message() = message; *log.mutable_time() = to_proto(time); + + auto& fields = *log.mutable_caller()->mutable_fields(); + fields["Defined"].set_bool_value(true); + fields["File"].set_string_value(file); + fields["Line"].set_number_value(line); + req.mutable_logs()->Add(std::move(log)); robot::v1::LogResponse resp; diff --git a/src/viam/sdk/robot/client.hpp b/src/viam/sdk/robot/client.hpp index 6e296c3e3..72261ee4a 100644 --- a/src/viam/sdk/robot/client.hpp +++ b/src/viam/sdk/robot/client.hpp @@ -174,7 +174,9 @@ class RobotClient { void log(const std::string& name, const std::string& level, const std::string& message, - time_pt time); + time_pt time, + const std::string& file, + unsigned int line); // Makes this RobotClient manage logging by sending logs over grpc to viam-server. // This is private and only ever called by ModuleService; in other words it is only called when