Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spdlog 1.x版本中msvc fmt #3025

Closed
BobLiu21 opened this issue Feb 27, 2024 · 9 comments
Closed

spdlog 1.x版本中msvc fmt #3025

BobLiu21 opened this issue Feb 27, 2024 · 9 comments

Comments

@BobLiu21
Copy link

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

@tt4g
Copy link
Contributor

tt4g commented Feb 27, 2024

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

@BobLiu21
Copy link
Author

目前fmt 10.2.1已经可以兼容了

@tt4g
Copy link
Contributor

tt4g commented Feb 28, 2024

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

@BobLiu21
Copy link
Author

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

@BobLiu21
Copy link
Author

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
Copy link
Contributor

tt4g commented Feb 29, 2024

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
Copy link
Contributor

tt4g commented Mar 1, 2024

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
Copy link
Author

BobLiu21 commented Mar 4, 2024

-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里面的内容;第二个问题在输入路径参数的时候先创建出来再去填写,问题就不会出现了,希望也能帮助和我遇到相同问题的人。

@BobLiu21 BobLiu21 closed this as completed Mar 4, 2024
@tt4g
Copy link
Contributor

tt4g commented Mar 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants