1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/logging.h"
10 typedef HANDLE FileHandle
;
11 typedef HANDLE MutexHandle
;
12 // Windows warns on using write(). It prefers _write().
13 #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count))
14 // Windows doesn't define STDERR_FILENO. Define it here.
15 #define STDERR_FILENO 2
16 #elif defined(OS_MACOSX)
17 #include <mach/mach.h>
18 #include <mach/mach_time.h>
19 #include <mach-o/dyld.h>
20 #elif defined(OS_POSIX)
22 #include <sys/time.h> // timespec doesn't seem to be in <time.h>
24 #include <sys/syscall.h>
36 #define MAX_PATH PATH_MAX
37 typedef FILE* FileHandle
;
38 typedef pthread_mutex_t
* MutexHandle
;
47 #include "base/base_switches.h"
48 #include "base/command_line.h"
49 #include "base/debug/debugger.h"
50 #include "base/debug/stack_trace.h"
51 #include "base/eintr_wrapper.h"
52 #include "base/string_piece.h"
53 #include "base/synchronization/lock_impl.h"
54 #include "base/threading/platform_thread.h"
55 #include "base/utf_string_conversions.h"
56 #include "base/vlog.h"
58 #include "base/safe_strerror_posix.h"
61 #if defined(OS_ANDROID)
62 #include <android/log.h>
67 DcheckState g_dcheck_state
= DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS
;
71 VlogInfo
* g_vlog_info
= NULL
;
72 VlogInfo
* g_vlog_info_prev
= NULL
;
74 const char* const log_severity_names
[LOG_NUM_SEVERITIES
] = {
75 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" };
77 int min_log_level
= 0;
79 // The default set here for logging_destination will only be used if
80 // InitLogging is not called. On Windows, use a file next to the exe;
81 // on POSIX platforms, where it may not even be possible to locate the
82 // executable on disk, use stderr.
84 LoggingDestination logging_destination
= LOG_ONLY_TO_FILE
;
85 #elif defined(OS_POSIX)
86 LoggingDestination logging_destination
= LOG_ONLY_TO_SYSTEM_DEBUG_LOG
;
89 // For LOG_ERROR and above, always print to stderr.
90 const int kAlwaysPrintErrorLevel
= LOG_ERROR
;
92 // Which log file to use? This is initialized by InitLogging or
93 // will be lazily initialized to the default value when it is
96 typedef std::wstring PathString
;
98 typedef std::string PathString
;
100 PathString
* log_file_name
= NULL
;
102 // this file is lazily opened and the handle may be NULL
103 FileHandle log_file
= NULL
;
105 // what should be prepended to each message?
106 bool log_process_id
= false;
107 bool log_thread_id
= false;
108 bool log_timestamp
= true;
109 bool log_tickcount
= false;
111 // Should we pop up fatal debug messages in a dialog?
112 bool show_error_dialogs
= false;
114 // An assert handler override specified by the client to be called instead of
115 // the debug message dialog and process termination.
116 LogAssertHandlerFunction log_assert_handler
= NULL
;
117 // An report handler override specified by the client to be called instead of
118 // the debug message dialog.
119 LogReportHandlerFunction log_report_handler
= NULL
;
120 // A log message handler that gets notified of every log message we process.
121 LogMessageHandlerFunction log_message_handler
= NULL
;
123 // Helper functions to wrap platform differences.
125 int32
CurrentProcessId() {
127 return GetCurrentProcessId();
128 #elif defined(OS_POSIX)
135 return GetTickCount();
136 #elif defined(OS_MACOSX)
137 return mach_absolute_time();
138 #elif defined(OS_NACL)
139 // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h
140 // So we have to use clock() for now.
142 #elif defined(OS_POSIX)
144 clock_gettime(CLOCK_MONOTONIC
, &ts
);
146 uint64 absolute_micro
=
147 static_cast<int64
>(ts
.tv_sec
) * 1000000 +
148 static_cast<int64
>(ts
.tv_nsec
) / 1000;
150 return absolute_micro
;
154 void CloseFile(FileHandle log
) {
162 void DeleteFilePath(const PathString
& log_name
) {
164 DeleteFile(log_name
.c_str());
166 unlink(log_name
.c_str());
170 PathString
GetDefaultLogFile() {
172 // On Windows we use the same path as the exe.
173 wchar_t module_name
[MAX_PATH
];
174 GetModuleFileName(NULL
, module_name
, MAX_PATH
);
176 PathString log_file
= module_name
;
177 PathString::size_type last_backslash
=
178 log_file
.rfind('\\', log_file
.size());
179 if (last_backslash
!= PathString::npos
)
180 log_file
.erase(last_backslash
+ 1);
181 log_file
+= L
"debug.log";
183 #elif defined(OS_POSIX)
184 // On other platforms we just use the current directory.
185 return PathString("debug.log");
189 // This class acts as a wrapper for locking the logging files.
190 // LoggingLock::Init() should be called from the main thread before any logging
191 // is done. Then whenever logging, be sure to have a local LoggingLock
192 // instance on the stack. This will ensure that the lock is unlocked upon
193 // exiting the frame.
194 // LoggingLocks can not be nested.
205 static void Init(LogLockingState lock_log
, const PathChar
* new_log_file
) {
208 lock_log_file
= lock_log
;
209 if (lock_log_file
== LOCK_LOG_FILE
) {
212 std::wstring safe_name
;
214 safe_name
= new_log_file
;
216 safe_name
= GetDefaultLogFile();
217 // \ is not a legal character in mutex names so we replace \ with /
218 std::replace(safe_name
.begin(), safe_name
.end(), '\\', '/');
219 std::wstring
t(L
"Global\\");
221 log_mutex
= ::CreateMutex(NULL
, FALSE
, t
.c_str());
223 if (log_mutex
== NULL
) {
225 // Keep the error code for debugging
226 int error
= GetLastError(); // NOLINT
227 base::debug::BreakDebugger();
229 // Return nicely without putting initialized to true.
235 log_lock
= new base::internal::LockImpl();
241 static void LockLogging() {
242 if (lock_log_file
== LOCK_LOG_FILE
) {
244 ::WaitForSingleObject(log_mutex
, INFINITE
);
245 // WaitForSingleObject could have returned WAIT_ABANDONED. We don't
246 // abort the process here. UI tests might be crashy sometimes,
247 // and aborting the test binary only makes the problem worse.
248 // We also don't use LOG macros because that might lead to an infinite
249 // loop. For more info see http://crbug.com/18028.
250 #elif defined(OS_POSIX)
251 pthread_mutex_lock(&log_mutex
);
259 static void UnlockLogging() {
260 if (lock_log_file
== LOCK_LOG_FILE
) {
262 ReleaseMutex(log_mutex
);
263 #elif defined(OS_POSIX)
264 pthread_mutex_unlock(&log_mutex
);
271 // The lock is used if log file locking is false. It helps us avoid problems
272 // with multiple threads writing to the log file at the same time. Use
273 // LockImpl directly instead of using Lock, because Lock makes logging calls.
274 static base::internal::LockImpl
* log_lock
;
276 // When we don't use a lock, we are using a global mutex. We need to do this
277 // because LockFileEx is not thread safe.
279 static MutexHandle log_mutex
;
280 #elif defined(OS_POSIX)
281 static pthread_mutex_t log_mutex
;
284 static bool initialized
;
285 static LogLockingState lock_log_file
;
289 bool LoggingLock::initialized
= false;
291 base::internal::LockImpl
* LoggingLock::log_lock
= NULL
;
293 LogLockingState
LoggingLock::lock_log_file
= LOCK_LOG_FILE
;
297 MutexHandle
LoggingLock::log_mutex
= NULL
;
298 #elif defined(OS_POSIX)
299 pthread_mutex_t
LoggingLock::log_mutex
= PTHREAD_MUTEX_INITIALIZER
;
302 // Called by logging functions to ensure that debug_file is initialized
303 // and can be used for writing. Returns false if the file could not be
304 // initialized. debug_file will be NULL in this case.
305 bool InitializeLogFileHandle() {
309 if (!log_file_name
) {
310 // Nobody has called InitLogging to specify a debug log file, so here we
311 // initialize the log file name to a default.
312 log_file_name
= new PathString(GetDefaultLogFile());
315 if (logging_destination
== LOG_ONLY_TO_FILE
||
316 logging_destination
== LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG
) {
318 log_file
= CreateFile(log_file_name
->c_str(), GENERIC_WRITE
,
319 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
320 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
321 if (log_file
== INVALID_HANDLE_VALUE
|| log_file
== NULL
) {
322 // try the current directory
323 log_file
= CreateFile(L
".\\debug.log", GENERIC_WRITE
,
324 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
325 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
326 if (log_file
== INVALID_HANDLE_VALUE
|| log_file
== NULL
) {
331 SetFilePointer(log_file
, 0, 0, FILE_END
);
332 #elif defined(OS_POSIX)
333 log_file
= fopen(log_file_name
->c_str(), "a");
334 if (log_file
== NULL
)
345 bool BaseInitLoggingImpl(const PathChar
* new_log_file
,
346 LoggingDestination logging_dest
,
347 LogLockingState lock_log
,
348 OldFileDeletionState delete_old
,
349 DcheckState dcheck_state
) {
350 g_dcheck_state
= dcheck_state
;
351 // TODO(bbudge) Hook this up to NaCl logging.
352 #if !defined(OS_NACL)
353 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
354 // Don't bother initializing g_vlog_info unless we use one of the
356 if (command_line
->HasSwitch(switches::kV
) ||
357 command_line
->HasSwitch(switches::kVModule
)) {
358 // NOTE: If g_vlog_info has already been initialized, it might be in use
359 // by another thread. Don't delete the old VLogInfo, just create a second
360 // one. We keep track of both to avoid memory leak warnings.
361 CHECK(!g_vlog_info_prev
);
362 g_vlog_info_prev
= g_vlog_info
;
365 new VlogInfo(command_line
->GetSwitchValueASCII(switches::kV
),
366 command_line
->GetSwitchValueASCII(switches::kVModule
),
370 LoggingLock::Init(lock_log
, new_log_file
);
372 LoggingLock logging_lock
;
375 // calling InitLogging twice or after some log call has already opened the
376 // default log file will re-initialize to the new options
381 logging_destination
= logging_dest
;
383 // ignore file options if logging is disabled or only to system
384 if (logging_destination
== LOG_NONE
||
385 logging_destination
== LOG_ONLY_TO_SYSTEM_DEBUG_LOG
)
389 log_file_name
= new PathString();
390 *log_file_name
= new_log_file
;
391 if (delete_old
== DELETE_OLD_LOG_FILE
)
392 DeleteFilePath(*log_file_name
);
394 return InitializeLogFileHandle();
397 #endif // !defined(OS_NACL)
400 void SetMinLogLevel(int level
) {
401 min_log_level
= std::min(LOG_ERROR_REPORT
, level
);
404 int GetMinLogLevel() {
405 return min_log_level
;
408 int GetVlogVerbosity() {
409 return std::max(-1, LOG_INFO
- GetMinLogLevel());
412 int GetVlogLevelHelper(const char* file
, size_t N
) {
414 // Note: g_vlog_info may change on a different thread during startup
415 // (but will always be valid or NULL).
416 VlogInfo
* vlog_info
= g_vlog_info
;
418 vlog_info
->GetVlogLevel(base::StringPiece(file
, N
- 1)) :
422 void SetLogItems(bool enable_process_id
, bool enable_thread_id
,
423 bool enable_timestamp
, bool enable_tickcount
) {
424 log_process_id
= enable_process_id
;
425 log_thread_id
= enable_thread_id
;
426 log_timestamp
= enable_timestamp
;
427 log_tickcount
= enable_tickcount
;
430 void SetShowErrorDialogs(bool enable_dialogs
) {
431 show_error_dialogs
= enable_dialogs
;
434 void SetLogAssertHandler(LogAssertHandlerFunction handler
) {
435 log_assert_handler
= handler
;
438 void SetLogReportHandler(LogReportHandlerFunction handler
) {
439 log_report_handler
= handler
;
442 void SetLogMessageHandler(LogMessageHandlerFunction handler
) {
443 log_message_handler
= handler
;
446 LogMessageHandlerFunction
GetLogMessageHandler() {
447 return log_message_handler
;
450 // MSVC doesn't like complex extern templates and DLLs.
451 #if !defined(COMPILER_MSVC)
452 // Explicit instantiations for commonly used comparisons.
453 template std::string
* MakeCheckOpString
<int, int>(
454 const int&, const int&, const char* names
);
455 template std::string
* MakeCheckOpString
<unsigned long, unsigned long>(
456 const unsigned long&, const unsigned long&, const char* names
);
457 template std::string
* MakeCheckOpString
<unsigned long, unsigned int>(
458 const unsigned long&, const unsigned int&, const char* names
);
459 template std::string
* MakeCheckOpString
<unsigned int, unsigned long>(
460 const unsigned int&, const unsigned long&, const char* names
);
461 template std::string
* MakeCheckOpString
<std::string
, std::string
>(
462 const std::string
&, const std::string
&, const char* name
);
465 // Displays a message box to the user with the error message in it.
466 // Used for fatal messages, where we close the app simultaneously.
467 // This is for developers only; we don't use this in circumstances
468 // (like release builds) where users could see it, since users don't
469 // understand these messages anyway.
470 void DisplayDebugMessageInDialog(const std::string
& str
) {
474 if (!show_error_dialogs
)
478 // For Windows programs, it's possible that the message loop is
479 // messed up on a fatal error, and creating a MessageBox will cause
480 // that message loop to be run. Instead, we try to spawn another
481 // process that displays its command line. We look for "Debug
482 // Message.exe" in the same directory as the application. If it
483 // exists, we use it, otherwise, we use a regular message box.
484 wchar_t prog_name
[MAX_PATH
];
485 GetModuleFileNameW(NULL
, prog_name
, MAX_PATH
);
486 wchar_t* backslash
= wcsrchr(prog_name
, '\\');
489 wcscat_s(prog_name
, MAX_PATH
, L
"debug_message.exe");
491 std::wstring cmdline
= UTF8ToWide(str
);
495 STARTUPINFO startup_info
;
496 memset(&startup_info
, 0, sizeof(startup_info
));
497 startup_info
.cb
= sizeof(startup_info
);
499 PROCESS_INFORMATION process_info
;
500 if (CreateProcessW(prog_name
, &cmdline
[0], NULL
, NULL
, false, 0, NULL
,
501 NULL
, &startup_info
, &process_info
)) {
502 WaitForSingleObject(process_info
.hProcess
, INFINITE
);
503 CloseHandle(process_info
.hThread
);
504 CloseHandle(process_info
.hProcess
);
506 // debug process broken, let's just do a message box
507 MessageBoxW(NULL
, &cmdline
[0], L
"Fatal error",
508 MB_OK
| MB_ICONHAND
| MB_TOPMOST
);
511 // We intentionally don't implement a dialog on other platforms.
512 // You can just look at stderr.
517 LogMessage::SaveLastError::SaveLastError() : last_error_(::GetLastError()) {
520 LogMessage::SaveLastError::~SaveLastError() {
521 ::SetLastError(last_error_
);
523 #endif // defined(OS_WIN)
525 LogMessage::LogMessage(const char* file
, int line
, LogSeverity severity
,
527 : severity_(severity
), file_(file
), line_(line
) {
531 LogMessage::LogMessage(const char* file
, int line
)
532 : severity_(LOG_INFO
), file_(file
), line_(line
) {
536 LogMessage::LogMessage(const char* file
, int line
, LogSeverity severity
)
537 : severity_(severity
), file_(file
), line_(line
) {
541 LogMessage::LogMessage(const char* file
, int line
, std::string
* result
)
542 : severity_(LOG_FATAL
), file_(file
), line_(line
) {
544 stream_
<< "Check failed: " << *result
;
548 LogMessage::LogMessage(const char* file
, int line
, LogSeverity severity
,
550 : severity_(severity
), file_(file
), line_(line
) {
552 stream_
<< "Check failed: " << *result
;
556 LogMessage::~LogMessage() {
557 // TODO(port): enable stacktrace generation on LOG_FATAL once backtrace are
558 // working in Android.
559 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_NACL)
560 if (severity_
== LOG_FATAL
) {
561 // Include a stack trace on a fatal.
562 base::debug::StackTrace trace
;
563 stream_
<< std::endl
; // Newline to separate from log message.
564 trace
.OutputToStream(&stream_
);
567 stream_
<< std::endl
;
568 std::string
str_newline(stream_
.str());
570 // Give any log message handler first dibs on the message.
571 if (log_message_handler
&& log_message_handler(severity_
, file_
, line_
,
572 message_start_
, str_newline
)) {
573 // The handler took care of it, no further processing.
577 if (logging_destination
== LOG_ONLY_TO_SYSTEM_DEBUG_LOG
||
578 logging_destination
== LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG
) {
580 OutputDebugStringA(str_newline
.c_str());
581 #elif defined(OS_ANDROID)
582 android_LogPriority priority
= ANDROID_LOG_UNKNOWN
;
585 priority
= ANDROID_LOG_INFO
;
588 priority
= ANDROID_LOG_WARN
;
591 case LOG_ERROR_REPORT
:
592 priority
= ANDROID_LOG_ERROR
;
595 priority
= ANDROID_LOG_FATAL
;
598 __android_log_write(priority
, "chromium", str_newline
.c_str());
600 fprintf(stderr
, "%s", str_newline
.c_str());
602 } else if (severity_
>= kAlwaysPrintErrorLevel
) {
603 // When we're only outputting to a log file, above a certain log level, we
604 // should still output to stderr so that we can better detect and diagnose
605 // problems with unit tests, especially on the buildbots.
606 fprintf(stderr
, "%s", str_newline
.c_str());
610 // We can have multiple threads and/or processes, so try to prevent them
611 // from clobbering each other's writes.
612 // If the client app did not call InitLogging, and the lock has not
613 // been created do it now. We do this on demand, but if two threads try
614 // to do this at the same time, there will be a race condition to create
615 // the lock. This is why InitLogging should be called from the main
616 // thread at the beginning of execution.
617 LoggingLock::Init(LOCK_LOG_FILE
, NULL
);
619 if (logging_destination
!= LOG_NONE
&&
620 logging_destination
!= LOG_ONLY_TO_SYSTEM_DEBUG_LOG
) {
621 LoggingLock logging_lock
;
622 if (InitializeLogFileHandle()) {
624 SetFilePointer(log_file
, 0, 0, SEEK_END
);
627 static_cast<const void*>(str_newline
.c_str()),
628 static_cast<DWORD
>(str_newline
.length()),
632 fprintf(log_file
, "%s", str_newline
.c_str());
638 if (severity_
== LOG_FATAL
) {
639 // display a message or break into the debugger on a fatal error
640 if (base::debug::BeingDebugged()) {
641 base::debug::BreakDebugger();
643 if (log_assert_handler
) {
644 // make a copy of the string for the handler out of paranoia
645 log_assert_handler(std::string(stream_
.str()));
647 // Don't use the string with the newline, get a fresh version to send to
648 // the debug message process. We also don't display assertions to the
649 // user in release mode. The enduser can't do anything with this
650 // information, and displaying message boxes when the application is
651 // hosed can cause additional problems.
653 DisplayDebugMessageInDialog(stream_
.str());
655 // Crash the process to generate a dump.
656 base::debug::BreakDebugger();
659 } else if (severity_
== LOG_ERROR_REPORT
) {
660 // We are here only if the user runs with --enable-dcheck in release mode.
661 if (log_report_handler
) {
662 log_report_handler(std::string(stream_
.str()));
664 DisplayDebugMessageInDialog(stream_
.str());
669 // writes the common header info to the stream
670 void LogMessage::Init(const char* file
, int line
) {
671 base::StringPiece
filename(file
);
672 size_t last_slash_pos
= filename
.find_last_of("\\/");
673 if (last_slash_pos
!= base::StringPiece::npos
)
674 filename
.remove_prefix(last_slash_pos
+ 1);
676 // TODO(darin): It might be nice if the columns were fixed width.
680 stream_
<< CurrentProcessId() << ':';
682 stream_
<< base::PlatformThread::CurrentId() << ':';
684 time_t t
= time(NULL
);
685 struct tm local_time
= {0};
687 localtime_s(&local_time
, &t
);
689 localtime_r(&t
, &local_time
);
691 struct tm
* tm_time
= &local_time
;
692 stream_
<< std::setfill('0')
693 << std::setw(2) << 1 + tm_time
->tm_mon
694 << std::setw(2) << tm_time
->tm_mday
696 << std::setw(2) << tm_time
->tm_hour
697 << std::setw(2) << tm_time
->tm_min
698 << std::setw(2) << tm_time
->tm_sec
702 stream_
<< TickCount() << ':';
704 stream_
<< log_severity_names
[severity_
];
706 stream_
<< "VERBOSE" << -severity_
;
708 stream_
<< ":" << filename
<< "(" << line
<< ")] ";
710 message_start_
= stream_
.tellp();
714 // This has already been defined in the header, but defining it again as DWORD
715 // ensures that the type used in the header is equivalent to DWORD. If not,
716 // the redefinition is a compile error.
717 typedef DWORD SystemErrorCode
;
720 SystemErrorCode
GetLastSystemErrorCode() {
722 return ::GetLastError();
723 #elif defined(OS_POSIX)
726 #error Not implemented
731 Win32ErrorLogMessage::Win32ErrorLogMessage(const char* file
,
733 LogSeverity severity
,
738 log_message_(file
, line
, severity
) {
741 Win32ErrorLogMessage::Win32ErrorLogMessage(const char* file
,
743 LogSeverity severity
,
747 log_message_(file
, line
, severity
) {
750 Win32ErrorLogMessage::~Win32ErrorLogMessage() {
751 const int error_message_buffer_size
= 256;
752 char msgbuf
[error_message_buffer_size
];
753 DWORD flags
= FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
;
756 hmod
= GetModuleHandleA(module_
);
758 flags
|= FORMAT_MESSAGE_FROM_HMODULE
;
760 // This makes a nested Win32ErrorLogMessage. It will have module_ of NULL
761 // so it will not call GetModuleHandle, so recursive errors are
763 DPLOG(WARNING
) << "Couldn't open module " << module_
764 << " for error message query";
769 DWORD len
= FormatMessageA(flags
,
774 sizeof(msgbuf
) / sizeof(msgbuf
[0]),
778 isspace(static_cast<unsigned char>(msgbuf
[len
- 1]))) {
781 stream() << ": " << msgbuf
;
783 stream() << ": Error " << GetLastError() << " while retrieving error "
787 #elif defined(OS_POSIX)
788 ErrnoLogMessage::ErrnoLogMessage(const char* file
,
790 LogSeverity severity
,
793 log_message_(file
, line
, severity
) {
796 ErrnoLogMessage::~ErrnoLogMessage() {
797 stream() << ": " << safe_strerror(err_
);
801 void CloseLogFile() {
802 LoggingLock logging_lock
;
811 void RawLog(int level
, const char* message
) {
812 if (level
>= min_log_level
) {
813 size_t bytes_written
= 0;
814 const size_t message_len
= strlen(message
);
816 while (bytes_written
< message_len
) {
818 write(STDERR_FILENO
, message
+ bytes_written
,
819 message_len
- bytes_written
));
821 // Give up, nothing we can do now.
827 if (message_len
> 0 && message
[message_len
- 1] != '\n') {
829 rv
= HANDLE_EINTR(write(STDERR_FILENO
, "\n", 1));
831 // Give up, nothing we can do now.
838 if (level
== LOG_FATAL
)
839 base::debug::BreakDebugger();
842 // This was defined at the beginning of this file.
845 } // namespace logging
847 std::ostream
& operator<<(std::ostream
& out
, const wchar_t* wstr
) {
848 return out
<< WideToUTF8(std::wstring(wstr
));