-
Notifications
You must be signed in to change notification settings - Fork 27
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
Can it use in threads? #14
Comments
I'm also interested in the answer to this, I'm using aixlog to log from different threads. In the console sometimes I get strange behaviour where the two messages from different threads and with different tags get mixed together: message A ends up being displayed with the wrong tag B, and message B never actually makes it to the console. |
Hi,
The problem can be reproduced by: AixLog::Log::init<AixLog::SinkCout>(AixLog::Severity::debug);
std::vector<std::shared_future<void>> futures;
for (int n = 0; n < 20; ++n)
{
const char x = 'A' + n;
auto task = std::async(std::launch::async, [this, x]
{
int n = 1000;
while (--n)
{
LOG(INFO, std::string{x}) << std::string{x} << std::string{x} << std::string{x} << std::endl;
std::this_thread::sleep_for(1ms);
}
});
futures.push_back(std::move(task));
}
for (auto& future : futures)
{
future.get();
} It seems to be caused by the fact that One possible solution is to put the std::map<std::thread::id, Metadata> buffer_; and then rewrite the Metadata& get_meta()
{
const auto id = std::this_thread::get_id();
return buffer_[id];
} |
`
int i[2] = { 0,1 };
string t[2] = { R"(E:\product\qqm\cv_pro\log\t1.log)",R"(E:\product\qqm\cv_pro\log\t2.log)" };
thread t1(&xxxx, i[0], t[0].c_str());
thread t2(&xxxx, i[1], t[1].c_str());
t1.join();
t2.join();
system("pause");
`
i want to use it in thread, as this code
i want log every thread with a single log file ,
can aixlog do it?
this 1.4 version do not work well , create two log files, but only ont have the log info
The text was updated successfully, but these errors were encountered: