mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 03:19:02 +08:00
clang-format
This commit is contained in:
@@ -5,21 +5,21 @@
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
#include <spdlog/details/fmt_helper.h>
|
||||
#include <spdlog/details/null_mutex.h>
|
||||
#include <spdlog/details/os.h>
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
#include <spdlog/details/synchronous_factory.h>
|
||||
# include <spdlog/details/fmt_helper.h>
|
||||
# include <spdlog/details/null_mutex.h>
|
||||
# include <spdlog/details/os.h>
|
||||
# include <spdlog/sinks/base_sink.h>
|
||||
# include <spdlog/details/synchronous_factory.h>
|
||||
|
||||
#include <android/log.h>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
# include <android/log.h>
|
||||
# include <chrono>
|
||||
# include <mutex>
|
||||
# include <string>
|
||||
# include <thread>
|
||||
|
||||
#if !defined(SPDLOG_ANDROID_RETRIES)
|
||||
#define SPDLOG_ANDROID_RETRIES 2
|
||||
#endif
|
||||
# if !defined(SPDLOG_ANDROID_RETRIES)
|
||||
# define SPDLOG_ANDROID_RETRIES 2
|
||||
# endif
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef SPDLOG_HEADER_ONLY
|
||||
#include <spdlog/sinks/ansicolor_sink.h>
|
||||
# include <spdlog/sinks/ansicolor_sink.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/pattern_formatter.h>
|
||||
|
@@ -114,5 +114,5 @@ using ansicolor_stderr_sink_st = ansicolor_stderr_sink<details::console_nullmute
|
||||
} // namespace spdlog
|
||||
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
#include "ansicolor_sink-inl.h"
|
||||
# include "ansicolor_sink-inl.h"
|
||||
#endif
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef SPDLOG_HEADER_ONLY
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
# include <spdlog/sinks/base_sink.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/common.h>
|
||||
|
@@ -48,5 +48,5 @@ protected:
|
||||
} // namespace spdlog
|
||||
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
#include "base_sink-inl.h"
|
||||
# include "base_sink-inl.h"
|
||||
#endif
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef SPDLOG_HEADER_ONLY
|
||||
#include <spdlog/sinks/basic_file_sink.h>
|
||||
# include <spdlog/sinks/basic_file_sink.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/common.h>
|
||||
|
@@ -54,6 +54,5 @@ inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, c
|
||||
} // namespace spdlog
|
||||
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
#include "basic_file_sink-inl.h"
|
||||
# include "basic_file_sink-inl.h"
|
||||
#endif
|
||||
|
||||
|
@@ -31,8 +31,8 @@ struct hourly_filename_calculator
|
||||
{
|
||||
filename_t basename, ext;
|
||||
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
||||
return fmt::format(
|
||||
SPDLOG_FILENAME_T("{}_{:04d}{:02d}{:02d}_{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, now_tm.tm_hour, ext);
|
||||
return fmt::format(SPDLOG_FILENAME_T("{}_{:04d}{:02d}{:02d}_{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
|
||||
now_tm.tm_mday, now_tm.tm_hour, ext);
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
// Building and using requires mongocxx library.
|
||||
// For building mongocxx library check the url below
|
||||
// http://mongocxx.org/mongocxx-v3/installation/
|
||||
//
|
||||
//
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/details/log_msg.h"
|
||||
@@ -25,45 +25,52 @@
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
template <typename Mutex> class mongo_sink : public base_sink<Mutex> {
|
||||
template<typename Mutex>
|
||||
class mongo_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
mongo_sink(const std::string &db_name, const std::string &collection_name,
|
||||
const std::string &uri = "mongodb://localhost:27017") {
|
||||
try {
|
||||
client_ = std::make_unique<mongocxx::client>(mongocxx::uri{uri});
|
||||
db_name_ = db_name;
|
||||
coll_name_ = collection_name;
|
||||
} catch (const std::exception) {
|
||||
throw spdlog_ex("Error opening database");
|
||||
mongo_sink(const std::string &db_name, const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017")
|
||||
{
|
||||
try
|
||||
{
|
||||
client_ = std::make_unique<mongocxx::client>(mongocxx::uri{uri});
|
||||
db_name_ = db_name;
|
||||
coll_name_ = collection_name;
|
||||
}
|
||||
catch (const std::exception)
|
||||
{
|
||||
throw spdlog_ex("Error opening database");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~mongo_sink() { flush_(); }
|
||||
~mongo_sink()
|
||||
{
|
||||
flush_();
|
||||
}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
using bsoncxx::builder::stream::document;
|
||||
using bsoncxx::builder::stream::finalize;
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
using bsoncxx::builder::stream::document;
|
||||
using bsoncxx::builder::stream::finalize;
|
||||
|
||||
if (client_ != nullptr) {
|
||||
auto doc = document{}
|
||||
<< "timestamp" << bsoncxx::types::b_date(msg.time) << "level"
|
||||
<< level::to_string_view(msg.level).data() << "message"
|
||||
<< std::string(msg.payload.begin(), msg.payload.end())
|
||||
<< "logger_name"
|
||||
<< std::string(msg.logger_name.begin(), msg.logger_name.end())
|
||||
<< "thread_id" << static_cast<int>(msg.thread_id) << finalize;
|
||||
client_->database(db_name_).collection(coll_name_).insert_one(doc.view());
|
||||
if (client_ != nullptr)
|
||||
{
|
||||
auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << level::to_string_view(msg.level).data()
|
||||
<< "message" << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name"
|
||||
<< std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id"
|
||||
<< static_cast<int>(msg.thread_id) << finalize;
|
||||
client_->database(db_name_).collection(coll_name_).insert_one(doc.view());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
void flush_() override {}
|
||||
|
||||
private:
|
||||
static mongocxx::instance instance_;
|
||||
std::string db_name_;
|
||||
std::string coll_name_;
|
||||
std::unique_ptr<mongocxx::client> client_ = nullptr;
|
||||
static mongocxx::instance instance_;
|
||||
std::string db_name_;
|
||||
std::string coll_name_;
|
||||
std::unique_ptr<mongocxx::client> client_ = nullptr;
|
||||
};
|
||||
mongocxx::instance mongo_sink<std::mutex>::instance_{};
|
||||
|
||||
@@ -73,24 +80,19 @@ using mongo_sink_mt = mongo_sink<std::mutex>;
|
||||
using mongo_sink_st = mongo_sink<spdlog::details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
mongo_logger_mt(const std::string &logger_name, const std::string &db_name,
|
||||
const std::string &collection_name,
|
||||
const std::string &uri = "mongodb://localhost:27017") {
|
||||
return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name,
|
||||
collection_name, uri);
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> mongo_logger_mt(const std::string &logger_name, const std::string &db_name,
|
||||
const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017")
|
||||
{
|
||||
return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name, collection_name, uri);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
mongo_logger_st(const std::string &logger_name, const std::string &db_name,
|
||||
const std::string &collection_name,
|
||||
const std::string &uri = "mongodb://localhost:27017") {
|
||||
return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name,
|
||||
collection_name, uri);
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> mongo_logger_st(const std::string &logger_name, const std::string &db_name,
|
||||
const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017")
|
||||
{
|
||||
return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name, collection_name, uri);
|
||||
}
|
||||
|
||||
|
||||
} // namespace spdlog
|
||||
|
||||
|
@@ -5,12 +5,11 @@
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include <spdlog/details/null_mutex.h>
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
# include <spdlog/details/null_mutex.h>
|
||||
# include <spdlog/sinks/base_sink.h>
|
||||
|
||||
# include <mutex>
|
||||
# include <string>
|
||||
|
||||
// Avoid including windows.h (https://stackoverflow.com/a/30741042)
|
||||
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
|
||||
|
@@ -1,187 +1,200 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman, mguludag and spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Custom sink for QPlainTextEdit or QTextEdit and its children(QTextBrowser...
|
||||
// etc) Building and using requires Qt library.
|
||||
//
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/details/log_msg.h"
|
||||
#include "spdlog/details/synchronous_factory.h"
|
||||
#include "spdlog/sinks/base_sink.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QTextEdit>
|
||||
|
||||
namespace _spdlog_p {
|
||||
namespace _sinks_p {
|
||||
//
|
||||
// Private class for QTextEdit and its derivatives
|
||||
//
|
||||
class qtextedit_sink_p : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
qtextedit_sink_p(QTextEdit *textedit = nullptr) {
|
||||
if (textedit != nullptr) {
|
||||
textedit_ = textedit;
|
||||
connect(this, &qtextedit_sink_p::append_text, textedit_,
|
||||
&QTextEdit::append);
|
||||
}
|
||||
}
|
||||
|
||||
~qtextedit_sink_p() {}
|
||||
|
||||
void append(const spdlog::string_view_t &str) {
|
||||
emit append_text(
|
||||
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
||||
}
|
||||
|
||||
signals:
|
||||
void append_text(const QString &);
|
||||
|
||||
private:
|
||||
QTextEdit *textedit_ = nullptr;
|
||||
};
|
||||
|
||||
//
|
||||
// Private class for QPlainTextEdit
|
||||
//
|
||||
class qplaintextedit_sink_p : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr) {
|
||||
if (textedit != nullptr) {
|
||||
textedit_ = textedit;
|
||||
connect(this, &qplaintextedit_sink_p::append_text, textedit_,
|
||||
&QPlainTextEdit::appendPlainText);
|
||||
}
|
||||
}
|
||||
|
||||
~qplaintextedit_sink_p() {}
|
||||
|
||||
void append(const spdlog::string_view_t &str) {
|
||||
emit append_text(
|
||||
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
||||
}
|
||||
|
||||
signals:
|
||||
void append_text(const QString &);
|
||||
|
||||
private:
|
||||
QPlainTextEdit *textedit_ = nullptr;
|
||||
};
|
||||
} // namespace _sinks_p
|
||||
} // namespace _spdlog_p
|
||||
|
||||
//
|
||||
// qtextedit_sink class
|
||||
//
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
template <typename Mutex> class qtextedit_sink : public base_sink<Mutex> {
|
||||
public:
|
||||
qtextedit_sink(QTextEdit *textedit = nullptr) {
|
||||
if (textedit != nullptr) {
|
||||
textedit_p =
|
||||
std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit);
|
||||
} else {
|
||||
throw spdlog_ex("Error opening QTextEdit");
|
||||
}
|
||||
}
|
||||
|
||||
~qtextedit_sink() { flush_(); }
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
||||
textedit_p->append(str_v);
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<_spdlog_p::_sinks_p::qtextedit_sink_p> textedit_p = nullptr;
|
||||
};
|
||||
|
||||
//
|
||||
// qplaintextedit_sink class
|
||||
//
|
||||
template <typename Mutex> class qplaintextedit_sink : public base_sink<Mutex> {
|
||||
public:
|
||||
qplaintextedit_sink(QPlainTextEdit *textedit = nullptr) {
|
||||
if (textedit != nullptr) {
|
||||
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>(
|
||||
textedit);
|
||||
} else {
|
||||
throw spdlog_ex("Error opening QPlainTextEdit");
|
||||
}
|
||||
}
|
||||
|
||||
~qplaintextedit_sink() { flush_(); }
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
||||
textedit_p->append(str_v);
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p =
|
||||
nullptr;
|
||||
};
|
||||
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include <mutex>
|
||||
using qtextedit_sink_mt = qtextedit_sink<std::mutex>;
|
||||
using qtextedit_sink_st = qtextedit_sink<spdlog::details::null_mutex>;
|
||||
|
||||
using qplaintextedit_sink_mt = qplaintextedit_sink<std::mutex>;
|
||||
using qplaintextedit_sink_st = qplaintextedit_sink<spdlog::details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
|
||||
//
|
||||
// Factory functions
|
||||
//
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qtextedit_logger_mt(const std::string &logger_name,
|
||||
QTextEdit *qtextedit = nullptr) {
|
||||
return Factory::template create<sinks::qtextedit_sink_mt>(logger_name,
|
||||
qtextedit);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qtextedit_logger_st(const std::string &logger_name,
|
||||
QTextEdit *qtextedit = nullptr) {
|
||||
return Factory::template create<sinks::qtextedit_sink_st>(logger_name,
|
||||
qtextedit);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qplaintextedit_logger_mt(const std::string &logger_name,
|
||||
QPlainTextEdit *qplaintextedit = nullptr) {
|
||||
return Factory::template create<sinks::qplaintextedit_sink_mt>(
|
||||
logger_name, qplaintextedit);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qplaintextedit_logger_st(const std::string &logger_name,
|
||||
QPlainTextEdit *qplaintextedit = nullptr) {
|
||||
return Factory::template create<sinks::qplaintextedit_sink_st>(
|
||||
logger_name, qplaintextedit);
|
||||
}
|
||||
} // namespace spdlog
|
||||
// Copyright(c) 2015-present, Gabi Melman, mguludag and spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Custom sink for QPlainTextEdit or QTextEdit and its children(QTextBrowser...
|
||||
// etc) Building and using requires Qt library.
|
||||
//
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/details/log_msg.h"
|
||||
#include "spdlog/details/synchronous_factory.h"
|
||||
#include "spdlog/sinks/base_sink.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QTextEdit>
|
||||
|
||||
namespace _spdlog_p {
|
||||
namespace _sinks_p {
|
||||
//
|
||||
// Private class for QTextEdit and its derivatives
|
||||
//
|
||||
class qtextedit_sink_p : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
qtextedit_sink_p(QTextEdit *textedit = nullptr)
|
||||
{
|
||||
if (textedit != nullptr)
|
||||
{
|
||||
textedit_ = textedit;
|
||||
connect(this, &qtextedit_sink_p::append_text, textedit_, &QTextEdit::append);
|
||||
}
|
||||
}
|
||||
|
||||
~qtextedit_sink_p() {}
|
||||
|
||||
void append(const spdlog::string_view_t &str)
|
||||
{
|
||||
emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
||||
}
|
||||
|
||||
signals:
|
||||
void append_text(const QString &);
|
||||
|
||||
private:
|
||||
QTextEdit *textedit_ = nullptr;
|
||||
};
|
||||
|
||||
//
|
||||
// Private class for QPlainTextEdit
|
||||
//
|
||||
class qplaintextedit_sink_p : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr)
|
||||
{
|
||||
if (textedit != nullptr)
|
||||
{
|
||||
textedit_ = textedit;
|
||||
connect(this, &qplaintextedit_sink_p::append_text, textedit_, &QPlainTextEdit::appendPlainText);
|
||||
}
|
||||
}
|
||||
|
||||
~qplaintextedit_sink_p() {}
|
||||
|
||||
void append(const spdlog::string_view_t &str)
|
||||
{
|
||||
emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
||||
}
|
||||
|
||||
signals:
|
||||
void append_text(const QString &);
|
||||
|
||||
private:
|
||||
QPlainTextEdit *textedit_ = nullptr;
|
||||
};
|
||||
} // namespace _sinks_p
|
||||
} // namespace _spdlog_p
|
||||
|
||||
//
|
||||
// qtextedit_sink class
|
||||
//
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
template<typename Mutex>
|
||||
class qtextedit_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
qtextedit_sink(QTextEdit *textedit = nullptr)
|
||||
{
|
||||
if (textedit != nullptr)
|
||||
{
|
||||
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw spdlog_ex("Error opening QTextEdit");
|
||||
}
|
||||
}
|
||||
|
||||
~qtextedit_sink()
|
||||
{
|
||||
flush_();
|
||||
}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
||||
textedit_p->append(str_v);
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<_spdlog_p::_sinks_p::qtextedit_sink_p> textedit_p = nullptr;
|
||||
};
|
||||
|
||||
//
|
||||
// qplaintextedit_sink class
|
||||
//
|
||||
template<typename Mutex>
|
||||
class qplaintextedit_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
qplaintextedit_sink(QPlainTextEdit *textedit = nullptr)
|
||||
{
|
||||
if (textedit != nullptr)
|
||||
{
|
||||
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>(textedit);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw spdlog_ex("Error opening QPlainTextEdit");
|
||||
}
|
||||
}
|
||||
|
||||
~qplaintextedit_sink()
|
||||
{
|
||||
flush_();
|
||||
}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
||||
textedit_p->append(str_v);
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p = nullptr;
|
||||
};
|
||||
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include <mutex>
|
||||
using qtextedit_sink_mt = qtextedit_sink<std::mutex>;
|
||||
using qtextedit_sink_st = qtextedit_sink<spdlog::details::null_mutex>;
|
||||
|
||||
using qplaintextedit_sink_mt = qplaintextedit_sink<std::mutex>;
|
||||
using qplaintextedit_sink_st = qplaintextedit_sink<spdlog::details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
|
||||
//
|
||||
// Factory functions
|
||||
//
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> qtextedit_logger_mt(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
|
||||
{
|
||||
return Factory::template create<sinks::qtextedit_sink_mt>(logger_name, qtextedit);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> qtextedit_logger_st(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
|
||||
{
|
||||
return Factory::template create<sinks::qtextedit_sink_st>(logger_name, qtextedit);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> qplaintextedit_logger_mt(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
|
||||
{
|
||||
return Factory::template create<sinks::qplaintextedit_sink_mt>(logger_name, qplaintextedit);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> qplaintextedit_logger_st(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
|
||||
{
|
||||
return Factory::template create<sinks::qplaintextedit_sink_st>(logger_name, qplaintextedit);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef SPDLOG_HEADER_ONLY
|
||||
#include <spdlog/sinks/rotating_file_sink.h>
|
||||
# include <spdlog/sinks/rotating_file_sink.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/common.h>
|
||||
|
@@ -74,5 +74,5 @@ inline std::shared_ptr<logger> rotating_logger_st(
|
||||
} // namespace spdlog
|
||||
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
#include "rotating_file_sink-inl.h"
|
||||
# include "rotating_file_sink-inl.h"
|
||||
#endif
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef SPDLOG_HEADER_ONLY
|
||||
#include <spdlog/sinks/sink.h>
|
||||
# include <spdlog/sinks/sink.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/common.h>
|
||||
|
@@ -31,5 +31,5 @@ protected:
|
||||
} // namespace spdlog
|
||||
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
#include "sink-inl.h"
|
||||
# include "sink-inl.h"
|
||||
#endif
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef SPDLOG_HEADER_ONLY
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
# include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/logger.h>
|
||||
@@ -36,4 +36,3 @@ SPDLOG_INLINE std::shared_ptr<logger> stderr_color_st(const std::string &logger_
|
||||
return Factory::template create<sinks::stderr_color_sink_st>(logger_name, mode);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
||||
|
@@ -4,9 +4,9 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <spdlog/sinks/wincolor_sink.h>
|
||||
# include <spdlog/sinks/wincolor_sink.h>
|
||||
#else
|
||||
#include <spdlog/sinks/ansicolor_sink.h>
|
||||
# include <spdlog/sinks/ansicolor_sink.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/details/synchronous_factory.h>
|
||||
@@ -41,5 +41,5 @@ std::shared_ptr<logger> stderr_color_st(const std::string &logger_name, color_mo
|
||||
} // namespace spdlog
|
||||
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
#include "stdout_color_sinks-inl.h"
|
||||
# include "stdout_color_sinks-inl.h"
|
||||
#endif
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef SPDLOG_HEADER_ONLY
|
||||
#include <spdlog/sinks/stdout_sinks.h>
|
||||
# include <spdlog/sinks/stdout_sinks.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/details/console_globals.h>
|
||||
@@ -14,15 +14,15 @@
|
||||
#ifdef _WIN32
|
||||
// under windows using fwrite to non-binary stream results in \r\r\n (see issue #1675)
|
||||
// so instead we use ::FileWrite
|
||||
#include <spdlog/details/windows_include.h>
|
||||
# include <spdlog/details/windows_include.h>
|
||||
|
||||
#ifndef _USING_V110_SDK71_ // fileapi.h doesnt exist in winxp
|
||||
#include <fileapi.h> // WriteFile (..)
|
||||
#endif
|
||||
# ifndef _USING_V110_SDK71_ // fileapi.h doesnt exist in winxp
|
||||
# include <fileapi.h> // WriteFile (..)
|
||||
# endif
|
||||
|
||||
#include <io.h> // _get_osfhandle(..)
|
||||
#include <stdio.h> // _fileno(..)
|
||||
#endif // WIN32
|
||||
# include <io.h> // _get_osfhandle(..)
|
||||
# include <stdio.h> // _fileno(..)
|
||||
#endif // WIN32
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
@@ -36,9 +36,9 @@ SPDLOG_INLINE stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// get windows handle from the FILE* object
|
||||
|
||||
handle_ = (HANDLE)::_get_osfhandle(::_fileno(file_));
|
||||
|
||||
|
||||
handle_ = (HANDLE)::_get_osfhandle(::_fileno(file_));
|
||||
|
||||
// don't throw to support cases where no console is attached,
|
||||
// and let the log method to do nothing if (handle_ == INVALID_HANDLE_VALUE).
|
||||
// throw only if non stdout/stderr target is requested (probably regular file and not console).
|
||||
@@ -54,7 +54,7 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &m
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (handle_ == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
@@ -74,7 +74,7 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &m
|
||||
formatter_->format(msg, formatted);
|
||||
::fwrite(formatted.data(), sizeof(char), formatted.size(), file_);
|
||||
::fflush(file_); // flush every line to terminal
|
||||
#endif // WIN32
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <spdlog/details/windows_include.h>
|
||||
# include <spdlog/details/windows_include.h>
|
||||
#endif
|
||||
|
||||
namespace spdlog {
|
||||
@@ -41,7 +41,7 @@ protected:
|
||||
FILE *file_;
|
||||
std::unique_ptr<spdlog::formatter> formatter_;
|
||||
#ifdef _WIN32
|
||||
HANDLE handle_;
|
||||
HANDLE handle_;
|
||||
#endif // WIN32
|
||||
};
|
||||
|
||||
@@ -83,5 +83,5 @@ std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name);
|
||||
} // namespace spdlog
|
||||
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
#include "stdout_sinks-inl.h"
|
||||
# include "stdout_sinks-inl.h"
|
||||
#endif
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <array>
|
||||
#ifndef SD_JOURNAL_SUPPRESS_LOCATION
|
||||
#define SD_JOURNAL_SUPPRESS_LOCATION
|
||||
# define SD_JOURNAL_SUPPRESS_LOCATION
|
||||
#endif
|
||||
#include <systemd/sd-journal.h>
|
||||
|
||||
|
@@ -7,9 +7,9 @@
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
#include <spdlog/details/null_mutex.h>
|
||||
#ifdef _WIN32
|
||||
#include <spdlog/details/tcp_client-windows.h>
|
||||
# include <spdlog/details/tcp_client-windows.h>
|
||||
#else
|
||||
#include <spdlog/details/tcp_client.h>
|
||||
# include <spdlog/details/tcp_client.h>
|
||||
#endif
|
||||
|
||||
#include <mutex>
|
||||
|
@@ -229,11 +229,11 @@ protected:
|
||||
|
||||
LPCWSTR lp_wstr = buf.data();
|
||||
succeeded = ::ReportEventW(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), event_id_,
|
||||
current_user_sid_.as_sid(), 1, 0, &lp_wstr, nullptr);
|
||||
current_user_sid_.as_sid(), 1, 0, &lp_wstr, nullptr);
|
||||
#else
|
||||
LPCSTR lp_str = formatted.data();
|
||||
succeeded = ::ReportEventA(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), event_id_,
|
||||
current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr);
|
||||
current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr);
|
||||
#endif
|
||||
|
||||
if (!succeeded)
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef SPDLOG_HEADER_ONLY
|
||||
#include <spdlog/sinks/wincolor_sink.h>
|
||||
# include <spdlog/sinks/wincolor_sink.h>
|
||||
#endif
|
||||
|
||||
#include <spdlog/details/windows_include.h>
|
||||
@@ -129,10 +129,10 @@ std::uint16_t SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_foreground_color_(s
|
||||
if (!::GetConsoleScreenBufferInfo(static_cast<HANDLE>(out_handle_), &orig_buffer_info))
|
||||
{
|
||||
// just return white if failed getting console info
|
||||
return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
}
|
||||
|
||||
// change only the foreground bits (lowest 4 bits)
|
||||
|
||||
// change only the foreground bits (lowest 4 bits)
|
||||
auto new_attribs = static_cast<WORD>(attribs) | (orig_buffer_info.wAttributes & 0xfff0);
|
||||
auto ignored = ::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), static_cast<WORD>(new_attribs));
|
||||
(void)(ignored);
|
||||
|
@@ -23,7 +23,7 @@ namespace sinks {
|
||||
template<typename ConsoleMutex>
|
||||
class wincolor_sink : public sink
|
||||
{
|
||||
public:
|
||||
public:
|
||||
wincolor_sink(void *out_handle, color_mode mode);
|
||||
~wincolor_sink() override;
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
protected:
|
||||
using mutex_t = typename ConsoleMutex::mutex_t;
|
||||
void *out_handle_;
|
||||
mutex_t &mutex_;
|
||||
mutex_t &mutex_;
|
||||
bool should_do_colors_;
|
||||
std::unique_ptr<spdlog::formatter> formatter_;
|
||||
std::array<std::uint16_t, level::n_levels> colors_;
|
||||
@@ -81,5 +81,5 @@ using wincolor_stderr_sink_st = wincolor_stderr_sink<details::console_nullmutex>
|
||||
} // namespace spdlog
|
||||
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
#include "wincolor_sink-inl.h"
|
||||
# include "wincolor_sink-inl.h"
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user