clang-format

This commit is contained in:
gabime 2019-03-24 00:41:22 +02:00
parent 934cc892eb
commit bac1e4a850
4 changed files with 23 additions and 30 deletions

View File

@ -70,7 +70,7 @@ int main(int, char *[])
spdlog::shutdown(); spdlog::shutdown();
} }
// Exceptions will only be thrown upon failed logger or sink construction (not during logging). // Exceptions will only be thrown upon failed logger or sink construction (not during logging).
catch (const spdlog::spdlog_ex &ex) catch (const spdlog::spdlog_ex &ex)
{ {
std::printf("Log initialization failed: %s\n", ex.what()); std::printf("Log initialization failed: %s\n", ex.what());

View File

@ -5,7 +5,7 @@ int main()
auto l = spdlog::create_lite(); auto l = spdlog::create_lite();
l.set_level(spdlog::lite::level::trace); l.set_level(spdlog::lite::level::trace);
l.trace_f("Hello %s ","GABI"); l.trace_f("Hello %s ", "GABI");
l.info_f("Hello %d", 12346); l.info_f("Hello %d", 12346);
l.warn_f("Hello %f", 12346.5656); l.warn_f("Hello %f", 12346.5656);
l.warn("Hello {}", 12346.5656); l.warn("Hello {}", 12346.5656);

View File

@ -28,65 +28,63 @@ void spdlog::lite::logger::log(spdlog::lite::level lvl, const string_view_t &sv)
impl_->log(spd_level, sv); impl_->log(spd_level, sv);
} }
void spdlog::lite::logger::log_printf(spdlog::lite::level lvl, const char *format, va_list args)
void spdlog::lite::logger::log_printf(spdlog::lite::level lvl, const char* format, va_list args)
{ {
char buffer[500]; char buffer[500];
auto size = vsnprintf (buffer, sizeof(buffer),format, args); auto size = vsnprintf(buffer, sizeof(buffer), format, args);
if(size < 0) if (size < 0)
{ {
size = snprintf(buffer, sizeof(buffer), "invalid format (%s)", format); size = snprintf(buffer, sizeof(buffer), "invalid format (%s)", format);
} }
log(lvl, string_view_t{buffer, static_cast<size_t>(size)}); log(lvl, string_view_t{buffer, static_cast<size_t>(size)});
} }
void spdlog::lite::logger::trace_f(const char *format, ...) void spdlog::lite::logger::trace_f(const char *format, ...)
{ {
va_list args; va_list args;
va_start (args, format); va_start(args, format);
log_printf(lite::level::trace, format, args); log_printf(lite::level::trace, format, args);
va_end (args); va_end(args);
} }
void spdlog::lite::logger::debug_f(const char *format, ...) void spdlog::lite::logger::debug_f(const char *format, ...)
{ {
va_list args; va_list args;
va_start (args, format); va_start(args, format);
log_printf(lite::level::debug, format, args); log_printf(lite::level::debug, format, args);
va_end (args); va_end(args);
} }
void spdlog::lite::logger::info_f(const char *format, ...) void spdlog::lite::logger::info_f(const char *format, ...)
{ {
va_list args; va_list args;
va_start (args, format); va_start(args, format);
log_printf(lite::level::info, format, args); log_printf(lite::level::info, format, args);
va_end (args); va_end(args);
} }
void spdlog::lite::logger::warn_f(const char *format, ...) void spdlog::lite::logger::warn_f(const char *format, ...)
{ {
va_list args; va_list args;
va_start (args, format); va_start(args, format);
log_printf(lite::level::warn, format, args); log_printf(lite::level::warn, format, args);
va_end (args); va_end(args);
} }
void spdlog::lite::logger::error_f(const char *format, ...) void spdlog::lite::logger::error_f(const char *format, ...)
{ {
va_list args; va_list args;
va_start (args, format); va_start(args, format);
log_printf(lite::level::err, format, args); log_printf(lite::level::err, format, args);
va_end (args); va_end(args);
} }
void spdlog::lite::logger::critical_f(const char *format, ...) void spdlog::lite::logger::critical_f(const char *format, ...)
{ {
va_list args; va_list args;
va_start (args, format); va_start(args, format);
log_printf(lite::level::critical, format, args); log_printf(lite::level::critical, format, args);
va_end (args); va_end(args);
} }
void spdlog::lite::logger::set_level(spdlog::lite::level level) void spdlog::lite::logger::set_level(spdlog::lite::level level)
@ -138,5 +136,3 @@ 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());
return s_default; return s_default;
} }

View File

@ -31,7 +31,6 @@ enum class level
off off
}; };
class logger class logger
{ {
public: public:
@ -60,7 +59,7 @@ public:
// log string view // log string view
void log(spdlog::lite::level lvl, const string_view_t &sv); void log(spdlog::lite::level lvl, const string_view_t &sv);
void log_printf(spdlog::lite::level lvl, const char* format, va_list args); void log_printf(spdlog::lite::level lvl, const char *format, va_list args);
// //
// trace // trace
@ -76,7 +75,7 @@ public:
log(spdlog::lite::level::trace, fmt, args...); log(spdlog::lite::level::trace, fmt, args...);
} }
void trace_f(const char *printf_format, ...); void trace_f(const char *printf_format, ...);
// //
// debug // debug
@ -92,7 +91,7 @@ public:
log(spdlog::lite::level::debug, fmt, args...); log(spdlog::lite::level::debug, fmt, args...);
} }
void debug_f(const char *printf_format, ...); void debug_f(const char *printf_format, ...);
// //
// info // info
@ -124,7 +123,7 @@ public:
log(spdlog::lite::level::warn, fmt, args...); log(spdlog::lite::level::warn, fmt, args...);
} }
void warn_f(const char *printf_format, ...); void warn_f(const char *printf_format, ...);
// //
// error // error
@ -134,14 +133,13 @@ public:
log(spdlog::lite::level::err, string_view_t(msg)); log(spdlog::lite::level::err, string_view_t(msg));
} }
template<typename... Args> template<typename... Args>
void error(const char *fmt, const Args &... args) void error(const char *fmt, const Args &... args)
{ {
log(spdlog::lite::level::err, fmt, args...); log(spdlog::lite::level::err, fmt, args...);
} }
void error_f(const char *printf_format, ...); void error_f(const char *printf_format, ...);
// //
// critical // critical
@ -157,7 +155,7 @@ public:
log(spdlog::lite::level::critical, fmt, args...); log(spdlog::lite::level::critical, fmt, args...);
} }
void critical_f(const char *printf_format, ...); void critical_f(const char *printf_format, ...);
// //
// setters/getters // setters/getters
@ -177,7 +175,6 @@ public:
protected: protected:
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);
}; };
spdlog::lite::logger &default_logger(); spdlog::lite::logger &default_logger();