Opened 9 years ago

Closed 9 years ago

#9220 closed Bugs (fixed)

Allow using widechar along with narrowchar without creating separated streams

Reported by: mntmnt7@… Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost 1.54.0 Severity: Problem
Keywords: log wchar_t wstring string Cc:

Description

It would be so nice to have a possibility to put wide-char objects along with narrow-char objects into Logging streams without creating separated versions like "logger"/"wlogger" for each type.

If I use both types simultaneously, I mean std::string and std::wstring, and I want to report everything into my log-file then I have a mess. I need EITHER to create separate logging-objects for each type OR convert one type into another.

For example, Google-test library allows mix wchar and char output for custom error message for ASSERT:

ASSERT_TRUE(false) << L"wide-message" << "narrow-message";
ASSERT_FALSE(true) << std::wstring(L"message") << std::string("message");

And it is so convenient!

Any stream operator overloading is not an option. If library claims to be convenient, it should not require some magic non-documented workarounds.

Thanks!

Change History (1)

comment:1 by Andrey Semashev, 9 years ago

Resolution: fixed
Status: newclosed

You can just always use wlogger. Just don't forget to setup a proper locale in the sink so that wide characters are converted to narrow chars correctly when storing to files.

You can also output wide strings to narrow loggers, but in this case you don't have the control over the locale in the stream.

Note: See TracTickets for help on using tickets.