Skip to content

Commit 5dd0be9

Browse files
committed
feat(logger): Add move constructor/assignment operator
1 parent 6972195 commit 5dd0be9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

components/logger/include/logger.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,39 @@ rate limit. @note Only calls that have _rate_limited suffixed will be rate limit
140140
, include_time_(other.include_time_.load())
141141
, level_(other.level_.load()) {}
142142

143+
/**
144+
* @brief Copy assignment operator
145+
* @param other The other logger to copy from.
146+
* @return Reference to this logger.
147+
*/
148+
Logger &operator=(const Logger &other) {
149+
if (this != &other) {
150+
std::scoped_lock lock(tag_mutex_, other.tag_mutex_);
151+
tag_ = other.tag_;
152+
rate_limit_ = other.rate_limit_;
153+
include_time_ = other.include_time_.load();
154+
level_ = other.level_.load();
155+
}
156+
return *this;
157+
}
158+
159+
/**
160+
* @brief Move assignment operator
161+
* @param other The other logger to move from.
162+
* @return Reference to this logger.
163+
*/
164+
Logger &operator=(Logger &&other) noexcept {
165+
if (this != &other) {
166+
std::scoped_lock lock(tag_mutex_, other.tag_mutex_);
167+
tag_ = std::move(other.tag_);
168+
rate_limit_ = std::move(other.rate_limit_);
169+
last_print_ = std::move(other.last_print_);
170+
include_time_ = other.include_time_.load();
171+
level_ = other.level_.load();
172+
}
173+
return *this;
174+
}
175+
143176
/**
144177
* @brief Get the current verbosity for the logger.
145178
* @return The current verbosity level.

0 commit comments

Comments
 (0)