You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
/// 该文件可在需要的地方引用
|
|
|
|
|
#ifndef LOGFORMAT_H
|
|
|
|
|
#define LOGFORMAT_H
|
|
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QByteArray>
|
|
|
|
|
#include <spdlog/fmt/fmt.h>
|
|
|
|
|
///
|
|
|
|
|
///spdlog对QString的输出支持
|
|
|
|
|
///
|
|
|
|
|
template <>
|
|
|
|
|
struct fmt::formatter<QString> {
|
|
|
|
|
template <typename ParseContext>
|
|
|
|
|
const typename ParseContext::iterator parse(ParseContext& ctx) {
|
|
|
|
|
return ctx.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename FormatContext>
|
|
|
|
|
typename FormatContext::iterator format(const QString& str, FormatContext& ctx) {
|
|
|
|
|
auto to_std_string = [](const QString& str) { return str.toStdString(); };
|
|
|
|
|
return format_to(ctx.out(), "{}", to_std_string(str));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
///
|
|
|
|
|
///spdlog对QByteArray的输出支持
|
|
|
|
|
///
|
|
|
|
|
template <>
|
|
|
|
|
struct fmt::formatter<QByteArray> {
|
|
|
|
|
template <typename ParseContext>
|
|
|
|
|
const typename ParseContext::iterator parse(ParseContext& ctx) {
|
|
|
|
|
return ctx.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename FormatContext>
|
|
|
|
|
typename FormatContext::iterator format(const QByteArray& str, FormatContext& ctx) {
|
|
|
|
|
auto to_std_string = [](const QByteArray& str) { return str.toStdString(); };
|
|
|
|
|
return format_to(ctx.out(), "{}", to_std_string(str));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
#endif // LOGFORMAT_H
|