clang-format

This commit is contained in:
gabime 2019-03-23 16:39:32 +02:00
parent c29b7d22d9
commit 1d72edcc4f
8 changed files with 183 additions and 191 deletions

View File

@ -128,7 +128,10 @@ enum level_enum
static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES;
#if !defined(SPDLOG_SHORT_LEVEL_NAMES) #if !defined(SPDLOG_SHORT_LEVEL_NAMES)
#define SPDLOG_SHORT_LEVEL_NAMES {"T", "D", "I", "W", "E", "C", "O"} #define SPDLOG_SHORT_LEVEL_NAMES \
{ \
"T", "D", "I", "W", "E", "C", "O" \
}
#endif #endif
static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES;

View File

@ -18,8 +18,10 @@
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {
inline int syslog_level(level::level_enum l) { inline int syslog_level(level::level_enum l)
switch(l) { {
switch (l)
{
case level::off: case level::off:
case level::trace: case level::trace:
case level::debug: case level::debug:
@ -57,13 +59,7 @@ public:
protected: protected:
void sink_it_(const details::log_msg &msg) override void sink_it_(const details::log_msg &msg) override
{ {
if( sd_journal_print( if (sd_journal_print(syslog_level(msg.level), "%.*s", static_cast<int>(msg.payload.size()), msg.payload.data()))
syslog_level(msg.level),
"%.*s",
static_cast<int>(msg.payload.size()),
msg.payload.data()
)
)
throw spdlog_ex("Failed writing to systemd"); throw spdlog_ex("Failed writing to systemd");
} }
@ -76,15 +72,13 @@ using systemd_sink_st = systemd_sink<details::null_mutex>;
// Create and register a syslog logger // Create and register a syslog logger
template<typename Factory = default_factory> template<typename Factory = default_factory>
inline std::shared_ptr<logger> systemd_logger_mt( inline std::shared_ptr<logger> systemd_logger_mt(const std::string &logger_name)
const std::string &logger_name)
{ {
return Factory::template create<sinks::systemd_sink_mt>(logger_name); return Factory::template create<sinks::systemd_sink_mt>(logger_name);
} }
template<typename Factory = default_factory> template<typename Factory = default_factory>
inline std::shared_ptr<logger> systemd_logger_st( inline std::shared_ptr<logger> systemd_logger_st(const std::string &logger_name)
const std::string &logger_name)
{ {
return Factory::template create<sinks::systemd_sink_st>(logger_name); return Factory::template create<sinks::systemd_sink_st>(logger_name);
} }

View File

@ -1,15 +1,13 @@
#include "logger.h" #include "logger.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
spdlog::lite::logger spdlog::create_lite(void *ctx) spdlog::lite::logger spdlog::create_lite(void *ctx)
{ {
if(ctx) { if (ctx)
{
//.. //..
} }
auto logger_impl = spdlog::default_logger(); auto logger_impl = spdlog::default_logger();
logger_impl->set_level(spdlog::level::trace); logger_impl->set_level(spdlog::level::trace);
return spdlog::lite::logger(logger_impl); return spdlog::lite::logger(logger_impl);
} }

View File

@ -7,5 +7,4 @@ int main()
// spdlog::lite::info("HELLO info {}", 123); // spdlog::lite::info("HELLO info {}", 123);
SPDLITE_TRACE("SOME MACRO {}", 123); SPDLITE_TRACE("SOME MACRO {}", 123);
SPDLITE_INFO("SOME MACRO {}", "HHHHH"); SPDLITE_INFO("SOME MACRO {}", "HHHHH");
} }

View File

@ -29,7 +29,6 @@ void spdlog::lite::logger::log_formatted_(spdlog::lite::level level, const fmt::
impl_->log(spd_level, spdlog::details::fmt_helper::to_string_view(formatted)); impl_->log(spd_level, spdlog::details::fmt_helper::to_string_view(formatted));
} }
void spdlog::lite::logger::log_formatted_src(const spdlog::lite::src_loc &src, spdlog::lite::level lvl, const fmt::memory_buffer &formatted) void spdlog::lite::logger::log_formatted_src(const spdlog::lite::src_loc &src, spdlog::lite::level lvl, const fmt::memory_buffer &formatted)
{ {
auto spd_level = to_spdlog_level(lvl); auto spd_level = to_spdlog_level(lvl);
@ -75,7 +74,6 @@ void spdlog::lite::logger::set_pattern(std::string pattern)
impl_->set_pattern(std::move(pattern)); impl_->set_pattern(std::move(pattern));
} }
spdlog::lite::logger &spdlog::lite::default_logger() spdlog::lite::logger &spdlog::lite::default_logger()
{ {
static spdlog::lite::logger s_default(spdlog::default_logger()); static spdlog::lite::logger s_default(spdlog::default_logger());

View File

@ -73,13 +73,12 @@
#define SPDLITE_CRITICAL(...) (void)0 #define SPDLITE_CRITICAL(...) (void)0
#endif #endif
namespace spdlog { namespace spdlog {
class logger; class logger;
namespace lite { namespace lite {
enum class level{ enum class level
{
trace = SPDLITE_LEVEL_TRACE, trace = SPDLITE_LEVEL_TRACE,
debug = SPDLITE_LEVEL_DEBUG, debug = SPDLITE_LEVEL_DEBUG,
info = SPDLITE_LEVEL_INFO, info = SPDLITE_LEVEL_INFO,
@ -89,13 +88,15 @@ namespace spdlog {
off = SPDLITE_LEVEL_OFF off = SPDLITE_LEVEL_OFF
}; };
struct src_loc { struct src_loc
{
const char *filename; const char *filename;
int line; int line;
const char *funcname; const char *funcname;
}; };
class logger { class logger
{
public: public:
logger() = default; logger() = default;
@ -109,8 +110,10 @@ namespace spdlog {
bool should_log(spdlog::lite::level lvl) const noexcept; bool should_log(spdlog::lite::level lvl) const noexcept;
template<typename... Args> template<typename... Args>
void log(spdlog::lite::level lvl, const char *fmt, const Args &... args) { void log(spdlog::lite::level lvl, const char *fmt, const Args &... args)
if (!should_log(lvl)) { {
if (!should_log(lvl))
{
return; return;
} }
fmt::memory_buffer formatted_buf; fmt::memory_buffer formatted_buf;
@ -118,10 +121,11 @@ namespace spdlog {
log_formatted_(lvl, formatted_buf); log_formatted_(lvl, formatted_buf);
} }
template<typename... Args> template<typename... Args>
void log(const spdlog::lite::src_loc& src, spdlog::lite::level lvl, const char *fmt, const Args &... args) { void log(const spdlog::lite::src_loc &src, spdlog::lite::level lvl, const char *fmt, const Args &... args)
if (!should_log(lvl)) { {
if (!should_log(lvl))
{
return; return;
} }
fmt::memory_buffer formatted_buf; fmt::memory_buffer formatted_buf;
@ -129,7 +133,6 @@ namespace spdlog {
log_formatted_src(src, lvl, formatted_buf); log_formatted_src(src, lvl, formatted_buf);
} }
template<typename... Args> template<typename... Args>
void trace(const char *fmt, const Args &... args) void trace(const char *fmt, const Args &... args)
{ {
@ -191,11 +194,9 @@ namespace spdlog {
std::shared_ptr<spdlog::logger> impl_; std::shared_ptr<spdlog::logger> impl_;
void log_formatted_(spdlog::lite::level lvl, const fmt::memory_buffer &formatted); void log_formatted_(spdlog::lite::level lvl, const fmt::memory_buffer &formatted);
void log_formatted_src(const spdlog::lite::src_loc &src, spdlog::lite::level lvl, const fmt::memory_buffer &formatted); void log_formatted_src(const spdlog::lite::src_loc &src, spdlog::lite::level lvl, const fmt::memory_buffer &formatted);
}; };
spdlog::lite::logger &default_logger(); spdlog::lite::logger &default_logger();
template<typename... Args> template<typename... Args>
void trace(const char *fmt, const Args &... args) void trace(const char *fmt, const Args &... args)
{ {
@ -231,7 +232,6 @@ namespace spdlog {
default_logger().critical(fmt, args...); default_logger().critical(fmt, args...);
} }
} // namespace lite } // namespace lite
// factory to create lite logger // factory to create lite logger