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

Inline logging output of fmtquill::join() outputs wrong data #356

Closed
YuukiHogo opened this issue Oct 2, 2023 · 2 comments
Closed

Inline logging output of fmtquill::join() outputs wrong data #356

YuukiHogo opened this issue Oct 2, 2023 · 2 comments

Comments

@YuukiHogo
Copy link

YuukiHogo commented Oct 2, 2023

In multithreaded environment the code below outputs random hex string:

std::vector<uint8_t> data(100);
LOG_DEBUG(quill::get_logger(), "data: {:02x}", fmtquill::join(data, ""));

Workaround:

std::vector<uint8_t> data(100);
auto aux = fmtquill::format("{:x02}",  fmtquill::join(data, ""));
LOG_DEBUG(quill::get_logger(), "data: {}", aux);

Is there a better way to fix this?

@odygrd
Copy link
Owner

odygrd commented Nov 1, 2023

The problem seems to be that fmt join returns a view

if you try this it will fail with error 'passing views as lvalues is disallowed'

  std::vector<uint8_t> data(100);
  auto s = fmtquill::join(data, "");
  fmtquill::format("data: {:02x}", s);

The logger makes a copy of the view and then the backend thread tries to format it.

I am not sure if that can be supported. It would be good tho to fail with a static assertion when a view is passed to a LOG macro

Your workaround is good with the only drawback that the format is done on the hot thread but i dont think we have another option here

@odygrd
Copy link
Owner

odygrd commented Nov 2, 2023

This is now disabled in compile time with 4cc4dae

As you mentioned please use the provided workaround for now

std::vector<uint8_t> data(100);
auto aux = fmtquill::format("{:x02}",  fmtquill::join(data, ""));
LOG_DEBUG(quill::get_logger(), "data: {}", aux);

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