Skip to content

Commit 418f882

Browse files
committed
add logging to complex module example
1 parent 4eb8643 commit 418f882

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/viam/examples/modules/complex/base/impl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
#include <exception>
44
#include <fstream>
5-
#include <iostream>
65
#include <sstream>
76

87
#include <grpcpp/support/status.h>
98

109
#include <viam/sdk/components/base.hpp>
1110
#include <viam/sdk/components/component.hpp>
1211
#include <viam/sdk/config/resource.hpp>
12+
#include <viam/sdk/log/logging.hpp>
1313
#include <viam/sdk/resource/resource.hpp>
1414

1515
using namespace viam::sdk;
@@ -106,7 +106,8 @@ void MyBase::set_power(const Vector3& linear, const Vector3& angular, const Prot
106106
}
107107

108108
ProtoStruct MyBase::do_command(const ProtoStruct& command) {
109-
std::cout << "Received DoCommand request for MyBase " << Resource::name() << std::endl;
109+
// The VIAM_RESOURCE_LOG macro will associate log messages to the current resource
110+
VIAM_RESOURCE_LOG(info) << "Received DoCommand request";
110111
return command;
111112
}
112113

src/viam/examples/modules/complex/gizmo/impl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "impl.hpp"
22

33
#include <fstream>
4-
#include <iostream>
54
#include <sstream>
65
#include <vector>
76

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <viam/sdk/components/base.hpp>
99
#include <viam/sdk/components/component.hpp>
1010
#include <viam/sdk/config/resource.hpp>
11+
#include <viam/sdk/log/logging.hpp>
1112
#include <viam/sdk/module/module.hpp>
1213
#include <viam/sdk/module/service.hpp>
1314
#include <viam/sdk/registry/registry.hpp>
@@ -47,6 +48,9 @@ int main(int argc, char** argv) {
4748
[](Dependencies deps, ResourceConfig cfg) { return std::make_unique<MyGizmo>(deps, cfg); },
4849
MyGizmo::validate);
4950

51+
// Write general log statements with the VIAM_LOG macro
52+
VIAM_LOG(info) << "Registered mybase and mygizmo";
53+
5054
Model mysummation_model("viam", "summation", "mysummation");
5155

5256
std::shared_ptr<ModelRegistration> mysummation_mr = std::make_shared<ModelRegistration>(

0 commit comments

Comments
 (0)