Skip to content

Commit 40b5400

Browse files
committed
use VIAM_SDK macro prefix
1 parent ee85b28 commit 40b5400

File tree

10 files changed

+51
-50
lines changed

10 files changed

+51
-50
lines changed

src/viam/examples/modules/complex/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ int main(int argc, char** argv) {
4848
[](Dependencies deps, ResourceConfig cfg) { return std::make_unique<MyGizmo>(deps, cfg); },
4949
MyGizmo::validate);
5050

51-
// Write general log statements with the VIAM_LOG macro
52-
VIAM_LOG(info) << "Registered mybase and mygizmo";
51+
// Write general log statements with the VIAM_SDK_LOG macro
52+
VIAM_SDK_LOG(info) << "Registered mybase and mygizmo";
5353

5454
Model mysummation_model("viam", "summation", "mysummation");
5555

src/viam/examples/modules/simple/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ int main(int argc, char** argv) try {
8383
// any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed.
8484
Instance inst;
8585

86-
// Write general log statements with the VIAM_LOG macro
87-
VIAM_LOG(info) << "Starting up simple sensor module";
86+
// Write general log statements with the VIAM_SDK_LOG macro
87+
VIAM_SDK_LOG(info) << "Starting up simple sensor module";
8888

8989
Model mysensor_model("viam", "sensor", "mysensor");
9090

src/viam/sdk/common/client_helper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace sdk {
1414
namespace client_helper_details {
1515

1616
[[noreturn]] void errorHandlerReturnedUnexpectedly(const ::grpc::Status* status) noexcept {
17-
VIAM_LOG(fatal) << "ClientHelper error handler callback returned instead of throwing: "
18-
<< status->error_message() << '(' << status->error_details() << ')';
17+
VIAM_SDK_LOG(fatal) << "ClientHelper error handler callback returned instead of throwing: "
18+
<< status->error_message() << '(' << status->error_details() << ')';
1919
std::abort();
2020
}
2121

src/viam/sdk/log/logging.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ log_level level_from_string(std::string level) {
5555
return ll::fatal;
5656
}
5757

58-
VIAM_LOG(warn) << "Returning unknown log level `" << level << "` as info";
58+
VIAM_SDK_LOG(warn) << "Returning unknown log level `" << level << "` as info";
5959
return ll::info;
6060
}
6161

@@ -132,11 +132,11 @@ void LogManager::init_logging() {
132132
console_sink_->set_formatter(fmt);
133133

134134
boost::log::core::get()->add_sink(console_sink_);
135-
VIAM_LOG(debug) << "Initialized console logging";
135+
VIAM_SDK_LOG(debug) << "Initialized console logging";
136136
}
137137

138138
void LogManager::disable_console_logging() {
139-
VIAM_LOG(debug) << "Disabling console logging";
139+
VIAM_SDK_LOG(debug) << "Disabling console logging";
140140

141141
// Set a filter which ignores all console logs unless they contain a console force flag which is
142142
// set to true.

src/viam/sdk/log/logging.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(attr_time,
134134
"TimeStamp",
135135
boost::log::attributes::local_clock::value_type);
136136

137-
#define VIAM_LOG_IMPL(lg, level) \
137+
#define VIAM_SDK_LOG_IMPL(lg, level) \
138138
BOOST_LOG_SEV((lg), ::viam::sdk::log_level::level) \
139139
<< ::boost::log::add_value(::viam::sdk::attr_file_type{}, \
140140
::viam::sdk::log_detail::trim_filename(__FILE__)) \
@@ -144,15 +144,15 @@ BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(attr_time,
144144
/// @ingroup Log
145145
///
146146
/// Use this macro to generate log messages pertaining to the SDK at large.
147-
#define VIAM_LOG(level) VIAM_LOG_IMPL(::viam::sdk::LogManager::get().global_logger(), level)
147+
#define VIAM_SDK_LOG(level) VIAM_SDK_LOG_IMPL(::viam::sdk::LogManager::get().global_logger(), level)
148148

149149
/// @brief Log macro for resource-level logs.
150150
/// @ingroup Log
151151
///
152152
/// This macro can only be called from the definition of a member function of a class inheriting
153153
/// @ref Resource. It will log messages to the log source of that specific resource, allowing
154154
/// resource-level log filtering.
155-
#define VIAM_RESOURCE_LOG(level) VIAM_LOG_IMPL(this->logger_, level)
155+
#define VIAM_RESOURCE_LOG(level) VIAM_SDK_LOG_IMPL(this->logger_, level)
156156

157157
} // namespace sdk
158158
} // namespace viam

src/viam/sdk/module/handler_map.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ HandlerMap_ from_proto_impl<module::v1::HandlerMap>::operator()(
6464
try {
6565
hm.add_model(Model::from_str(mod), handle);
6666
} catch (const std::exception& ex) {
67-
VIAM_LOG(error) << "Error " << ex.what() << " processing model " + mod;
67+
VIAM_SDK_LOG(error) << "Error " << ex.what() << " processing model " + mod;
6868
}
6969
}
7070
}

src/viam/sdk/module/service.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
109109
try {
110110
Stoppable::stop_if_stoppable(res);
111111
} catch (const std::exception& err) {
112-
VIAM_LOG(error) << "unable to stop resource: " << err.what();
112+
VIAM_SDK_LOG(error) << "unable to stop resource: " << err.what();
113113
}
114114

115115
const std::shared_ptr<const ModelRegistration> reg =
@@ -170,7 +170,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
170170
try {
171171
Stoppable::stop_if_stoppable(res);
172172
} catch (const std::exception& err) {
173-
VIAM_LOG(error) << "unable to stop resource: " << err.what();
173+
VIAM_SDK_LOG(error) << "unable to stop resource: " << err.what();
174174
}
175175

176176
manager->remove(name);
@@ -247,14 +247,14 @@ ModuleService::ModuleService(int argc,
247247

248248
ModuleService::~ModuleService() {
249249
// TODO(RSDK-5509): Run registered cleanup functions here.
250-
VIAM_LOG(info) << "Shutting down gracefully.";
250+
VIAM_SDK_LOG(info) << "Shutting down gracefully.";
251251
server_->shutdown();
252252

253253
if (parent_) {
254254
try {
255255
parent_->close();
256256
} catch (const std::exception& exc) {
257-
VIAM_LOG(error) << exc.what();
257+
VIAM_SDK_LOG(error) << exc.what();
258258
}
259259
}
260260
}
@@ -272,8 +272,8 @@ void ModuleService::serve() {
272272
module_->set_ready();
273273
server_->start();
274274

275-
VIAM_LOG(info) << "Module listening on " << module_->addr();
276-
VIAM_LOG(info) << "Module handles the following API/model pairs:\n" << module_->handles();
275+
VIAM_SDK_LOG(info) << "Module listening on " << module_->addr();
276+
VIAM_SDK_LOG(info) << "Module handles the following API/model pairs:\n" << module_->handles();
277277

278278
signal_manager_.wait();
279279
}

src/viam/sdk/resource/resource_manager.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void ResourceManager::replace_all(
5050
try {
5151
do_add(resource.first, resource.second);
5252
} catch (std::exception& exc) {
53-
VIAM_LOG(error) << "Error replacing all resources" << exc.what();
53+
VIAM_SDK_LOG(error) << "Error replacing all resources" << exc.what();
5454
return;
5555
}
5656
}
@@ -95,7 +95,7 @@ void ResourceManager::add(const Name& name, std::shared_ptr<Resource> resource)
9595
try {
9696
do_add(name, std::move(resource));
9797
} catch (std::exception& exc) {
98-
VIAM_LOG(error) << "Error adding resource to subtype service: " << exc.what();
98+
VIAM_SDK_LOG(error) << "Error adding resource to subtype service: " << exc.what();
9999
}
100100
};
101101

@@ -132,7 +132,7 @@ void ResourceManager::remove(const Name& name) {
132132
try {
133133
do_remove(name);
134134
} catch (std::exception& exc) {
135-
VIAM_LOG(error) << "unable to remove resource: " << exc.what();
135+
VIAM_SDK_LOG(error) << "unable to remove resource: " << exc.what();
136136
};
137137
};
138138

@@ -142,7 +142,8 @@ void ResourceManager::replace_one(const Name& name, std::shared_ptr<Resource> re
142142
do_remove(name);
143143
do_add(name, std::move(resource));
144144
} catch (std::exception& exc) {
145-
VIAM_LOG(error) << "failed to replace resource " << name.to_string() << ": " << exc.what();
145+
VIAM_SDK_LOG(error) << "failed to replace resource " << name.to_string() << ": "
146+
<< exc.what();
146147
}
147148
}
148149

src/viam/sdk/robot/client.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ RobotClient::~RobotClient() {
121121
try {
122122
this->close();
123123
} catch (const std::exception& e) {
124-
VIAM_LOG(error) << "Received err while closing RobotClient: " << e.what();
124+
VIAM_SDK_LOG(error) << "Received err while closing RobotClient: " << e.what();
125125
} catch (...) {
126-
VIAM_LOG(error) << "Received unknown err while closing RobotClient";
126+
VIAM_SDK_LOG(error) << "Received unknown err while closing RobotClient";
127127
}
128128
}
129129
}
@@ -150,7 +150,7 @@ std::vector<RobotClient::operation> RobotClient::get_operations() {
150150

151151
grpc::Status const response = impl_->stub_->GetOperations(ctx, req, &resp);
152152
if (is_error_response(response)) {
153-
VIAM_LOG(error) << "Error getting operations: " << response.error_message();
153+
VIAM_SDK_LOG(error) << "Error getting operations: " << response.error_message();
154154
}
155155

156156
for (int i = 0; i < resp.operations().size(); ++i) {
@@ -168,7 +168,7 @@ void RobotClient::cancel_operation(std::string id) {
168168
req.set_id(id);
169169
const grpc::Status response = impl_->stub_->CancelOperation(ctx, req, &resp);
170170
if (is_error_response(response)) {
171-
VIAM_LOG(error) << "Error canceling operation with id " << id;
171+
VIAM_SDK_LOG(error) << "Error canceling operation with id " << id;
172172
}
173173
}
174174

@@ -181,7 +181,7 @@ void RobotClient::block_for_operation(std::string id) {
181181

182182
const grpc::Status response = impl_->stub_->BlockForOperation(ctx, req, &resp);
183183
if (is_error_response(response)) {
184-
VIAM_LOG(error) << "Error blocking for operation with id " << id;
184+
VIAM_SDK_LOG(error) << "Error blocking for operation with id " << id;
185185
}
186186
}
187187

@@ -192,7 +192,7 @@ void RobotClient::refresh() {
192192

193193
const grpc::Status response = impl_->stub_->ResourceNames(ctx, req, &resp);
194194
if (is_error_response(response)) {
195-
VIAM_LOG(error) << "Error getting resource names: " << response.error_message();
195+
VIAM_SDK_LOG(error) << "Error getting resource names: " << response.error_message();
196196
}
197197

198198
std::unordered_map<Name, std::shared_ptr<Resource>> new_resources;
@@ -216,8 +216,8 @@ void RobotClient::refresh() {
216216
const Name name_({name.namespace_(), name.type(), name.subtype()}, "", name.name());
217217
new_resources.emplace(name_, rpc_client);
218218
} catch (const std::exception& exc) {
219-
VIAM_LOG(debug) << "Error registering component " << name.subtype() << ": "
220-
<< exc.what();
219+
VIAM_SDK_LOG(debug)
220+
<< "Error registering component " << name.subtype() << ": " << exc.what();
221221
}
222222
}
223223
}
@@ -281,9 +281,9 @@ void RobotClient::log(const std::string& name,
281281
if (is_error_response(response)) {
282282
// Manually override to force this to get logged to console so we don't set off an infinite
283283
// loop
284-
VIAM_LOG(error) << boost::log::add_value(sdk::impl::attr_console_force_type{}, true)
285-
<< "Error sending log message over grpc: " << response.error_message()
286-
<< response.error_details();
284+
VIAM_SDK_LOG(error) << boost::log::add_value(sdk::impl::attr_console_force_type{}, true)
285+
<< "Error sending log message over grpc: " << response.error_message()
286+
<< response.error_details();
287287
}
288288
}
289289

@@ -339,7 +339,7 @@ std::vector<RobotClient::frame_system_config> RobotClient::get_frame_system_conf
339339

340340
const grpc::Status response = impl_->stub_->FrameSystemConfig(ctx, req, &resp);
341341
if (is_error_response(response)) {
342-
VIAM_LOG(error) << "Error getting frame system config: " << response.error_message();
342+
VIAM_SDK_LOG(error) << "Error getting frame system config: " << response.error_message();
343343
}
344344

345345
const RepeatedPtrField<FrameSystemConfig> configs = resp.frame_system_configs();
@@ -367,7 +367,7 @@ pose_in_frame RobotClient::transform_pose(
367367

368368
const grpc::Status response = impl_->stub_->TransformPose(ctx, req, &resp);
369369
if (is_error_response(response)) {
370-
VIAM_LOG(error) << "Error getting PoseInFrame: " << response.error_message();
370+
VIAM_SDK_LOG(error) << "Error getting PoseInFrame: " << response.error_message();
371371
}
372372

373373
return from_proto(resp.pose());
@@ -402,8 +402,8 @@ void RobotClient::stop_all(const std::unordered_map<Name, ProtoStruct>& extra) {
402402
}
403403
const grpc::Status response = impl_->stub_->StopAll(ctx, req, &resp);
404404
if (is_error_response(response)) {
405-
VIAM_LOG(error) << "Error stopping all: " << response.error_message()
406-
<< response.error_details();
405+
VIAM_SDK_LOG(error) << "Error stopping all: " << response.error_message()
406+
<< response.error_details();
407407
}
408408
}
409409

@@ -431,8 +431,8 @@ RobotClient::status RobotClient::get_machine_status() const {
431431

432432
const grpc::Status response = impl_->stub_->GetMachineStatus(ctx, req, &resp);
433433
if (is_error_response(response)) {
434-
VIAM_LOG(error) << "Error getting machine status: " << response.error_message()
435-
<< response.error_details();
434+
VIAM_SDK_LOG(error) << "Error getting machine status: " << response.error_message()
435+
<< response.error_details();
436436
}
437437
switch (resp.state()) {
438438
case robot::v1::GetMachineStatusResponse_State_STATE_INITIALIZING:

src/viam/sdk/tests/test_log.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace sdktests {
1616
BOOST_AUTO_TEST_CASE(test_cout_logging) {
1717
cout_redirect redirect;
1818

19-
VIAM_LOG(info) << "log1";
19+
VIAM_SDK_LOG(info) << "log1";
2020

2121
using namespace std::string_literals;
2222

@@ -32,28 +32,28 @@ BOOST_AUTO_TEST_CASE(test_cout_logging) {
3232
BOOST_AUTO_TEST_CASE(test_global_filter) {
3333
cout_redirect redirect;
3434

35-
VIAM_LOG(info) << "info1";
36-
VIAM_LOG(error) << "error1";
37-
VIAM_LOG(trace) << "trace1"; // not logged
35+
VIAM_SDK_LOG(info) << "info1";
36+
VIAM_SDK_LOG(error) << "error1";
37+
VIAM_SDK_LOG(trace) << "trace1"; // not logged
3838

3939
auto& logger = sdk::LogManager::get();
4040

4141
using ll = sdk::log_level;
4242

4343
logger.set_global_log_level(ll::trace);
4444

45-
VIAM_LOG(trace) << "trace2";
46-
VIAM_LOG(info) << "info2";
45+
VIAM_SDK_LOG(trace) << "trace2";
46+
VIAM_SDK_LOG(info) << "info2";
4747

4848
logger.set_global_log_level(ll::error);
4949

50-
VIAM_LOG(info) << "info3"; // not logged
51-
VIAM_LOG(error) << "error2";
50+
VIAM_SDK_LOG(info) << "info3"; // not logged
51+
VIAM_SDK_LOG(error) << "error2";
5252

5353
logger.set_global_log_level(ll::info);
5454

55-
VIAM_LOG(info) << "info4";
56-
VIAM_LOG(trace) << "trace3"; // once again not logged
55+
VIAM_SDK_LOG(info) << "info4";
56+
VIAM_SDK_LOG(trace) << "trace3"; // once again not logged
5757

5858
const std::string rec = redirect.os.str();
5959
redirect.release();

0 commit comments

Comments
 (0)