Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#10246 closed Bugs (invalid)

asynchronous_sink sometimes "misses" an attribute

Reported by: bielecki.b@… Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

Using following

boost::log::sinks::asynchronous_sink<
    boost::log::sinks::text_ostream_backend
>

boost::log::sources::severity_channel_logger_mt<Level, Group> scl;

with helper keywords (Level and Group and enums)

namespace {
    BOOST_LOG_ATTRIBUTE_KEYWORD(level, "Severity", Level)
    BOOST_LOG_ATTRIBUTE_KEYWORD(group, "Channel", Group)
}

configured to use following format

void formatter(
    blog::record_view const& record,
    blog::formatting_ostream& stream
) {
    stream << "[" << record[level] << "]";
    stream << "[" << record[group] << "]";
    stream << " " << record[expr::smessage];
}

In the std::cout and/or in file output one of the attributes (I only noticed this happens for level) is (sometimes) missing, even though that they are always passed. Example:

BOOST_LOG_CHANNEL_SEV(scl, Group::General, Level::Error) << "Foo";

Possible outputs:
[Error][General] Foo
[][General] Foo

This doesn't happen in case of synchronous sink.

Visual Studio 2013

Attachments (1)

async_missing.cpp (3.1 KB ) - added by bielecki.b@… 8 years ago.
Reproduction

Download all attachments as: .zip

Change History (6)

comment:1 by Andrey Semashev, 8 years ago

Please, test with 1.56 RC or the current git master.

comment:2 by Andrey Semashev, 8 years ago

Also, if the more recent version still has the problem, I'll need a small test program to reproduce the problem.

by bielecki.b@…, 8 years ago

Attachment: async_missing.cpp added

Reproduction

comment:3 by bielecki.b@…, 8 years ago

I've tested it with 1.56 - the problem remains.

comment:4 by Andrey Semashev, 8 years ago

Resolution: invalid
Status: newclosed

You have a race condition in operator<< for Level and Group enums. MSVC doesn't support thread-safe initialization of function-local static variables. Since these operators are called in dedicated threads of async sinks, they are called concurrently. Sometimes this results in the 'strings' arrays being uninitialized when used.

comment:5 by anonymous, 8 years ago

Thank you (I thought that MSVC team got this one done at least).

Note: See TracTickets for help on using tickets.