mirror of
https://github.com/gabime/spdlog.git
synced 2025-11-16 09:28:56 +08:00
Fixed linux port of v1.x
This commit is contained in:
@@ -37,18 +37,18 @@ inline spdlog::async_logger::async_logger(
|
||||
|
||||
// send the log message to the thread pool
|
||||
inline void spdlog::async_logger::_sink_it(details::log_msg &msg)
|
||||
{
|
||||
{
|
||||
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
|
||||
_incr_msg_counter(msg);
|
||||
_incr_msg_counter(msg);
|
||||
#endif
|
||||
if (auto pool_ptr = _thread_pool.lock())
|
||||
{
|
||||
pool_ptr->post_log(shared_from_this(), std::move(msg), _overflow_policy);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw spdlog_ex("async log: thread pool doens't exist anymore");
|
||||
}
|
||||
if (auto pool_ptr = _thread_pool.lock())
|
||||
{
|
||||
pool_ptr->post_log(shared_from_this(), std::move(msg), _overflow_policy);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw spdlog_ex("async log: thread pool doens't exist anymore");
|
||||
}
|
||||
}
|
||||
|
||||
// send flush request to the thread pool
|
||||
@@ -89,10 +89,10 @@ inline void spdlog::async_logger::_backend_log(details::log_msg &incoming_log_ms
|
||||
_err_handler("Unknown exception in async logger " + _name);
|
||||
}
|
||||
|
||||
if (_should_flush(incoming_log_msg))
|
||||
{
|
||||
_backend_flush();
|
||||
}
|
||||
if (_should_flush(incoming_log_msg))
|
||||
{
|
||||
_backend_flush();
|
||||
}
|
||||
}
|
||||
|
||||
inline void spdlog::async_logger::_backend_flush()
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../logger.h"
|
||||
#include "../sinks/stdout_sinks.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -476,18 +476,6 @@ inline bool in_terminal(FILE *file)
|
||||
#endif
|
||||
}
|
||||
|
||||
// stdout/stderr global mutexes
|
||||
inline std::mutex& stdout_mutex()
|
||||
{
|
||||
static std::mutex &mutex = std::mutex{};
|
||||
return mutex;
|
||||
}
|
||||
|
||||
inline std::mutex& stderr_mutex()
|
||||
{
|
||||
static std::mutex &mutex = std::mutex{};
|
||||
return mutex;
|
||||
}
|
||||
} // namespace os
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -148,16 +148,15 @@ public:
|
||||
|
||||
void drop_all()
|
||||
{
|
||||
{
|
||||
std::lock_guard<Mutex> lock(_mutex);
|
||||
_loggers.clear();
|
||||
}
|
||||
{
|
||||
std::lock_guard<Mutex> lock(_mutex);
|
||||
_loggers.clear();
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> lock(_tp_mutex);
|
||||
_tp.reset();
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<Mutex> lock(_tp_mutex);
|
||||
_tp.reset();
|
||||
}
|
||||
}
|
||||
|
||||
Mutex &tp_mutex()
|
||||
|
||||
@@ -6,41 +6,53 @@
|
||||
|
||||
#include "stdio.h"
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
struct console_stdout_trait
|
||||
{
|
||||
static FILE* stream() {return stdout;}
|
||||
namespace details {
|
||||
struct console_stdout_trait
|
||||
{
|
||||
static FILE *stream()
|
||||
{
|
||||
return stdout;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
static HANDLE handle() { return ::GetStdHandle(STD_OUTPUT_HANDLE); }
|
||||
static HANDLE handle()
|
||||
{
|
||||
return ::GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
struct console_stderr_trait
|
||||
{
|
||||
static FILE* stream() { return stdout; }
|
||||
struct console_stderr_trait
|
||||
{
|
||||
static FILE *stream()
|
||||
{
|
||||
return stdout;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
static HANDLE handle() { return ::GetStdHandle(STD_ERROR_HANDLE); }
|
||||
static HANDLE handle()
|
||||
{
|
||||
return ::GetStdHandle(STD_ERROR_HANDLE);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
struct console_mutex_trait
|
||||
{
|
||||
using mutex_t = std::mutex;
|
||||
static mutex_t& console_mutex()
|
||||
{
|
||||
static auto &mutex = mutex_t{};
|
||||
return mutex;
|
||||
}
|
||||
};
|
||||
struct console_mutex_trait
|
||||
{
|
||||
using mutex_t = std::mutex;
|
||||
static mutex_t &console_mutex()
|
||||
{
|
||||
static mutex_t mutex;
|
||||
return mutex;
|
||||
}
|
||||
};
|
||||
|
||||
struct console_null_mutex_trait
|
||||
{
|
||||
using mutex_t = null_mutex;
|
||||
static mutex_t& console_mutex()
|
||||
{
|
||||
static auto mutex = mutex_t{};
|
||||
return mutex;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
struct console_null_mutex_trait
|
||||
{
|
||||
using mutex_t = null_mutex;
|
||||
static mutex_t &console_mutex()
|
||||
{
|
||||
static mutex_t mutex;
|
||||
return mutex;
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
Reference in New Issue
Block a user