clang-format
This commit is contained in:
		
							parent
							
								
									c1c2ff2d07
								
							
						
					
					
						commit
						2de924a187
					
				| @ -19,7 +19,6 @@ | |||||||
| // Upon destruction, logs all remaining messages in the queue before
 | // Upon destruction, logs all remaining messages in the queue before
 | ||||||
| // destructing..
 | // destructing..
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| #include "spdlog/logger.h" | #include "spdlog/logger.h" | ||||||
| 
 | 
 | ||||||
| namespace spdlog { | namespace spdlog { | ||||||
| @ -69,5 +68,3 @@ private: | |||||||
| #ifdef SPDLOG_HEADER_ONLY | #ifdef SPDLOG_HEADER_ONLY | ||||||
| #include "spdlog/impl/async_logger.cpp" | #include "spdlog/impl/async_logger.cpp" | ||||||
| #endif // SPDLOG_HEADER_ONLY
 | #endif // SPDLOG_HEADER_ONLY
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -70,7 +70,6 @@ | |||||||
| #define SPDLOG_FUNCTION __FUNCTION__ | #define SPDLOG_FUNCTION __FUNCTION__ | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| namespace spdlog { | namespace spdlog { | ||||||
| 
 | 
 | ||||||
| class formatter; | class formatter; | ||||||
|  | |||||||
| @ -20,7 +20,6 @@ | |||||||
| namespace spdlog { | namespace spdlog { | ||||||
| namespace details { | namespace details { | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| // padding information.
 | // padding information.
 | ||||||
| struct padding_info | struct padding_info | ||||||
| { | { | ||||||
| @ -61,20 +60,16 @@ protected: | |||||||
|     padding_info padinfo_; |     padding_info padinfo_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } | } // namespace details
 | ||||||
| 
 | 
 | ||||||
| class pattern_formatter final : public formatter | class pattern_formatter final : public formatter | ||||||
| { | { | ||||||
| public: | public: | ||||||
|     explicit pattern_formatter( |     explicit pattern_formatter( | ||||||
|         std::string pattern,  |         std::string pattern, pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol); | ||||||
| 		pattern_time_type time_type = pattern_time_type::local,  |  | ||||||
| 		std::string eol = spdlog::details::os::default_eol); |  | ||||||
| 
 | 
 | ||||||
|     // use default pattern is not given
 |     // use default pattern is not given
 | ||||||
|     explicit pattern_formatter( |     explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol); | ||||||
| 		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(const pattern_formatter &other) = delete; | ||||||
|     pattern_formatter &operator=(const pattern_formatter &other) = delete; |     pattern_formatter &operator=(const pattern_formatter &other) = delete; | ||||||
|  | |||||||
| @ -2,7 +2,6 @@ | |||||||
| #include "spdlog/async_logger.h" | #include "spdlog/async_logger.h" | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| // async logger implementation
 | // async logger implementation
 | ||||||
| // uses a thread pool to perform the actual logging
 | // 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_); |     cloned->set_error_handler(this->custom_err_handler_); | ||||||
|     return std::move(cloned); |     return std::move(cloned); | ||||||
| } | } | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -17,15 +17,14 @@ | |||||||
| #include <tuple> | #include <tuple> | ||||||
| 
 | 
 | ||||||
| namespace spdlog { | namespace spdlog { | ||||||
| namespace details  | namespace details { | ||||||
|  | SPDLOG_INLINE file_helper::~file_helper() | ||||||
| { | { | ||||||
|     SPDLOG_INLINE file_helper::~file_helper() |  | ||||||
|     { |  | ||||||
|     close(); |     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(); |     close(); | ||||||
|     auto *mode = truncate ? SPDLOG_FILENAME_T("wb") : SPDLOG_FILENAME_T("ab"); |     auto *mode = truncate ? SPDLOG_FILENAME_T("wb") : SPDLOG_FILENAME_T("ab"); | ||||||
|     _filename = fname; |     _filename = fname; | ||||||
| @ -40,75 +39,75 @@ namespace details | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     throw spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno); |     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()) |     if (_filename.empty()) | ||||||
|     { |     { | ||||||
|         throw spdlog_ex("Failed re opening file - was not opened before"); |         throw spdlog_ex("Failed re opening file - was not opened before"); | ||||||
|     } |     } | ||||||
|     open(_filename, truncate); |     open(_filename, truncate); | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
|     SPDLOG_INLINE void file_helper::flush() | SPDLOG_INLINE void file_helper::flush() | ||||||
|     { | { | ||||||
|     std::fflush(fd_); |     std::fflush(fd_); | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
|     SPDLOG_INLINE void file_helper::close() | SPDLOG_INLINE void file_helper::close() | ||||||
|     { | { | ||||||
|     if (fd_ != nullptr) |     if (fd_ != nullptr) | ||||||
|     { |     { | ||||||
|         std::fclose(fd_); |         std::fclose(fd_); | ||||||
|         fd_ = nullptr; |         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(); |     size_t msg_size = buf.size(); | ||||||
|     auto data = buf.data(); |     auto data = buf.data(); | ||||||
|     if (std::fwrite(data, 1, msg_size, fd_) != msg_size) |     if (std::fwrite(data, 1, msg_size, fd_) != msg_size) | ||||||
|     { |     { | ||||||
|         throw spdlog_ex("Failed writing to file " + os::filename_to_str(_filename), errno); |         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) |     if (fd_ == nullptr) | ||||||
|     { |     { | ||||||
|         throw spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename)); |         throw spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename)); | ||||||
|     } |     } | ||||||
|     return os::filesize(fd_); |     return os::filesize(fd_); | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
|     SPDLOG_INLINE const filename_t &file_helper::filename() const | SPDLOG_INLINE const filename_t &file_helper::filename() const | ||||||
|     { | { | ||||||
|     return _filename; |     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 os::file_exists(fname); | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
|     //
 | //
 | ||||||
|     // return file path and its extension:
 | // return file path and its extension:
 | ||||||
|     //
 | //
 | ||||||
|     // "mylog.txt" => ("mylog", ".txt")
 | // "mylog.txt" => ("mylog", ".txt")
 | ||||||
|     // "mylog" => ("mylog", "")
 | // "mylog" => ("mylog", "")
 | ||||||
|     // "mylog." => ("mylog.", "")
 | // "mylog." => ("mylog.", "")
 | ||||||
|     // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt")
 | // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt")
 | ||||||
|     //
 | //
 | ||||||
|     // the starting dot in filenames is ignored (hidden files):
 | // the starting dot in filenames is ignored (hidden files):
 | ||||||
|     //
 | //
 | ||||||
|     // ".mylog" => (".mylog". "")
 | // ".mylog" => (".mylog". "")
 | ||||||
|     // "my_folder/.mylog" => ("my_folder/.mylog", "")
 | // "my_folder/.mylog" => ("my_folder/.mylog", "")
 | ||||||
|     // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
 | // "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) | SPDLOG_INLINE std::tuple<filename_t, filename_t> file_helper::split_by_extension(const filename_t &fname) | ||||||
|     { | { | ||||||
|     auto ext_index = fname.rfind('.'); |     auto ext_index = fname.rfind('.'); | ||||||
| 
 | 
 | ||||||
|     // no valid extension found - return whole path and empty string as
 |     // 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
 |     // finally - return a valid base and extension tuple
 | ||||||
|     return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index)); |     return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index)); | ||||||
|     } | } | ||||||
| } // namespace details
 | } // namespace details
 | ||||||
| } // namespace spdlog
 | } // namespace spdlog
 | ||||||
|  | |||||||
| @ -5,8 +5,6 @@ | |||||||
| #include "spdlog/details/log_msg.h" | #include "spdlog/details/log_msg.h" | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| SPDLOG_INLINE spdlog::details::log_msg::log_msg( | 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) |     spdlog::source_loc loc, const std::string *loggers_name, spdlog::level::level_enum lvl, spdlog::string_view_t view) | ||||||
|     : logger_name(loggers_name) |     : logger_name(loggers_name) | ||||||
|  | |||||||
| @ -959,37 +959,34 @@ private: | |||||||
| 
 | 
 | ||||||
| } // namespace details
 | } // 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)) |     : pattern_(std::move(pattern)) | ||||||
|     , eol_(std::move(eol)) |     , eol_(std::move(eol)) | ||||||
|     , pattern_time_type_(time_type) |     , pattern_time_type_(time_type) | ||||||
|     , last_log_secs_(0) |     , last_log_secs_(0) | ||||||
|     { | { | ||||||
|     std::memset(&cached_tm_, 0, sizeof(cached_tm_)); |     std::memset(&cached_tm_, 0, sizeof(cached_tm_)); | ||||||
|     compile_pattern_(pattern_); |     compile_pattern_(pattern_); | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
|     // use by default full formatter for if pattern is not given
 | // 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) | SPDLOG_INLINE pattern_formatter::pattern_formatter(pattern_time_type time_type, std::string eol) | ||||||
|     : pattern_("%+") |     : pattern_("%+") | ||||||
|     , eol_(std::move(eol)) |     , eol_(std::move(eol)) | ||||||
|     , pattern_time_type_(time_type) |     , pattern_time_type_(time_type) | ||||||
|     , last_log_secs_(0) |     , last_log_secs_(0) | ||||||
|     { | { | ||||||
|     std::memset(&cached_tm_, 0, sizeof(cached_tm_)); |     std::memset(&cached_tm_, 0, sizeof(cached_tm_)); | ||||||
|     formatters_.push_back(details::make_unique<details::full_formatter>(details::padding_info{})); |     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_); |     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 | #ifndef SPDLOG_NO_DATETIME | ||||||
|     auto secs = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch()); |     auto secs = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch()); | ||||||
|     if (secs != last_log_secs_) |     if (secs != last_log_secs_) | ||||||
| @ -1004,19 +1001,19 @@ private: | |||||||
|     } |     } | ||||||
|     // write eol
 |     // write eol
 | ||||||
|     details::fmt_helper::append_string_view(eol_, dest); |     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) |     if (pattern_time_type_ == pattern_time_type::local) | ||||||
|     { |     { | ||||||
|         return details::os::localtime(log_clock::to_time_t(msg.time)); |         return details::os::localtime(log_clock::to_time_t(msg.time)); | ||||||
|     } |     } | ||||||
|     return details::os::gmtime(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) |     switch (flag) | ||||||
|     { |     { | ||||||
| 
 | 
 | ||||||
| @ -1178,13 +1175,13 @@ private: | |||||||
|         formatters_.push_back((std::move(unknown_flag))); |         formatters_.push_back((std::move(unknown_flag))); | ||||||
|         break; |         break; | ||||||
|     } |     } | ||||||
|     } | } | ||||||
| 
 | 
 | ||||||
|     // Extract given pad spec (e.g. %8X)
 | // Extract given pad spec (e.g. %8X)
 | ||||||
|     // Advance the given it pass the end of the padding spec found (if any)
 | // Advance the given it pass the end of the padding spec found (if any)
 | ||||||
|     // Return padding.
 | // Return padding.
 | ||||||
|     SPDLOG_INLINE details::padding_info pattern_formatter::handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end) | 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::padding_info; | ||||||
|     using details::scoped_pad; |     using details::scoped_pad; | ||||||
|     const size_t max_width = 128; |     const size_t max_width = 128; | ||||||
| @ -1221,10 +1218,10 @@ private: | |||||||
|         width = width * 10 + digit; |         width = width * 10 + digit; | ||||||
|     } |     } | ||||||
|     return details::padding_info{std::min<size_t>(width, max_width), side}; |     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(); |     auto end = pattern.end(); | ||||||
|     std::unique_ptr<details::aggregate_formatter> user_chars; |     std::unique_ptr<details::aggregate_formatter> user_chars; | ||||||
|     formatters_.clear(); |     formatters_.clear(); | ||||||
| @ -1261,6 +1258,5 @@ private: | |||||||
|     { |     { | ||||||
|         formatters_.push_back(std::move(user_chars)); |         formatters_.push_back(std::move(user_chars)); | ||||||
|     } |     } | ||||||
|     } | } | ||||||
| } // namespace spdlog
 | } // namespace spdlog
 | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -6,7 +6,6 @@ | |||||||
| #include "spdlog/details/registry.h" | #include "spdlog/details/registry.h" | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| #include "spdlog/common.h" | #include "spdlog/common.h" | ||||||
| #include "spdlog/details/periodic_worker.h" | #include "spdlog/details/periodic_worker.h" | ||||||
| #include "spdlog/logger.h" | #include "spdlog/logger.h" | ||||||
|  | |||||||
| @ -7,11 +7,13 @@ | |||||||
| 
 | 
 | ||||||
| SPDLOG_INLINE spdlog::sinks::sink::sink() | SPDLOG_INLINE spdlog::sinks::sink::sink() | ||||||
|     : formatter_{details::make_unique<spdlog::pattern_formatter>()} |     : formatter_{details::make_unique<spdlog::pattern_formatter>()} | ||||||
| {} | { | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| SPDLOG_INLINE spdlog::sinks::sink::sink(std::unique_ptr<spdlog::formatter> formatter) | SPDLOG_INLINE spdlog::sinks::sink::sink(std::unique_ptr<spdlog::formatter> formatter) | ||||||
|     : formatter_{std::move(formatter)} |     : formatter_{std::move(formatter)} | ||||||
| {} | { | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const | SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const | ||||||
| { | { | ||||||
|  | |||||||
| @ -124,7 +124,6 @@ public: | |||||||
|         log(level::critical, fmt, args...); |         log(level::critical, fmt, args...); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     void log(level::level_enum lvl, const T &msg) |     void log(level::level_enum lvl, const T &msg) | ||||||
|     { |     { | ||||||
| @ -323,7 +322,7 @@ public: | |||||||
|     // create new logger with same sinks and configuration.
 |     // create new logger with same sinks and configuration.
 | ||||||
|     virtual std::shared_ptr<logger> clone(std::string logger_name); |     virtual std::shared_ptr<logger> clone(std::string logger_name); | ||||||
| 
 | 
 | ||||||
|     protected: | protected: | ||||||
|     virtual void sink_it_(details::log_msg &msg); |     virtual void sink_it_(details::log_msg &msg); | ||||||
| 
 | 
 | ||||||
|     virtual void flush_(); |     virtual void flush_(); | ||||||
| @ -338,8 +337,6 @@ public: | |||||||
|     spdlog::level_t level_{spdlog::logger::default_level()}; |     spdlog::level_t level_{spdlog::logger::default_level()}; | ||||||
|     spdlog::level_t flush_level_{level::off}; |     spdlog::level_t flush_level_{level::off}; | ||||||
|     err_handler custom_err_handler_{nullptr}; |     err_handler custom_err_handler_{nullptr}; | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| }; | }; | ||||||
| } // namespace spdlog
 | } // namespace spdlog
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -328,7 +328,8 @@ inline void critical(const wchar_t *fmt, const Args &... args) | |||||||
| //
 | //
 | ||||||
| 
 | 
 | ||||||
| #define SPDLOG_LOGGER_CALL(logger, level, ...)                                                                                             \ | #define SPDLOG_LOGGER_CALL(logger, level, ...)                                                                                             \ | ||||||
|     do {                                                                                                                                   \ |     do                                                                                                                                     \ | ||||||
|  |     {                                                                                                                                      \ | ||||||
|         if (logger->should_log(level))                                                                                                     \ |         if (logger->should_log(level))                                                                                                     \ | ||||||
|             logger->log(spdlog::source_loc{SPDLOG_FILE_BASENAME(__FILE__), __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__);                \ |             logger->log(spdlog::source_loc{SPDLOG_FILE_BASENAME(__FILE__), __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__);                \ | ||||||
|     } while (0) |     } while (0) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user