Skip to content

Commit 9a0ab7b

Browse files
Merge branch 'gabime:v1.x' into v1.x
2 parents 0343542 + 472945b commit 9a0ab7b

16 files changed

Lines changed: 41 additions & 43 deletions

example/example.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,24 +267,24 @@ void multi_sink_example() {
267267

268268
// User defined types logging
269269
struct my_type {
270-
int i = 0;
271-
explicit my_type(int i)
272-
: i(i) {}
270+
int value_ = 0;
271+
explicit my_type(int value)
272+
: value_(value) {}
273273
};
274274

275275
#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib
276276
template <>
277277
struct fmt::formatter<my_type> : fmt::formatter<std::string> {
278278
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
279-
return fmt::format_to(ctx.out(), "[my_type i={}]", my.i);
279+
return fmt::format_to(ctx.out(), "[my_type value={}]", my.value_);
280280
}
281281
};
282282

283283
#else // when using std::format
284284
template <>
285285
struct std::formatter<my_type> : std::formatter<std::string> {
286286
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
287-
return std::format_to(ctx.out(), "[my_type i={}]", my.i);
287+
return std::format_to(ctx.out(), "[my_type value={}]", my.value_);
288288
}
289289
};
290290
#endif

include/spdlog/async_logger-inl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ SPDLOG_LOGGER_CATCH(source_loc())
5757
//
5858
// backend functions - called from the thread pool to do the actual job
5959
//
60-
SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg) {
60+
SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &incoming_log_msg) {
6161
for (auto &sink : sinks_) {
62-
if (sink->should_log(msg.level)) {
63-
SPDLOG_TRY { sink->log(msg); }
64-
SPDLOG_LOGGER_CATCH(msg.source)
62+
if (sink->should_log(incoming_log_msg.level)) {
63+
SPDLOG_TRY { sink->log(incoming_log_msg); }
64+
SPDLOG_LOGGER_CATCH(incoming_log_msg.source)
6565
}
6666
}
6767

68-
if (should_flush_(msg)) {
68+
if (should_flush_(incoming_log_msg)) {
6969
backend_flush_();
7070
}
7171
}

include/spdlog/cfg/argv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ inline void load_argv_levels(int argc, const char **argv) {
2626
for (int i = 1; i < argc; i++) {
2727
std::string arg = argv[i];
2828
if (arg.find(spdlog_level_prefix) == 0) {
29-
auto levels_string = arg.substr(spdlog_level_prefix.size());
30-
helpers::load_levels(levels_string);
29+
const auto levels_spec = arg.substr(spdlog_level_prefix.size());
30+
helpers::load_levels(levels_spec);
3131
}
3232
}
3333
}

include/spdlog/cfg/env.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
namespace spdlog {
2727
namespace cfg {
2828
inline void load_env_levels(const char* var = "SPDLOG_LEVEL") {
29-
auto env_val = details::os::getenv(var);
30-
if (!env_val.empty()) {
31-
helpers::load_levels(env_val);
29+
const auto levels_spec = details::os::getenv(var);
30+
if (!levels_spec.empty()) {
31+
helpers::load_levels(levels_spec);
3232
}
3333
}
3434

include/spdlog/cfg/helpers-inl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ inline std::unordered_map<std::string, std::string> extract_key_vals_(const std:
7070
return rv;
7171
}
7272

73-
SPDLOG_INLINE void load_levels(const std::string &input) {
74-
if (input.empty() || input.size() >= 32768) {
73+
SPDLOG_INLINE void load_levels(const std::string &levels_spec) {
74+
if (levels_spec.empty() || levels_spec.size() >= 32768) {
7575
return;
7676
}
7777

78-
auto key_vals = extract_key_vals_(input);
78+
auto key_vals = extract_key_vals_(levels_spec);
7979
std::unordered_map<std::string, level::level_enum> levels;
8080
level::level_enum global_level = level::info;
8181
bool global_level_found = false;
8282

8383
for (auto &name_level : key_vals) {
8484
const auto &logger_name = name_level.first;
8585
const auto &level_name = to_lower_(name_level.second);
86-
auto level = level::from_str(level_name);
86+
const auto level = level::from_str(level_name);
8787
// ignore unrecognized level names
8888
if (level == level::off && level_name != "off") {
8989
continue;

include/spdlog/cfg/helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace helpers {
1818
// turn off all logging except for logger1: "off,logger1=debug"
1919
// turn off all logging except for logger1 and logger2: "off,logger1=debug,logger2=info"
2020
//
21-
SPDLOG_API void load_levels(const std::string &txt);
21+
SPDLOG_API void load_levels(const std::string &levels_spec);
2222
} // namespace helpers
2323

2424
} // namespace cfg

include/spdlog/details/null_mutex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct null_mutex {
1515
};
1616

1717
struct null_atomic_int {
18-
int value;
18+
int value{0};
1919
null_atomic_int() = default;
2020

2121
explicit null_atomic_int(int new_value)

include/spdlog/details/registry-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name) {
257257
}
258258

259259
SPDLOG_INLINE void registry::register_logger_(std::shared_ptr<logger> new_logger) {
260-
auto &logger_name = new_logger->name();
260+
const auto &logger_name = new_logger->name();
261261
throw_if_exists_(logger_name);
262262
loggers_[logger_name] = std::move(new_logger);
263263
}

include/spdlog/logger-inl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ SPDLOG_INLINE void logger::dump_backtrace_() {
164164
}
165165

166166
SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg) const {
167-
auto flush_level = flush_level_.load(std::memory_order_relaxed);
168-
return (msg.level >= flush_level) && (msg.level != level::off);
167+
return (msg.level >= flush_level()) && (msg.level != level::off);
169168
}
170169

171170
SPDLOG_INLINE void logger::err_handler_(const std::string &msg) const {

include/spdlog/pattern_formatter-inl.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ class mdc_formatter : public flag_formatter {
813813
: flag_formatter(padinfo) {}
814814

815815
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override {
816-
auto &mdc_map = mdc::get_context();
816+
const auto &mdc_map = mdc::get_context();
817817
if (mdc_map.empty()) {
818818
ScopedPadder p(0, padinfo_, dest);
819819
return;
@@ -823,11 +823,10 @@ class mdc_formatter : public flag_formatter {
823823
}
824824

825825
void format_mdc(const mdc::mdc_map_t &mdc_map, memory_buf_t &dest) {
826-
auto last_element = --mdc_map.end();
826+
const auto last_element = std::prev(mdc_map.end());
827827
for (auto it = mdc_map.begin(); it != mdc_map.end(); ++it) {
828-
auto &pair = *it;
829-
const auto &key = pair.first;
830-
const auto &value = pair.second;
828+
const auto &key = it->first;
829+
const auto &value = it->second;
831830
size_t content_size = key.size() + value.size() + 1; // 1 for ':'
832831

833832
if (it != last_element) {
@@ -1012,7 +1011,7 @@ SPDLOG_INLINE void pattern_formatter::set_pattern(std::string pattern) {
10121011

10131012
SPDLOG_INLINE void pattern_formatter::need_localtime(bool need) { need_localtime_ = need; }
10141013

1015-
SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg) {
1014+
SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg) const {
10161015
if (pattern_time_type_ == pattern_time_type::local) {
10171016
return details::os::localtime(log_clock::to_time_t(msg.time));
10181017
}

0 commit comments

Comments
 (0)