gabime / spdlog

Fast C++ logging library.
Other
24.39k stars 4.55k forks source link

spdlog 1.x版本中msvc fmt #3025

Closed BobLiu21 closed 8 months ago

BobLiu21 commented 8 months ago

spdlog 1.x分支下的fmt内容没有更新,虽然对应的spdlog已经更新但是include/spdlog/fmt/bound下的内容没有更新不知道是我用错了分支还是博主忘记了更新。by 2024-02-27

tt4g commented 8 months ago

fmt v10 will not be bundled in v1.x branch. See: #2767

BobLiu21 commented 8 months ago

目前fmt 10.2.1已经可以兼容了

tt4g commented 8 months ago

As far as I know, fmt v10 has been reverted by 4338b9cd23c90c7bacde5bfefddade8d02dfd821 and there will be no update to fmt v10.

BobLiu21 commented 8 months ago

我目前的用法是使用msvc2022 编译spdlog,出现大量的warning,然后我替换了10.2.1的fmt之后就没有warning了,而且能够正常输出,稍后我再重新弄个纯净的版本验证一下,多谢您的回复。

BobLiu21 commented 8 months ago

1 环境 vs2022+qt 5.15.2 c++20 2 问题 1)编译spdlog代码使用c++20标准存在大量的warning,使用c++14的时候正常,没有警告。 2)daily_logger_format_mt 第二个参数直接输入一个完整的路径存在问题,无法创建文件夹,但是我用qt代码尝试创建文件夹的时候正常。 上一个spdlog版本是可以正常创建的。 3)使用10.2.1版本的fmt代码替换spdlog/fmt/boundle下的代码c++20不存在警告。 想跟您请教一下,是否是我用错了。 1709198605571

代码

include "testspd.h"

include "spdlog/spdlog.h"

include "spdlog/sinks/daily_file_sink.h"

pragma comment(lib,"../lib/spdlogd")

testspd::testspd(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); OnInitDialog(); }

testspd::~testspd() {}

void testspd::OnInitDialog() { spdlog::set_level(spdlog::level::trace); spdlog::flush_on(spdlog::level::trace); QString path{QString("%1/logs/daily.log").arg(qApp->applicationDirPath())}; auto daily_logger = spdlog::daily_logger_format_mt("mt",path.toStdString()); daily_logger->debug("fuck"); }

tt4g commented 8 months ago

I can't answer the MSVC warning because it is fmt related, not spdlog. The reason why the log directory is not created may be that the path string is not in the character encoding expected by the OS or there is an permission error.

tt4g commented 8 months ago

2)daily_logger_format_mt 第二个参数直接输入一个完整的路径存在问题,无法创建文件夹,但是我用qt代码尝试创建文件夹的时候正常。

This is duplicate #2510

Since spdlog is calling the Windows API, you must pass the character encoding that the Windows API requires. QString::toStdString() returns UTF-8 encoding characters but Windows API requires OS encoding.

Should use QString::toLocal8Bit() that returns current OS locale cahracter encoding and QByteArray::data() (or QByteArray::toStdString()).

 void testspd::OnInitDialog()
 {
 spdlog::set_level(spdlog::level::trace);
 spdlog::flush_on(spdlog::level::trace);
 QString path{QString("%1/logs/daily.log").arg(qApp->applicationDirPath())};
-auto daily_logger = spdlog::daily_logger_format_mt("mt",path.toStdString());
+auto daily_logger = spdlog::daily_logger_format_mt("mt",path.toLocal8Bit().data());
 daily_logger->debug("fuck");
 }
BobLiu21 commented 8 months ago

-auto daily_logger = spdlog::daily_logger_format_mt("mt",path.toStdString()); +auto daily_logger = spdlog::daily_logger_format_mt("mt",path.toLocal8Bit().data()); 没有解决问题,我现在的解决方案针对msvc的警告问题,直接用最新的fmt替换boundle里面的内容;第二个问题在输入路径参数的时候先创建出来再去填写,问题就不会出现了,希望也能帮助和我遇到相同问题的人。

tt4g commented 8 months ago

fmt warnings cannot be resolved by spdlog. Since spdlog has an option to use external fmt, use external fmt option if the problem is resolved by fmt.