clang-format

This commit is contained in:
gabime 2019-04-27 02:34:50 +03:00
parent c1c2ff2d07
commit 2de924a187
17 changed files with 694 additions and 715 deletions

View File

@ -19,7 +19,6 @@
// Upon destruction, logs all remaining messages in the queue before
// destructing..
#include "spdlog/logger.h"
namespace spdlog {
@ -69,5 +68,3 @@ private:
#ifdef SPDLOG_HEADER_ONLY
#include "spdlog/impl/async_logger.cpp"
#endif // SPDLOG_HEADER_ONLY

View File

@ -70,7 +70,6 @@
#define SPDLOG_FUNCTION __FUNCTION__
#endif
namespace spdlog {
class formatter;

View File

@ -20,7 +20,6 @@
namespace spdlog {
namespace details {
// padding information.
struct padding_info
{
@ -61,20 +60,16 @@ protected:
padding_info padinfo_;
};
}
} // namespace details
class pattern_formatter final : public formatter
{
public:
explicit pattern_formatter(
std::string pattern,
pattern_time_type time_type = pattern_time_type::local,
std::string eol = spdlog::details::os::default_eol);
std::string pattern, pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol);
// use default pattern is not given
explicit pattern_formatter(
pattern_time_type time_type = pattern_time_type::local,
std::string eol = spdlog::details::os::default_eol);
explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol);
pattern_formatter(const pattern_formatter &other) = delete;
pattern_formatter &operator=(const pattern_formatter &other) = delete;

View File

@ -2,7 +2,6 @@
#include "spdlog/async_logger.h"
#endif
// async logger implementation
// uses a thread pool to perform the actual logging
@ -118,6 +117,3 @@ SPDLOG_INLINE std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::s
cloned->set_error_handler(this->custom_err_handler_);
return std::move(cloned);
}

View File

@ -17,15 +17,14 @@
#include <tuple>
namespace spdlog {
namespace details
namespace details {
SPDLOG_INLINE file_helper::~file_helper()
{
SPDLOG_INLINE file_helper::~file_helper()
{
close();
}
}
SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
{
SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
{
close();
auto *mode = truncate ? SPDLOG_FILENAME_T("wb") : SPDLOG_FILENAME_T("ab");
_filename = fname;
@ -40,75 +39,75 @@ namespace details
}
throw spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno);
}
}
SPDLOG_INLINE void file_helper::reopen(bool truncate)
{
SPDLOG_INLINE void file_helper::reopen(bool truncate)
{
if (_filename.empty())
{
throw spdlog_ex("Failed re opening file - was not opened before");
}
open(_filename, truncate);
}
}
SPDLOG_INLINE void file_helper::flush()
{
SPDLOG_INLINE void file_helper::flush()
{
std::fflush(fd_);
}
}
SPDLOG_INLINE void file_helper::close()
{
SPDLOG_INLINE void file_helper::close()
{
if (fd_ != nullptr)
{
std::fclose(fd_);
fd_ = nullptr;
}
}
}
SPDLOG_INLINE void file_helper::write(const fmt::memory_buffer &buf)
{
SPDLOG_INLINE void file_helper::write(const fmt::memory_buffer &buf)
{
size_t msg_size = buf.size();
auto data = buf.data();
if (std::fwrite(data, 1, msg_size, fd_) != msg_size)
{
throw spdlog_ex("Failed writing to file " + os::filename_to_str(_filename), errno);
}
}
}
SPDLOG_INLINE size_t file_helper::size() const
{
SPDLOG_INLINE size_t file_helper::size() const
{
if (fd_ == nullptr)
{
throw spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename));
}
return os::filesize(fd_);
}
}
SPDLOG_INLINE const filename_t &file_helper::filename() const
{
SPDLOG_INLINE const filename_t &file_helper::filename() const
{
return _filename;
}
}
SPDLOG_INLINE bool file_helper::file_exists(const filename_t &fname)
{
SPDLOG_INLINE bool file_helper::file_exists(const filename_t &fname)
{
return os::file_exists(fname);
}
}
//
// return file path and its extension:
//
// "mylog.txt" => ("mylog", ".txt")
// "mylog" => ("mylog", "")
// "mylog." => ("mylog.", "")
// "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt")
//
// the starting dot in filenames is ignored (hidden files):
//
// ".mylog" => (".mylog". "")
// "my_folder/.mylog" => ("my_folder/.mylog", "")
// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
SPDLOG_INLINE std::tuple<filename_t, filename_t> file_helper::split_by_extension(const filename_t &fname)
{
//
// return file path and its extension:
//
// "mylog.txt" => ("mylog", ".txt")
// "mylog" => ("mylog", "")
// "mylog." => ("mylog.", "")
// "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt")
//
// the starting dot in filenames is ignored (hidden files):
//
// ".mylog" => (".mylog". "")
// "my_folder/.mylog" => ("my_folder/.mylog", "")
// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
SPDLOG_INLINE std::tuple<filename_t, filename_t> file_helper::split_by_extension(const filename_t &fname)
{
auto ext_index = fname.rfind('.');
// no valid extension found - return whole path and empty string as
@ -127,6 +126,6 @@ namespace details
// finally - return a valid base and extension tuple
return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index));
}
}
} // namespace details
} // namespace spdlog

View File

@ -5,8 +5,6 @@
#include "spdlog/details/log_msg.h"
#endif
SPDLOG_INLINE spdlog::details::log_msg::log_msg(
spdlog::source_loc loc, const std::string *loggers_name, spdlog::level::level_enum lvl, spdlog::string_view_t view)
: logger_name(loggers_name)

View File

@ -959,37 +959,34 @@ private:
} // namespace details
SPDLOG_INLINE pattern_formatter::pattern_formatter(
std::string pattern, pattern_time_type time_type, std::string eol)
SPDLOG_INLINE pattern_formatter::pattern_formatter(std::string pattern, pattern_time_type time_type, std::string eol)
: pattern_(std::move(pattern))
, eol_(std::move(eol))
, pattern_time_type_(time_type)
, last_log_secs_(0)
{
{
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
compile_pattern_(pattern_);
}
}
// use by default full formatter for if pattern is not given
SPDLOG_INLINE pattern_formatter::pattern_formatter(pattern_time_type time_type, std::string eol)
// use by default full formatter for if pattern is not given
SPDLOG_INLINE pattern_formatter::pattern_formatter(pattern_time_type time_type, std::string eol)
: pattern_("%+")
, eol_(std::move(eol))
, pattern_time_type_(time_type)
, last_log_secs_(0)
{
{
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
formatters_.push_back(details::make_unique<details::full_formatter>(details::padding_info{}));
}
}
SPDLOG_INLINE std::unique_ptr<formatter> pattern_formatter::clone() const
{
SPDLOG_INLINE std::unique_ptr<formatter> pattern_formatter::clone() const
{
return details::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_);
}
}
SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, fmt::memory_buffer &dest)
{
SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, fmt::memory_buffer &dest)
{
#ifndef SPDLOG_NO_DATETIME
auto secs = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch());
if (secs != last_log_secs_)
@ -1004,19 +1001,19 @@ private:
}
// write eol
details::fmt_helper::append_string_view(eol_, dest);
}
}
SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg)
{
SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg)
{
if (pattern_time_type_ == pattern_time_type::local)
{
return details::os::localtime(log_clock::to_time_t(msg.time));
}
return details::os::gmtime(log_clock::to_time_t(msg.time));
}
}
SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_info padding)
{
SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_info padding)
{
switch (flag)
{
@ -1178,13 +1175,13 @@ private:
formatters_.push_back((std::move(unknown_flag)));
break;
}
}
}
// Extract given pad spec (e.g. %8X)
// Advance the given it pass the end of the padding spec found (if any)
// Return padding.
SPDLOG_INLINE details::padding_info pattern_formatter::handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end)
{
// Extract given pad spec (e.g. %8X)
// Advance the given it pass the end of the padding spec found (if any)
// Return padding.
SPDLOG_INLINE details::padding_info pattern_formatter::handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end)
{
using details::padding_info;
using details::scoped_pad;
const size_t max_width = 128;
@ -1221,10 +1218,10 @@ private:
width = width * 10 + digit;
}
return details::padding_info{std::min<size_t>(width, max_width), side};
}
}
SPDLOG_INLINE void pattern_formatter::compile_pattern_(const std::string &pattern)
{
SPDLOG_INLINE void pattern_formatter::compile_pattern_(const std::string &pattern)
{
auto end = pattern.end();
std::unique_ptr<details::aggregate_formatter> user_chars;
formatters_.clear();
@ -1261,6 +1258,5 @@ private:
{
formatters_.push_back(std::move(user_chars));
}
}
}
} // namespace spdlog

View File

@ -6,7 +6,6 @@
#include "spdlog/details/registry.h"
#endif
#include "spdlog/common.h"
#include "spdlog/details/periodic_worker.h"
#include "spdlog/logger.h"

View File

@ -7,11 +7,13 @@
SPDLOG_INLINE spdlog::sinks::sink::sink()
: formatter_{details::make_unique<spdlog::pattern_formatter>()}
{}
{
}
SPDLOG_INLINE spdlog::sinks::sink::sink(std::unique_ptr<spdlog::formatter> formatter)
: formatter_{std::move(formatter)}
{}
{
}
SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const
{

View File

@ -124,7 +124,6 @@ public:
log(level::critical, fmt, args...);
}
template<typename T>
void log(level::level_enum lvl, const T &msg)
{
@ -323,7 +322,7 @@ public:
// create new logger with same sinks and configuration.
virtual std::shared_ptr<logger> clone(std::string logger_name);
protected:
protected:
virtual void sink_it_(details::log_msg &msg);
virtual void flush_();
@ -338,8 +337,6 @@ public:
spdlog::level_t level_{spdlog::logger::default_level()};
spdlog::level_t flush_level_{level::off};
err_handler custom_err_handler_{nullptr};
};
} // namespace spdlog

View File

@ -328,7 +328,8 @@ inline void critical(const wchar_t *fmt, const Args &... args)
//
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
do { \
do \
{ \
if (logger->should_log(level)) \
logger->log(spdlog::source_loc{SPDLOG_FILE_BASENAME(__FILE__), __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__); \
} while (0)