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 #include "base/files/file_path.h"
11 #include "base/files/file_util.h"
12 typedef HANDLE FileHandle
;
13 typedef HANDLE MutexHandle
;
14 // Windows warns on using write(). It prefers _write().
15 #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count))
16 // Windows doesn't define STDERR_FILENO. Define it here.
17 #define STDERR_FILENO 2
18 #elif defined(OS_MACOSX)
19 #include <mach/mach.h>
20 #include <mach/mach_time.h>
21 #include <mach-o/dyld.h>
22 #elif defined(OS_POSIX)
24 #include <sys/time.h> // timespec doesn't seem to be in <time.h>
26 #include <sys/syscall.h>
38 #define MAX_PATH PATH_MAX
39 typedef FILE* FileHandle
;
40 typedef pthread_mutex_t
* MutexHandle
;
50 #include "base/base_switches.h"
51 #include "base/command_line.h"
52 #include "base/debug/alias.h"
53 #include "base/debug/debugger.h"
54 #include "base/debug/stack_trace.h"
55 #include "base/posix/eintr_wrapper.h"
56 #include "base/strings/string_piece.h"
57 #include "base/strings/string_util.h"
58 #include "base/strings/stringprintf.h"
59 #include "base/strings/utf_string_conversions.h"
60 #include "base/synchronization/lock_impl.h"
61 #include "base/threading/platform_thread.h"
62 #include "base/vlog.h"
64 #include "base/posix/safe_strerror.h"
67 #if defined(OS_ANDROID)
68 #include <android/log.h>
75 VlogInfo
* g_vlog_info
= nullptr;
76 VlogInfo
* g_vlog_info_prev
= nullptr;
78 const char* const log_severity_names
[LOG_NUM_SEVERITIES
] = {
79 "INFO", "WARNING", "ERROR", "FATAL" };
81 const char* log_severity_name(int severity
) {
82 if (severity
>= 0 && severity
< LOG_NUM_SEVERITIES
)
83 return log_severity_names
[severity
];
87 int g_min_log_level
= 0;
89 LoggingDestination g_logging_destination
= LOG_DEFAULT
;
91 // For LOG_ERROR and above, always print to stderr.
92 const int kAlwaysPrintErrorLevel
= LOG_ERROR
;
94 // Which log file to use? This is initialized by InitLogging or
95 // will be lazily initialized to the default value when it is
98 typedef std::wstring PathString
;
100 typedef std::string PathString
;
102 PathString
* g_log_file_name
= nullptr;
104 // This file is lazily opened and the handle may be nullptr
105 FileHandle g_log_file
= nullptr;
107 // What should be prepended to each message?
108 bool g_log_process_id
= false;
109 bool g_log_thread_id
= false;
110 bool g_log_timestamp
= true;
111 bool g_log_tickcount
= false;
113 // Should we pop up fatal debug messages in a dialog?
114 bool show_error_dialogs
= false;
116 // An assert handler override specified by the client to be called instead of
117 // the debug message dialog and process termination.
118 LogAssertHandlerFunction log_assert_handler
= nullptr;
119 // A log message handler that gets notified of every log message we process.
120 LogMessageHandlerFunction log_message_handler
= nullptr;
122 // Helper functions to wrap platform differences.
124 int32
CurrentProcessId() {
126 return GetCurrentProcessId();
127 #elif defined(OS_POSIX)
134 return GetTickCount();
135 #elif defined(OS_MACOSX)
136 return mach_absolute_time();
137 #elif defined(OS_NACL)
138 // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h
139 // So we have to use clock() for now.
141 #elif defined(OS_POSIX)
143 clock_gettime(CLOCK_MONOTONIC
, &ts
);
145 uint64 absolute_micro
=
146 static_cast<int64
>(ts
.tv_sec
) * 1000000 +
147 static_cast<int64
>(ts
.tv_nsec
) / 1000;
149 return absolute_micro
;
153 void DeleteFilePath(const PathString
& log_name
) {
155 DeleteFile(log_name
.c_str());
156 #elif defined(OS_NACL)
157 // Do nothing; unlink() isn't supported on NaCl.
159 unlink(log_name
.c_str());
163 PathString
GetDefaultLogFile() {
165 // On Windows we use the same path as the exe.
166 wchar_t module_name
[MAX_PATH
];
167 GetModuleFileName(nullptr, module_name
, MAX_PATH
);
169 PathString log_name
= module_name
;
170 PathString::size_type last_backslash
= log_name
.rfind('\\', log_name
.size());
171 if (last_backslash
!= PathString::npos
)
172 log_name
.erase(last_backslash
+ 1);
173 log_name
+= L
"debug.log";
175 #elif defined(OS_POSIX)
176 // On other platforms we just use the current directory.
177 return PathString("debug.log");
181 // We don't need locks on Windows for atomically appending to files. The OS
182 // provides this functionality.
184 // This class acts as a wrapper for locking the logging files.
185 // LoggingLock::Init() should be called from the main thread before any logging
186 // is done. Then whenever logging, be sure to have a local LoggingLock
187 // instance on the stack. This will ensure that the lock is unlocked upon
188 // exiting the frame.
189 // LoggingLocks can not be nested.
200 static void Init(LogLockingState lock_log
, const PathChar
* new_log_file
) {
203 lock_log_file
= lock_log
;
205 if (lock_log_file
!= LOCK_LOG_FILE
)
206 log_lock
= new base::internal::LockImpl();
212 static void LockLogging() {
213 if (lock_log_file
== LOCK_LOG_FILE
) {
214 #if defined(OS_POSIX)
215 pthread_mutex_lock(&log_mutex
);
223 static void UnlockLogging() {
224 if (lock_log_file
== LOCK_LOG_FILE
) {
225 #if defined(OS_POSIX)
226 pthread_mutex_unlock(&log_mutex
);
233 // The lock is used if log file locking is false. It helps us avoid problems
234 // with multiple threads writing to the log file at the same time. Use
235 // LockImpl directly instead of using Lock, because Lock makes logging calls.
236 static base::internal::LockImpl
* log_lock
;
238 // When we don't use a lock, we are using a global mutex. We need to do this
239 // because LockFileEx is not thread safe.
240 #if defined(OS_POSIX)
241 static pthread_mutex_t log_mutex
;
244 static bool initialized
;
245 static LogLockingState lock_log_file
;
249 bool LoggingLock::initialized
= false;
251 base::internal::LockImpl
* LoggingLock::log_lock
= nullptr;
253 LogLockingState
LoggingLock::lock_log_file
= LOCK_LOG_FILE
;
255 #if defined(OS_POSIX)
256 pthread_mutex_t
LoggingLock::log_mutex
= PTHREAD_MUTEX_INITIALIZER
;
261 // Called by logging functions to ensure that |g_log_file| is initialized
262 // and can be used for writing. Returns false if the file could not be
263 // initialized. |g_log_file| will be nullptr in this case.
264 bool InitializeLogFileHandle() {
268 if (!g_log_file_name
) {
269 // Nobody has called InitLogging to specify a debug log file, so here we
270 // initialize the log file name to a default.
271 g_log_file_name
= new PathString(GetDefaultLogFile());
274 if ((g_logging_destination
& LOG_TO_FILE
) != 0) {
276 // The FILE_APPEND_DATA access mask ensures that the file is atomically
277 // appended to across accesses from multiple threads.
278 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364399(v=vs.85).aspx
279 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
280 g_log_file
= CreateFile(g_log_file_name
->c_str(), FILE_APPEND_DATA
,
281 FILE_SHARE_READ
| FILE_SHARE_WRITE
, nullptr,
282 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, nullptr);
283 if (g_log_file
== INVALID_HANDLE_VALUE
|| g_log_file
== nullptr) {
284 // try the current directory
285 base::FilePath file_path
;
286 if (!base::GetCurrentDirectory(&file_path
))
289 *g_log_file_name
= file_path
.Append(
290 FILE_PATH_LITERAL("debug.log")).value();
292 g_log_file
= CreateFile(g_log_file_name
->c_str(), FILE_APPEND_DATA
,
293 FILE_SHARE_READ
| FILE_SHARE_WRITE
, nullptr,
294 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, nullptr);
295 if (g_log_file
== INVALID_HANDLE_VALUE
|| g_log_file
== nullptr) {
296 g_log_file
= nullptr;
300 #elif defined(OS_POSIX)
301 g_log_file
= fopen(g_log_file_name
->c_str(), "a");
302 if (g_log_file
== nullptr)
310 void CloseFile(FileHandle log
) {
318 void CloseLogFileUnlocked() {
322 CloseFile(g_log_file
);
323 g_log_file
= nullptr;
328 LoggingSettings::LoggingSettings()
329 : logging_dest(LOG_DEFAULT
),
331 lock_log(LOCK_LOG_FILE
),
332 delete_old(APPEND_TO_OLD_LOG_FILE
) {}
334 bool BaseInitLoggingImpl(const LoggingSettings
& settings
) {
336 // Can log only to the system debug log.
337 CHECK_EQ(settings
.logging_dest
& ~LOG_TO_SYSTEM_DEBUG_LOG
, 0);
339 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
340 // Don't bother initializing |g_vlog_info| unless we use one of the
342 if (command_line
->HasSwitch(switches::kV
) ||
343 command_line
->HasSwitch(switches::kVModule
)) {
344 // NOTE: If |g_vlog_info| has already been initialized, it might be in use
345 // by another thread. Don't delete the old VLogInfo, just create a second
346 // one. We keep track of both to avoid memory leak warnings.
347 CHECK(!g_vlog_info_prev
);
348 g_vlog_info_prev
= g_vlog_info
;
351 new VlogInfo(command_line
->GetSwitchValueASCII(switches::kV
),
352 command_line
->GetSwitchValueASCII(switches::kVModule
),
356 g_logging_destination
= settings
.logging_dest
;
358 // ignore file options unless logging to file is set.
359 if ((g_logging_destination
& LOG_TO_FILE
) == 0)
363 LoggingLock::Init(settings
.lock_log
, settings
.log_file
);
364 LoggingLock logging_lock
;
367 // Calling InitLogging twice or after some log call has already opened the
368 // default log file will re-initialize to the new options.
369 CloseLogFileUnlocked();
371 if (!g_log_file_name
)
372 g_log_file_name
= new PathString();
373 *g_log_file_name
= settings
.log_file
;
374 if (settings
.delete_old
== DELETE_OLD_LOG_FILE
)
375 DeleteFilePath(*g_log_file_name
);
377 return InitializeLogFileHandle();
380 void SetMinLogLevel(int level
) {
381 g_min_log_level
= std::min(LOG_FATAL
, level
);
384 int GetMinLogLevel() {
385 return g_min_log_level
;
388 int GetVlogVerbosity() {
389 return std::max(-1, LOG_INFO
- GetMinLogLevel());
392 int GetVlogLevelHelper(const char* file
, size_t N
) {
394 // Note: |g_vlog_info| may change on a different thread during startup
395 // (but will always be valid or nullptr).
396 VlogInfo
* vlog_info
= g_vlog_info
;
398 vlog_info
->GetVlogLevel(base::StringPiece(file
, N
- 1)) :
402 void SetLogItems(bool enable_process_id
, bool enable_thread_id
,
403 bool enable_timestamp
, bool enable_tickcount
) {
404 g_log_process_id
= enable_process_id
;
405 g_log_thread_id
= enable_thread_id
;
406 g_log_timestamp
= enable_timestamp
;
407 g_log_tickcount
= enable_tickcount
;
410 void SetShowErrorDialogs(bool enable_dialogs
) {
411 show_error_dialogs
= enable_dialogs
;
414 void SetLogAssertHandler(LogAssertHandlerFunction handler
) {
415 log_assert_handler
= handler
;
418 void SetLogMessageHandler(LogMessageHandlerFunction handler
) {
419 log_message_handler
= handler
;
422 LogMessageHandlerFunction
GetLogMessageHandler() {
423 return log_message_handler
;
426 // Explicit instantiations for commonly used comparisons.
427 template std::string
* MakeCheckOpString
<int, int>(
428 const int&, const int&, const char* names
);
429 template std::string
* MakeCheckOpString
<unsigned long, unsigned long>(
430 const unsigned long&, const unsigned long&, const char* names
);
431 template std::string
* MakeCheckOpString
<unsigned long, unsigned int>(
432 const unsigned long&, const unsigned int&, const char* names
);
433 template std::string
* MakeCheckOpString
<unsigned int, unsigned long>(
434 const unsigned int&, const unsigned long&, const char* names
);
435 template std::string
* MakeCheckOpString
<std::string
, std::string
>(
436 const std::string
&, const std::string
&, const char* name
);
439 // Displays a message box to the user with the error message in it.
440 // Used for fatal messages, where we close the app simultaneously.
441 // This is for developers only; we don't use this in circumstances
442 // (like release builds) where users could see it, since users don't
443 // understand these messages anyway.
444 void DisplayDebugMessageInDialog(const std::string
& str
) {
448 if (!show_error_dialogs
)
452 // For Windows programs, it's possible that the message loop is
453 // messed up on a fatal error, and creating a MessageBox will cause
454 // that message loop to be run. Instead, we try to spawn another
455 // process that displays its command line. We look for "Debug
456 // Message.exe" in the same directory as the application. If it
457 // exists, we use it, otherwise, we use a regular message box.
458 wchar_t prog_name
[MAX_PATH
];
459 GetModuleFileNameW(nullptr, prog_name
, MAX_PATH
);
460 wchar_t* backslash
= wcsrchr(prog_name
, '\\');
463 wcscat_s(prog_name
, MAX_PATH
, L
"debug_message.exe");
465 std::wstring cmdline
= base::UTF8ToWide(str
);
469 STARTUPINFO startup_info
;
470 memset(&startup_info
, 0, sizeof(startup_info
));
471 startup_info
.cb
= sizeof(startup_info
);
473 PROCESS_INFORMATION process_info
;
474 if (CreateProcessW(prog_name
, &cmdline
[0], nullptr, nullptr, false, 0,
475 nullptr, nullptr, &startup_info
, &process_info
)) {
476 WaitForSingleObject(process_info
.hProcess
, INFINITE
);
477 CloseHandle(process_info
.hThread
);
478 CloseHandle(process_info
.hProcess
);
480 // debug process broken, let's just do a message box
481 MessageBoxW(nullptr, &cmdline
[0], L
"Fatal error",
482 MB_OK
| MB_ICONHAND
| MB_TOPMOST
);
485 // We intentionally don't implement a dialog on other platforms.
486 // You can just look at stderr.
487 #endif // defined(OS_WIN)
489 #endif // !defined(NDEBUG)
492 LogMessage::SaveLastError::SaveLastError() : last_error_(::GetLastError()) {
495 LogMessage::SaveLastError::~SaveLastError() {
496 ::SetLastError(last_error_
);
498 #endif // defined(OS_WIN)
500 LogMessage::LogMessage(const char* file
, int line
, LogSeverity severity
)
501 : severity_(severity
), file_(file
), line_(line
) {
505 LogMessage::LogMessage(const char* file
, int line
, const char* condition
)
506 : severity_(LOG_FATAL
), file_(file
), line_(line
) {
508 stream_
<< "Check failed: " << condition
<< ". ";
511 LogMessage::LogMessage(const char* file
, int line
, std::string
* result
)
512 : severity_(LOG_FATAL
), file_(file
), line_(line
) {
514 stream_
<< "Check failed: " << *result
;
518 LogMessage::LogMessage(const char* file
, int line
, LogSeverity severity
,
520 : severity_(severity
), file_(file
), line_(line
) {
522 stream_
<< "Check failed: " << *result
;
526 LogMessage::~LogMessage() {
527 #if !defined(OFFICIAL_BUILD) && !defined(OS_NACL) && !defined(__UCLIBC__)
528 if (severity_
== LOG_FATAL
&& !base::debug::BeingDebugged()) {
529 // Include a stack trace on a fatal, unless a debugger is attached.
530 base::debug::StackTrace trace
;
531 stream_
<< std::endl
; // Newline to separate from log message.
532 trace
.OutputToStream(&stream_
);
535 stream_
<< std::endl
;
536 std::string
str_newline(stream_
.str());
538 // Give any log message handler first dibs on the message.
539 if (log_message_handler
&&
540 log_message_handler(severity_
, file_
, line_
,
541 message_start_
, str_newline
)) {
542 // The handler took care of it, no further processing.
546 if ((g_logging_destination
& LOG_TO_SYSTEM_DEBUG_LOG
) != 0) {
548 OutputDebugStringA(str_newline
.c_str());
549 #elif defined(OS_ANDROID)
550 android_LogPriority priority
=
551 (severity_
< 0) ? ANDROID_LOG_VERBOSE
: ANDROID_LOG_UNKNOWN
;
554 priority
= ANDROID_LOG_INFO
;
557 priority
= ANDROID_LOG_WARN
;
560 priority
= ANDROID_LOG_ERROR
;
563 priority
= ANDROID_LOG_FATAL
;
566 __android_log_write(priority
, "chromium", str_newline
.c_str());
568 ignore_result(fwrite(str_newline
.data(), str_newline
.size(), 1, stderr
));
570 } else if (severity_
>= kAlwaysPrintErrorLevel
) {
571 // When we're only outputting to a log file, above a certain log level, we
572 // should still output to stderr so that we can better detect and diagnose
573 // problems with unit tests, especially on the buildbots.
574 ignore_result(fwrite(str_newline
.data(), str_newline
.size(), 1, stderr
));
579 if ((g_logging_destination
& LOG_TO_FILE
) != 0) {
580 // We can have multiple threads and/or processes, so try to prevent them
581 // from clobbering each other's writes.
582 // If the client app did not call InitLogging, and the lock has not
583 // been created do it now. We do this on demand, but if two threads try
584 // to do this at the same time, there will be a race condition to create
585 // the lock. This is why InitLogging should be called from the main
586 // thread at the beginning of execution.
588 LoggingLock::Init(LOCK_LOG_FILE
, nullptr);
589 LoggingLock logging_lock
;
591 if (InitializeLogFileHandle()) {
594 WriteFile(g_log_file
,
595 static_cast<const void*>(str_newline
.c_str()),
596 static_cast<DWORD
>(str_newline
.length()),
600 ignore_result(fwrite(
601 str_newline
.data(), str_newline
.size(), 1, g_log_file
));
607 if (severity_
== LOG_FATAL
) {
608 // Ensure the first characters of the string are on the stack so they
609 // are contained in minidumps for diagnostic purposes.
610 char str_stack
[1024];
611 str_newline
.copy(str_stack
, arraysize(str_stack
));
612 base::debug::Alias(str_stack
);
614 if (log_assert_handler
) {
615 // Make a copy of the string for the handler out of paranoia.
616 log_assert_handler(std::string(stream_
.str()));
618 // Don't use the string with the newline, get a fresh version to send to
619 // the debug message process. We also don't display assertions to the
620 // user in release mode. The enduser can't do anything with this
621 // information, and displaying message boxes when the application is
622 // hosed can cause additional problems.
624 if (!base::debug::BeingDebugged()) {
625 // Displaying a dialog is unnecessary when debugging and can complicate
627 DisplayDebugMessageInDialog(stream_
.str());
630 // Crash the process to generate a dump.
631 base::debug::BreakDebugger();
636 // writes the common header info to the stream
637 void LogMessage::Init(const char* file
, int line
) {
638 base::StringPiece
filename(file
);
639 size_t last_slash_pos
= filename
.find_last_of("\\/");
640 if (last_slash_pos
!= base::StringPiece::npos
)
641 filename
.remove_prefix(last_slash_pos
+ 1);
643 // TODO(darin): It might be nice if the columns were fixed width.
646 if (g_log_process_id
)
647 stream_
<< CurrentProcessId() << ':';
649 stream_
<< base::PlatformThread::CurrentId() << ':';
650 if (g_log_timestamp
) {
651 time_t t
= time(nullptr);
652 struct tm local_time
= {0};
654 localtime_s(&local_time
, &t
);
656 localtime_r(&t
, &local_time
);
658 struct tm
* tm_time
= &local_time
;
659 stream_
<< std::setfill('0')
660 << std::setw(2) << 1 + tm_time
->tm_mon
661 << std::setw(2) << tm_time
->tm_mday
663 << std::setw(2) << tm_time
->tm_hour
664 << std::setw(2) << tm_time
->tm_min
665 << std::setw(2) << tm_time
->tm_sec
669 stream_
<< TickCount() << ':';
671 stream_
<< log_severity_name(severity_
);
673 stream_
<< "VERBOSE" << -severity_
;
675 stream_
<< ":" << filename
<< "(" << line
<< ")] ";
677 message_start_
= stream_
.str().length();
681 // This has already been defined in the header, but defining it again as DWORD
682 // ensures that the type used in the header is equivalent to DWORD. If not,
683 // the redefinition is a compile error.
684 typedef DWORD SystemErrorCode
;
687 SystemErrorCode
GetLastSystemErrorCode() {
689 return ::GetLastError();
690 #elif defined(OS_POSIX)
693 #error Not implemented
698 BASE_EXPORT
std::string
SystemErrorCodeToString(SystemErrorCode error_code
) {
699 const int kErrorMessageBufferSize
= 256;
700 char msgbuf
[kErrorMessageBufferSize
];
701 DWORD flags
= FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
;
702 DWORD len
= FormatMessageA(flags
, nullptr, error_code
, 0, msgbuf
,
703 arraysize(msgbuf
), nullptr);
705 // Messages returned by system end with line breaks.
706 return base::CollapseWhitespaceASCII(msgbuf
, true) +
707 base::StringPrintf(" (0x%X)", error_code
);
709 return base::StringPrintf("Error (0x%X) while retrieving error. (0x%X)",
710 GetLastError(), error_code
);
712 #elif defined(OS_POSIX)
713 BASE_EXPORT
std::string
SystemErrorCodeToString(SystemErrorCode error_code
) {
714 return base::safe_strerror(error_code
);
717 #error Not implemented
718 #endif // defined(OS_WIN)
722 Win32ErrorLogMessage::Win32ErrorLogMessage(const char* file
,
724 LogSeverity severity
,
727 log_message_(file
, line
, severity
) {
730 Win32ErrorLogMessage::~Win32ErrorLogMessage() {
731 stream() << ": " << SystemErrorCodeToString(err_
);
732 // We're about to crash (CHECK). Put |err_| on the stack (by placing it in a
733 // field) and use Alias in hopes that it makes it into crash dumps.
734 DWORD last_error
= err_
;
735 base::debug::Alias(&last_error
);
737 #elif defined(OS_POSIX)
738 ErrnoLogMessage::ErrnoLogMessage(const char* file
,
740 LogSeverity severity
,
743 log_message_(file
, line
, severity
) {
746 ErrnoLogMessage::~ErrnoLogMessage() {
747 stream() << ": " << SystemErrorCodeToString(err_
);
749 #endif // defined(OS_WIN)
751 void CloseLogFile() {
753 LoggingLock logging_lock
;
755 CloseLogFileUnlocked();
758 void RawLog(int level
, const char* message
) {
759 if (level
>= g_min_log_level
) {
760 size_t bytes_written
= 0;
761 const size_t message_len
= strlen(message
);
763 while (bytes_written
< message_len
) {
765 write(STDERR_FILENO
, message
+ bytes_written
,
766 message_len
- bytes_written
));
768 // Give up, nothing we can do now.
774 if (message_len
> 0 && message
[message_len
- 1] != '\n') {
776 rv
= HANDLE_EINTR(write(STDERR_FILENO
, "\n", 1));
778 // Give up, nothing we can do now.
785 if (level
== LOG_FATAL
)
786 base::debug::BreakDebugger();
789 // This was defined at the beginning of this file.
793 bool IsLoggingToFileEnabled() {
794 return g_logging_destination
& LOG_TO_FILE
;
797 std::wstring
GetLogFileFullPath() {
799 return *g_log_file_name
;
800 return std::wstring();
804 BASE_EXPORT
void LogErrorNotReached(const char* file
, int line
) {
805 LogMessage(file
, line
, LOG_ERROR
).stream()
806 << "NOTREACHED() hit.";
809 } // namespace logging
811 std::ostream
& std::operator<<(std::ostream
& out
, const wchar_t* wstr
) {
812 return out
<< base::WideToUTF8(wstr
);