logog
logger optimized for games
Unicode support

The logog library may be compiled either in ANSI mode or in Unicode mode. By default, logog is compiled as an ANSI library. In this case, multibyte characters are not permitted in log messages. To enable Unicode support, define the LOGOG_UNICODE flag in logog.hpp before compiling the logog library.

Defining this flag sets wchar_t as the base type for all logog character operations. On Windows like platforms, a wchar_t is two bytes, and on Posix-like platforms this may be two bytes or four bytes.

Because Unicode support is based around wchar_t, the exact format of the Unicode output depends on the endianness of the target platform as well as the size of wchar_t. If logog is creating a new output log file, logog tries to add a Unicode BOM to the start of the file, if wchar_t is either two or four bytes in length. In this case, logog can write a UTF-16 or UTF-32 BOM, in either little or big endian format. See LogFile::WriteUnicodeBOM() for more information on how this BOM is written. More information on what a BOM does is available at http://unicode.org/faq/utf_bom.html .

Defining LOGOG_UNICODE has several effects on logog. First, this forces all logging functions to expect to receive string parameters as arrays of the local wchar_t type instead of char types. In other words, the LOGOG_CHAR base type is redefined to wchar_t instead of char. Second, this forces logog to route all Cout messages to wcout, and all Cerr messages to wcerr.

A convenience macro, _LG(), is available (if you haven't defined LOGOG_USE_PREFIX) for easily switching your constant strings from ANSI to Unicode, based on the compilation value of LOGOG_UNICODE. To use this macro, and hence to have all your code compile in both ANSI and Unicode modes, log in the following fashion:

INFO(_LG("This informational message is displayed in both ANSI and Unicode builds."));
WARN(LOGOG_CONST_STRING("And this one works regardless of the LOGOG_USE_PREFIX setting."));

Mixing and matching both Unicode and ANSI messages in one application is not currently supported, as most compilers do not implement this functionality.

Windows specific issues

Windows platforms have special considerations when logging to the console with wide characters via wcout or wcerr. Because logog shares the console with its host application, it does not initialize the console in any way. On Windows flavored platforms, the console must be initialized in a Unicode-friendly way. See http://blogs.msdn.com/b/michkap/archive/2008/03/18/8306597.aspx for details about how this might work.

One way of initializing a Windows console for Unicode support, which seems to work, is as follows:

#ifdef LOGOG_UNICODE
#ifdef LOGOG_FLAVOR_WINDOWS
_setmode(_fileno(stdout), _O_U16TEXT);
_setmode(_fileno(stderr), _O_U16TEXT);
#endif // LOGOG_FLAVOR_WINDOWS
#endif // LOGOG_UNICODE

See also Microsoft's documentation at http://msdn.microsoft.com/en-us/library/tw4k6df8.aspx .