mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-13 17:22:06 +08:00
clang format
This commit is contained in:
parent
1faeb5b6fa
commit
90e92438c8
@ -27,7 +27,7 @@ void custom_flags_example();
|
|||||||
void file_events_example();
|
void file_events_example();
|
||||||
void replace_default_logger_example();
|
void replace_default_logger_example();
|
||||||
|
|
||||||
#define SPDLOG_EMIT_SOURCE_LOCATION // define if you want to log the source file/line/function name.
|
//#define SPDLOG_EMIT_SOURCE_LOCATION // define if you want to log the source file/line/function name.
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
#include "spdlog/cfg/env.h" // support for loading levels from the environment variable
|
#include "spdlog/cfg/env.h" // support for loading levels from the environment variable
|
||||||
|
|
||||||
@ -37,7 +37,6 @@ int main(int, char *[])
|
|||||||
load_levels_example();
|
load_levels_example();
|
||||||
|
|
||||||
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
|
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
|
||||||
|
|
||||||
spdlog::warn("Easy padding in numbers like {:08d}", 12);
|
spdlog::warn("Easy padding in numbers like {:08d}", 12);
|
||||||
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||||
spdlog::info("Support for floats {:03.2f}", 1.23456);
|
spdlog::info("Support for floats {:03.2f}", 1.23456);
|
||||||
|
@ -18,14 +18,13 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <version>
|
#include <version>
|
||||||
|
|
||||||
# if __cpp_lib_source_location >= 201907
|
#if __cpp_lib_source_location >= 201907
|
||||||
# include <source_location>
|
# include <source_location>
|
||||||
# define SPDLOG_STD_SOURCE_LOCATION
|
# define SPDLOG_STD_SOURCE_LOCATION
|
||||||
# elif __has_include(<experimental/source_location>)
|
#elif __has_include(<experimental/source_location>)
|
||||||
# include <experimental/source_location>
|
# include <experimental/source_location>
|
||||||
# define SPDLOG_EXPERIMENTAL_SOURCE_LOCATION
|
# define SPDLOG_EXPERIMENTAL_SOURCE_LOCATION
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef SPDLOG_USE_STD_FORMAT
|
#ifdef SPDLOG_USE_STD_FORMAT
|
||||||
# if __cpp_lib_format >= 202207L
|
# if __cpp_lib_format >= 202207L
|
||||||
@ -67,7 +66,6 @@
|
|||||||
# define SPDLOG_FMT_STRING(format_string) format_string
|
# define SPDLOG_FMT_STRING(format_string) format_string
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef SPDLOG_FUNCTION
|
#ifndef SPDLOG_FUNCTION
|
||||||
# define SPDLOG_FUNCTION static_cast<const char *>(__FUNCTION__)
|
# define SPDLOG_FUNCTION static_cast<const char *>(__FUNCTION__)
|
||||||
#endif
|
#endif
|
||||||
@ -124,7 +122,6 @@ using format_string_t = std::format_string<Args...>;
|
|||||||
using format_string_t = std::string_view;
|
using format_string_t = std::string_view;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
|
||||||
# define SPDLOG_BUF_TO_STRING(x) x
|
# define SPDLOG_BUF_TO_STRING(x) x
|
||||||
#else // use fmt lib instead of std::format
|
#else // use fmt lib instead of std::format
|
||||||
namespace fmt_lib = fmt;
|
namespace fmt_lib = fmt;
|
||||||
@ -164,7 +161,7 @@ using level_t = std::atomic<int>;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Is convertable to string_view_t ?
|
// Is convertable to string_view_t ?
|
||||||
template <typename T>
|
template<typename T>
|
||||||
using is_convertible_to_sv = std::enable_if_t<std::is_convertible_v<T, string_view_t>>;
|
using is_convertible_to_sv = std::enable_if_t<std::is_convertible_v<T, string_view_t>>;
|
||||||
|
|
||||||
// Log level enum
|
// Log level enum
|
||||||
@ -248,7 +245,6 @@ private:
|
|||||||
[[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno);
|
[[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno);
|
||||||
[[noreturn]] SPDLOG_API void throw_spdlog_ex(std::string msg);
|
[[noreturn]] SPDLOG_API void throw_spdlog_ex(std::string msg);
|
||||||
|
|
||||||
|
|
||||||
struct source_loc
|
struct source_loc
|
||||||
{
|
{
|
||||||
constexpr source_loc() = default;
|
constexpr source_loc() = default;
|
||||||
@ -264,7 +260,8 @@ struct source_loc
|
|||||||
return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()};
|
return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()};
|
||||||
}
|
}
|
||||||
#elif defined(SPDLOG_EXPERIMENTAL_SOURCE_LOCATION)
|
#elif defined(SPDLOG_EXPERIMENTAL_SOURCE_LOCATION)
|
||||||
static constexpr source_loc current(const std::experimental::source_location source_location = std::experimental::source_location::current())
|
static constexpr source_loc current(
|
||||||
|
const std::experimental::source_location source_location = std::experimental::source_location::current())
|
||||||
{
|
{
|
||||||
return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()};
|
return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()};
|
||||||
}
|
}
|
||||||
@ -290,8 +287,10 @@ struct loc_with_fmt
|
|||||||
source_loc loc;
|
source_loc loc;
|
||||||
string_view_t fmt_string;
|
string_view_t fmt_string;
|
||||||
template<typename S, typename = is_convertible_to_sv<S>>
|
template<typename S, typename = is_convertible_to_sv<S>>
|
||||||
constexpr loc_with_fmt(S fmt_str, source_loc loc = source_loc::current()) noexcept:
|
constexpr loc_with_fmt(S fmt_str, source_loc loc = source_loc::current()) noexcept
|
||||||
loc(loc), fmt_string(fmt_str) {}
|
: loc(loc)
|
||||||
|
, fmt_string(fmt_str)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct file_event_handlers
|
struct file_event_handlers
|
||||||
@ -349,7 +348,6 @@ constexpr std::basic_string_view<T> to_string_view(std::basic_format_string<T, A
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public:
|
|||||||
// Pop item from front if not empty.
|
// Pop item from front if not empty.
|
||||||
void pop_front()
|
void pop_front()
|
||||||
{
|
{
|
||||||
if(!empty())
|
if (!empty())
|
||||||
{
|
{
|
||||||
head_ = (head_ + 1) % max_items_;
|
head_ = (head_ + 1) % max_items_;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,9 @@ SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
|
|||||||
update_string_views();
|
update_string_views();
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) noexcept : log_msg{other}, buffer{std::move(other.buffer)}
|
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) noexcept
|
||||||
|
: log_msg{other}
|
||||||
|
, buffer{std::move(other.buffer)}
|
||||||
{
|
{
|
||||||
update_string_views();
|
update_string_views();
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,12 @@ SPDLOG_INLINE logger::logger(const logger &other) noexcept
|
|||||||
, custom_err_handler_(other.custom_err_handler_)
|
, custom_err_handler_(other.custom_err_handler_)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
SPDLOG_INLINE logger::logger(logger &&other) noexcept : name_(std::move(other.name_)),
|
SPDLOG_INLINE logger::logger(logger &&other) noexcept
|
||||||
sinks_(std::move(other.sinks_)),
|
: name_(std::move(other.name_))
|
||||||
level_(other.level_.load(std::memory_order_relaxed)),
|
, sinks_(std::move(other.sinks_))
|
||||||
flush_level_(other.flush_level_.load(std::memory_order_relaxed)),
|
, level_(other.level_.load(std::memory_order_relaxed))
|
||||||
custom_err_handler_(std::move(other.custom_err_handler_))
|
, flush_level_(other.flush_level_.load(std::memory_order_relaxed))
|
||||||
|
, custom_err_handler_(std::move(other.custom_err_handler_))
|
||||||
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -93,9 +93,7 @@ public:
|
|||||||
log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
|
log(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename S,
|
template<typename S, typename = is_convertible_to_sv<S>, typename... Args>
|
||||||
typename = is_convertible_to_sv<S>,
|
|
||||||
typename... Args>
|
|
||||||
void log(source_loc loc, level::level_enum lvl, S fmt, Args &&...args)
|
void log(source_loc loc, level::level_enum lvl, S fmt, Args &&...args)
|
||||||
{
|
{
|
||||||
if (should_log(lvl))
|
if (should_log(lvl))
|
||||||
@ -105,8 +103,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// log with no format string, just string message
|
// log with no format string, just string message
|
||||||
template<typename S,
|
template<typename S, typename = is_convertible_to_sv<S>>
|
||||||
typename = is_convertible_to_sv<S>>
|
|
||||||
void log(source_loc loc, level::level_enum lvl, S msg)
|
void log(source_loc loc, level::level_enum lvl, S msg)
|
||||||
{
|
{
|
||||||
if (should_log(lvl))
|
if (should_log(lvl))
|
||||||
@ -282,7 +279,6 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// return true logging is enabled for the given level.
|
// return true logging is enabled for the given level.
|
||||||
[[nodiscard]] bool should_log(level::level_enum msg_level) const
|
[[nodiscard]] bool should_log(level::level_enum msg_level) const
|
||||||
{
|
{
|
||||||
@ -352,7 +348,7 @@ protected:
|
|||||||
// log the given message (if the given log level is high enough)
|
// log the given message (if the given log level is high enough)
|
||||||
virtual void sink_it_(const details::log_msg &msg)
|
virtual void sink_it_(const details::log_msg &msg)
|
||||||
{
|
{
|
||||||
assert (should_log(msg.level));
|
assert(should_log(msg.level));
|
||||||
for (auto &sink : sinks_)
|
for (auto &sink : sinks_)
|
||||||
{
|
{
|
||||||
if (sink->should_log(msg.level))
|
if (sink->should_log(msg.level))
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
: q_{n_items}
|
: q_{n_items}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void drain_raw(std::function<void(const details::log_msg_buffer&)> callback)
|
void drain_raw(std::function<void(const details::log_msg_buffer &)> callback)
|
||||||
{
|
{
|
||||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||||
while (!q_.empty())
|
while (!q_.empty())
|
||||||
@ -49,7 +49,7 @@ public:
|
|||||||
{
|
{
|
||||||
formatted.clear();
|
formatted.clear();
|
||||||
base_sink<Mutex>::formatter_->format(q_.front(), formatted);
|
base_sink<Mutex>::formatter_->format(q_.front(), formatted);
|
||||||
callback(std::string_view (formatted.data(), formatted.size()));
|
callback(std::string_view(formatted.data(), formatted.size()));
|
||||||
q_.pop_front();
|
q_.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,9 @@ struct local_alloc_t
|
|||||||
{
|
{
|
||||||
HLOCAL hlocal_;
|
HLOCAL hlocal_;
|
||||||
|
|
||||||
constexpr local_alloc_t() noexcept : hlocal_(nullptr) {}
|
constexpr local_alloc_t() noexcept
|
||||||
|
: hlocal_(nullptr)
|
||||||
|
{}
|
||||||
|
|
||||||
local_alloc_t(local_alloc_t const &) = delete;
|
local_alloc_t(local_alloc_t const &) = delete;
|
||||||
local_alloc_t &operator=(local_alloc_t const &) = delete;
|
local_alloc_t &operator=(local_alloc_t const &) = delete;
|
||||||
|
@ -122,8 +122,6 @@ SPDLOG_API spdlog::logger *default_logger_raw();
|
|||||||
|
|
||||||
SPDLOG_API void set_default_logger(std::shared_ptr<spdlog::logger> default_logger);
|
SPDLOG_API void set_default_logger(std::shared_ptr<spdlog::logger> default_logger);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Initialize logger level based on environment configs.
|
// Initialize logger level based on environment configs.
|
||||||
//
|
//
|
||||||
// Useful for applying SPDLOG_LEVEL to manually created loggers.
|
// Useful for applying SPDLOG_LEVEL to manually created loggers.
|
||||||
|
@ -45,8 +45,7 @@ set(SPDLOG_UTESTS_SOURCES
|
|||||||
test_time_point.cpp
|
test_time_point.cpp
|
||||||
test_stopwatch.cpp
|
test_stopwatch.cpp
|
||||||
test_circular_q.cpp
|
test_circular_q.cpp
|
||||||
test_ringbuffer_sink.cpp
|
test_ringbuffer_sink.cpp)
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT SPDLOG_NO_EXCEPTIONS)
|
if(NOT SPDLOG_NO_EXCEPTIONS)
|
||||||
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
||||||
|
@ -80,7 +80,6 @@ TEST_CASE("test_full", "[circular_q]")
|
|||||||
REQUIRE(q2.full());
|
REQUIRE(q2.full());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("test_operator[]", "[circular_q]")
|
TEST_CASE("test_operator[]", "[circular_q]")
|
||||||
{
|
{
|
||||||
q_type q(2);
|
q_type q(2);
|
||||||
@ -90,7 +89,6 @@ TEST_CASE("test_operator[]", "[circular_q]")
|
|||||||
REQUIRE(q[1] == 200);
|
REQUIRE(q[1] == 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("test_operator=", "[circular_q]")
|
TEST_CASE("test_operator=", "[circular_q]")
|
||||||
{
|
{
|
||||||
q_type q1(2);
|
q_type q1(2);
|
||||||
@ -114,7 +112,7 @@ TEST_CASE("test_overrun_counter", "[circular_q]")
|
|||||||
{
|
{
|
||||||
q_type q(2);
|
q_type q(2);
|
||||||
REQUIRE(q.overrun_counter() == 0);
|
REQUIRE(q.overrun_counter() == 0);
|
||||||
for(size_t i=0; i<10; i++)
|
for (size_t i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
q.push_back(100);
|
q.push_back(100);
|
||||||
}
|
}
|
||||||
@ -140,7 +138,3 @@ TEST_CASE("test_move", "[circular_q]")
|
|||||||
REQUIRE(q1.empty());
|
REQUIRE(q1.empty());
|
||||||
REQUIRE(q1.overrun_counter() == 0);
|
REQUIRE(q1.overrun_counter() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ TEST_CASE("basic_logging ", "[basic_logging]")
|
|||||||
// std::string
|
// std::string
|
||||||
REQUIRE(log_info(std::string("Hello")) == "Hello");
|
REQUIRE(log_info(std::string("Hello")) == "Hello");
|
||||||
REQUIRE(log_info(std::string()).empty());
|
REQUIRE(log_info(std::string()).empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("log_levels", "[log_levels]")
|
TEST_CASE("log_levels", "[log_levels]")
|
||||||
|
Loading…
Reference in New Issue
Block a user