Skip to content

Commit d681f6f

Browse files
committed
rename to log manager and global logger
1 parent 2de9f40 commit d681f6f

File tree

9 files changed

+32
-31
lines changed

9 files changed

+32
-31
lines changed

src/viam/sdk/common/instance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Instance::Instance() {
2727

2828
impl_ = std::make_unique<Instance::Impl>();
2929
impl_->registry.initialize();
30-
impl_->logger.init_logging();
30+
impl_->log_mgr.init_logging();
3131
}
3232

3333
Instance::~Instance() {

src/viam/sdk/common/instance.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Instance {
2828

2929
private:
3030
friend class Registry;
31-
friend class Logger;
31+
friend class LogManager;
3232

3333
struct Impl;
3434
std::unique_ptr<Impl> impl_;

src/viam/sdk/common/private/instance.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace sdk {
99

1010
struct Instance::Impl {
1111
Registry registry;
12-
Logger logger;
12+
LogManager log_mgr;
1313
};
1414

1515
} // namespace sdk

src/viam/sdk/log/logger.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const char* global_resource_name() {
6767
return "Viam C++ SDK";
6868
}
6969

70-
bool Logger::Filter::operator()(const boost::log::attribute_value_set& attrs) const {
70+
bool LogManager::Filter::operator()(const boost::log::attribute_value_set& attrs) const {
7171
auto sev = attrs[attr_sev_type{}];
7272
if (!sev) {
7373
return false;
@@ -84,31 +84,31 @@ bool Logger::Filter::operator()(const boost::log::attribute_value_set& attrs) co
8484
return *sev >= parent->global_level_;
8585
}
8686

87-
Logger& Logger::get() {
88-
static Logger& result = Instance::current(Instance::Creation::open_existing).impl_->logger;
87+
LogManager& LogManager::get() {
88+
static LogManager& result = Instance::current(Instance::Creation::open_existing).impl_->log_mgr;
8989

9090
return result;
9191
}
9292

93-
LogSource& Logger::logger() {
93+
LogSource& LogManager::global_logger() {
9494
return sdk_logger_;
9595
}
9696

97-
void Logger::set_global_log_level(log_level lvl) {
97+
void LogManager::set_global_log_level(log_level lvl) {
9898
global_level_ = lvl;
9999
}
100100

101-
void Logger::set_global_log_level(int argc, char** argv) {
101+
void LogManager::set_global_log_level(int argc, char** argv) {
102102
if (argc >= 3 && strcmp(argv[2], "--log-level=debug") == 0) {
103103
set_global_log_level(log_level::debug);
104104
}
105105
}
106106

107-
void Logger::set_resource_log_level(const std::string& resource, log_level lvl) {
107+
void LogManager::set_resource_log_level(const std::string& resource, log_level lvl) {
108108
resource_levels_[resource] = lvl;
109109
}
110110

111-
void Logger::init_logging() {
111+
void LogManager::init_logging() {
112112
sdk_logger_.channel(global_resource_name());
113113
boost::log::core::get()->add_global_attribute("TimeStamp",
114114
boost::log::attributes::local_clock());
@@ -134,7 +134,7 @@ void Logger::init_logging() {
134134
VIAM_LOG(debug) << "Initialized console logging";
135135
}
136136

137-
void Logger::disable_console_logging() {
137+
void LogManager::disable_console_logging() {
138138
VIAM_LOG(debug) << "Disabling console logging";
139139
boost::log::core::get()->remove_sink(console_sink_);
140140
}

src/viam/sdk/log/logger.hpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ using LogSource = boost::log::sources::severity_channel_logger_mt<log_level>;
5050
/// @ingroup Log
5151
const char* global_resource_name();
5252

53-
/// @class Logger logger.hpp "log/logger.hpp"
53+
/// @class LogManager logger.hpp "log/logger.hpp"
5454
/// @brief Manages the logging infrastructure in the SDDK.
5555
/// @ingroup Log
5656
///
5757
/// Handles initialization and bookkeeping for logging infrastructure in the C++ SDK. This includes
5858
/// console logging, if active, and both global and resource-level log filtering.
59-
class Logger {
59+
class LogManager {
6060
public:
6161
struct Filter {
62-
const Logger* parent;
62+
const LogManager* parent;
6363

6464
bool operator()(const boost::log::attribute_value_set&) const;
6565
};
6666

6767
/// @brief Returns the unique logger instance.
6868
///
6969
/// This is the only way to access the logger.
70-
static Logger& get();
70+
static LogManager& get();
7171

7272
/// @brief Set the global logger severity.
7373
void set_global_log_level(log_level);
@@ -82,28 +82,29 @@ class Logger {
8282

8383
/// @brief Set the logger severity for a resource.
8484
///
85-
/// Logger can maintain separate severity levels for individual resources. For example, you may
86-
/// want to only report "error" messages for global logs and logs for one component of a modular
87-
/// resource, but enable verbose logging for a new component that is still being debugged.
85+
/// LogManager can maintain separate severity levels for individual resources. For example, you
86+
/// may want to only report "error" messages for global logs and logs for one component of a
87+
/// modular resource, but enable verbose logging for a new component that is still being
88+
/// debugged.
8889
/// @see @ref Resource, which has a set_log_level method which automatically provides its own
8990
/// resource name.
9091
void set_resource_log_level(const std::string& resource, log_level);
9192

9293
/// @brief Return the SDK global log source.
9394
///
9495
/// Users should prefer to log messages using the logging macros below.
95-
LogSource& logger();
96+
LogSource& global_logger();
9697

9798
private:
9899
friend class RobotClient;
99100
friend class Instance;
100-
Logger() = default;
101+
LogManager() = default;
101102

102-
Logger(const Logger&) = delete;
103-
Logger(Logger&&) = delete;
103+
LogManager(const LogManager&) = delete;
104+
LogManager(LogManager&&) = delete;
104105

105-
Logger& operator=(const Logger&) = delete;
106-
Logger& operator=(Logger&&) = delete;
106+
LogManager& operator=(const LogManager&) = delete;
107+
LogManager& operator=(LogManager&&) = delete;
107108

108109
void init_logging();
109110
void disable_console_logging();
@@ -143,7 +144,7 @@ BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(attr_time,
143144
/// @ingroup Log
144145
///
145146
/// Use this macro to generate log messages pertaining to the SDK at large.
146-
#define VIAM_LOG(level) VIAM_LOG_IMPL(::viam::sdk::Logger::get().logger(), level)
147+
#define VIAM_LOG(level) VIAM_LOG_IMPL(::viam::sdk::LogManager::get().global_logger(), level)
147148

148149
/// @brief Log macro for resource-level logs.
149150
/// @ingroup Log

src/viam/sdk/module/service.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ ModuleService::ModuleService(int argc,
237237
}
238238
return argv[1];
239239
}()) {
240-
Logger::get().set_global_log_level(argc, argv);
240+
LogManager::get().set_global_log_level(argc, argv);
241241

242242
for (auto&& mr : registrations) {
243243
Registry::get().register_model(mr);

src/viam/sdk/resource/resource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Name Resource::get_resource_name() const {
3030
}
3131

3232
void Resource::set_log_level(log_level ll) const {
33-
Logger::get().set_resource_log_level(name_, ll);
33+
LogManager::get().set_resource_log_level(name_, ll);
3434
}
3535

3636
} // namespace sdk

src/viam/sdk/robot/client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ void RobotClient::connect_logging() {
101101
auto& sink = impl_->log_sink;
102102
if (!sink) {
103103
sink = sdk::impl::LogBackend::create(this);
104-
sink->set_filter(Logger::Filter{&Logger::get()});
104+
sink->set_filter(LogManager::Filter{&LogManager::get()});
105105

106-
Logger::get().disable_console_logging();
106+
LogManager::get().disable_console_logging();
107107
boost::log::core::get()->add_sink(sink);
108108
}
109109
}

src/viam/sdk/tests/test_log.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE(test_global_filter) {
3636
VIAM_LOG(error) << "error1";
3737
VIAM_LOG(trace) << "trace1"; // not logged
3838

39-
auto& logger = sdk::Logger::get();
39+
auto& logger = sdk::LogManager::get();
4040

4141
using ll = sdk::log_level;
4242

0 commit comments

Comments
 (0)