mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 03:19:02 +08:00
clang-format
This commit is contained in:
@@ -51,7 +51,9 @@ void spdlog::async_logger::flush_() {
|
||||
void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg) {
|
||||
for (auto &sink : sinks_) {
|
||||
if (sink->should_log(msg.log_level)) {
|
||||
try { sink->log(msg); }
|
||||
try {
|
||||
sink->log(msg);
|
||||
}
|
||||
SPDLOG_LOGGER_CATCH(msg.source)
|
||||
}
|
||||
}
|
||||
@@ -63,7 +65,9 @@ void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg) {
|
||||
|
||||
void spdlog::async_logger::backend_flush_() {
|
||||
for (auto &sink : sinks_) {
|
||||
try { sink->flush(); }
|
||||
try {
|
||||
sink->flush();
|
||||
}
|
||||
SPDLOG_LOGGER_CATCH(source_loc())
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,10 @@ log_msg::log_msg(spdlog::log_clock::time_point log_time,
|
||||
: logger_name(a_logger_name),
|
||||
log_level(lvl),
|
||||
time(log_time),
|
||||
|
||||
#ifdef SPDLOG_NO_THREAD_ID
|
||||
thread_id(0),
|
||||
thread_id(0),
|
||||
#else
|
||||
thread_id(os::thread_id()),
|
||||
thread_id(os::thread_id()),
|
||||
#endif
|
||||
source(loc),
|
||||
payload(msg) {
|
||||
|
@@ -109,7 +109,7 @@ int rename(const filename_t &filename1, const filename_t &filename2) noexcept {
|
||||
|
||||
// Return true if path exists (file or directory)
|
||||
bool path_exists(const filename_t &filename) noexcept {
|
||||
struct stat buffer{};
|
||||
struct stat buffer {};
|
||||
return (::stat(filename.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ size_t filesize(FILE *f) {
|
||||
#endif
|
||||
// 64 bits(but not in osx, linux/musl or cygwin, where fstat64 is deprecated)
|
||||
#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__sun) || defined(_AIX)) && (defined(__LP64__) || defined(_LP64))
|
||||
struct stat64 st{};
|
||||
struct stat64 st {};
|
||||
if (::fstat64(fd, &st) == 0) {
|
||||
return static_cast<size_t>(st.st_size);
|
||||
}
|
||||
@@ -326,15 +326,13 @@ std::string getenv(const char *field) {
|
||||
// Return true on success
|
||||
bool fsync(FILE *fp) { return ::fsync(fileno(fp)) == 0; }
|
||||
|
||||
|
||||
// Non locking ::fwrite if possible (SPDLOG_FWRITE_UNLOCKED defined) or use the regular locking fwrite
|
||||
bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp)
|
||||
{
|
||||
#if defined(SPDLOG_FWRITE_UNLOCKED)
|
||||
return ::fwrite_unlocked(ptr, 1, n_bytes, fp) == n_bytes;
|
||||
#else
|
||||
return std::fwrite(ptr, 1, n_bytes, fp) == n_bytes;
|
||||
#endif
|
||||
bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp) {
|
||||
#if defined(SPDLOG_FWRITE_UNLOCKED)
|
||||
return ::fwrite_unlocked(ptr, 1, n_bytes, fp) == n_bytes;
|
||||
#else
|
||||
return std::fwrite(ptr, 1, n_bytes, fp) == n_bytes;
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace os
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -23,7 +24,6 @@
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <cassert>
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/details/os.h"
|
||||
@@ -76,9 +76,7 @@ bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) {
|
||||
return *fp == nullptr;
|
||||
}
|
||||
|
||||
int remove(const filename_t &filename) noexcept {
|
||||
return std::remove(filename.c_str());
|
||||
}
|
||||
int remove(const filename_t &filename) noexcept { return std::remove(filename.c_str()); }
|
||||
|
||||
int remove_if_exists(const filename_t &filename) noexcept { return path_exists(filename) ? remove(filename) : 0; }
|
||||
|
||||
@@ -169,7 +167,6 @@ bool is_color_terminal() noexcept { return true; }
|
||||
// Determine if the terminal attached
|
||||
bool in_terminal(FILE *file) noexcept { return ::_isatty(_fileno(file)) != 0; }
|
||||
|
||||
|
||||
void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target) {
|
||||
if (wstr.size() > static_cast<size_t>((std::numeric_limits<int>::max)()) / 4 - 1) {
|
||||
throw_spdlog_ex("UTF-16 string is too big to be converted to UTF-8");
|
||||
@@ -183,14 +180,12 @@ void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target) {
|
||||
|
||||
int result_size = static_cast<int>(target.capacity());
|
||||
if ((wstr_size + 1) * 4 > result_size) {
|
||||
result_size =
|
||||
::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, NULL, 0, NULL, NULL);
|
||||
result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, NULL, 0, NULL, NULL);
|
||||
}
|
||||
|
||||
if (result_size > 0) {
|
||||
target.resize(result_size);
|
||||
result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, target.data(),
|
||||
result_size, NULL, NULL);
|
||||
result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, target.data(), result_size, NULL, NULL);
|
||||
|
||||
if (result_size > 0) {
|
||||
target.resize(result_size);
|
||||
@@ -198,8 +193,7 @@ void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target) {
|
||||
}
|
||||
}
|
||||
|
||||
throw_spdlog_ex(
|
||||
fmt_lib::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError()));
|
||||
throw_spdlog_ex(fmt_lib::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError()));
|
||||
}
|
||||
|
||||
void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
|
||||
@@ -214,27 +208,22 @@ void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
|
||||
}
|
||||
|
||||
// find the size to allocate for the result buffer
|
||||
int result_size =
|
||||
::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, NULL, 0);
|
||||
int result_size = ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, NULL, 0);
|
||||
|
||||
if (result_size > 0) {
|
||||
target.resize(result_size);
|
||||
result_size = ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, target.data(),
|
||||
result_size);
|
||||
result_size = ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, target.data(), result_size);
|
||||
if (result_size > 0) {
|
||||
assert(result_size == target.size());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw_spdlog_ex(
|
||||
fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError()));
|
||||
throw_spdlog_ex(fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError()));
|
||||
}
|
||||
|
||||
// return true on success
|
||||
static bool mkdir_(const filename_t &path) {
|
||||
return ::_mkdir(path.c_str()) == 0;
|
||||
}
|
||||
static bool mkdir_(const filename_t &path) { return ::_mkdir(path.c_str()) == 0; }
|
||||
|
||||
// create the given directory - and all directories leading to it
|
||||
// return true on success or if the directory already exists
|
||||
@@ -305,13 +294,12 @@ std::string getenv(const char *field) {
|
||||
bool fsync(FILE *fp) { return FlushFileBuffers(reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp)))) != 0; }
|
||||
|
||||
// Non locking fwrite if possible (SPDLOG_FWRITE_UNLOCKED defined) or use the regular locking fwrite
|
||||
bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp)
|
||||
{
|
||||
#if defined(SPDLOG_FWRITE_UNLOCKED)
|
||||
return _fwrite_nolock(ptr, 1, n_bytes, fp) == n_bytes;
|
||||
#else
|
||||
return std::fwrite(ptr, 1, n_bytes, fp) == n_bytes;
|
||||
#endif
|
||||
bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp) {
|
||||
#if defined(SPDLOG_FWRITE_UNLOCKED)
|
||||
return _fwrite_nolock(ptr, 1, n_bytes, fp) == n_bytes;
|
||||
#else
|
||||
return std::fwrite(ptr, 1, n_bytes, fp) == n_bytes;
|
||||
#endif
|
||||
}
|
||||
} // namespace os
|
||||
} // namespace details
|
||||
|
@@ -45,8 +45,8 @@ thread_pool::~thread_pool() {
|
||||
for (auto &t : threads_) {
|
||||
t.join();
|
||||
}
|
||||
} catch (...) {
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
|
||||
void thread_pool::post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy) {
|
||||
|
@@ -75,7 +75,9 @@ std::shared_ptr<logger> logger::clone(std::string logger_name) {
|
||||
// private/protected methods
|
||||
void logger::flush_() {
|
||||
for (auto &sink : sinks_) {
|
||||
try { sink->flush(); }
|
||||
try {
|
||||
sink->flush();
|
||||
}
|
||||
SPDLOG_LOGGER_CATCH(source_loc())
|
||||
}
|
||||
}
|
||||
|
@@ -148,7 +148,8 @@ public:
|
||||
};
|
||||
|
||||
// Full weekday name
|
||||
static constexpr std::array<const char *, 7> full_days{{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}};
|
||||
static constexpr std::array<const char *, 7> full_days{
|
||||
{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}};
|
||||
|
||||
template <typename ScopedPadder>
|
||||
class A_formatter final : public flag_formatter {
|
||||
|
@@ -11,6 +11,4 @@ bool spdlog::sinks::sink::should_log(spdlog::level msg_level) const {
|
||||
|
||||
void spdlog::sinks::sink::set_level(level level) { level_.store(level, std::memory_order_relaxed); }
|
||||
|
||||
spdlog::level spdlog::sinks::sink::log_level() const {
|
||||
return level_.load(std::memory_order_relaxed);
|
||||
}
|
||||
spdlog::level spdlog::sinks::sink::log_level() const { return level_.load(std::memory_order_relaxed); }
|
||||
|
@@ -1,12 +1,12 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#include "spdlog/sinks/stdout_sinks.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "spdlog/pattern_formatter.h"
|
||||
#include "spdlog/sinks/stdout_sinks.h"
|
||||
#include "spdlog/details/os.h"
|
||||
#include "spdlog/pattern_formatter.h"
|
||||
|
||||
// clang-format off
|
||||
#ifdef _WIN32
|
||||
|
Reference in New Issue
Block a user