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/alias.h"
50 #include "base/debug/debugger.h"
51 #include "base/debug/stack_trace.h"
52 #include "base/posix/eintr_wrapper.h"
53 #include "base/strings/string_piece.h"
54 #include "base/strings/utf_string_conversions.h"
55 #include "base/synchronization/lock_impl.h"
56 #include "base/threading/platform_thread.h"
57 #include "base/vlog.h"
59 #include "base/safe_strerror_posix.h"
62 #if defined(OS_ANDROID)
63 #include <android/log.h>
68 DcheckState g_dcheck_state
= DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS
;
70 DcheckState
get_dcheck_state() {
71 return g_dcheck_state
;
74 void set_dcheck_state(DcheckState state
) {
75 g_dcheck_state
= state
;
80 VlogInfo
* g_vlog_info
= NULL
;
81 VlogInfo
* g_vlog_info_prev
= NULL
;
83 const char* const log_severity_names
[LOG_NUM_SEVERITIES
] = {
84 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" };
86 const char* log_severity_name(int severity
)
88 if (severity
>= 0 && severity
< LOG_NUM_SEVERITIES
)
89 return log_severity_names
[severity
];
93 int min_log_level
= 0;
95 LoggingDestination logging_destination
= LOG_DEFAULT
;
97 // For LOG_ERROR and above, always print to stderr.
98 const int kAlwaysPrintErrorLevel
= LOG_ERROR
;
100 // Which log file to use? This is initialized by InitLogging or
101 // will be lazily initialized to the default value when it is
104 typedef std::wstring PathString
;
106 typedef std::string PathString
;
108 PathString
* log_file_name
= NULL
;
110 // this file is lazily opened and the handle may be NULL
111 FileHandle log_file
= NULL
;
113 // what should be prepended to each message?
114 bool log_process_id
= false;
115 bool log_thread_id
= false;
116 bool log_timestamp
= true;
117 bool log_tickcount
= false;
119 // Should we pop up fatal debug messages in a dialog?
120 bool show_error_dialogs
= false;
122 // An assert handler override specified by the client to be called instead of
123 // the debug message dialog and process termination.
124 LogAssertHandlerFunction log_assert_handler
= NULL
;
125 // An report handler override specified by the client to be called instead of
126 // the debug message dialog.
127 LogReportHandlerFunction log_report_handler
= NULL
;
128 // A log message handler that gets notified of every log message we process.
129 LogMessageHandlerFunction log_message_handler
= NULL
;
131 // Helper functions to wrap platform differences.
133 int32
CurrentProcessId() {
135 return GetCurrentProcessId();
136 #elif defined(OS_POSIX)
143 return GetTickCount();
144 #elif defined(OS_MACOSX)
145 return mach_absolute_time();
146 #elif defined(OS_NACL)
147 // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h
148 // So we have to use clock() for now.
150 #elif defined(OS_POSIX)
152 clock_gettime(CLOCK_MONOTONIC
, &ts
);
154 uint64 absolute_micro
=
155 static_cast<int64
>(ts
.tv_sec
) * 1000000 +
156 static_cast<int64
>(ts
.tv_nsec
) / 1000;
158 return absolute_micro
;
162 void DeleteFilePath(const PathString
& log_name
) {
164 DeleteFile(log_name
.c_str());
165 #elif defined (OS_NACL)
166 // Do nothing; unlink() isn't supported on NaCl.
168 unlink(log_name
.c_str());
172 PathString
GetDefaultLogFile() {
174 // On Windows we use the same path as the exe.
175 wchar_t module_name
[MAX_PATH
];
176 GetModuleFileName(NULL
, module_name
, MAX_PATH
);
178 PathString log_file
= module_name
;
179 PathString::size_type last_backslash
=
180 log_file
.rfind('\\', log_file
.size());
181 if (last_backslash
!= PathString::npos
)
182 log_file
.erase(last_backslash
+ 1);
183 log_file
+= L
"debug.log";
185 #elif defined(OS_POSIX)
186 // On other platforms we just use the current directory.
187 return PathString("debug.log");
191 // This class acts as a wrapper for locking the logging files.
192 // LoggingLock::Init() should be called from the main thread before any logging
193 // is done. Then whenever logging, be sure to have a local LoggingLock
194 // instance on the stack. This will ensure that the lock is unlocked upon
195 // exiting the frame.
196 // LoggingLocks can not be nested.
207 static void Init(LogLockingState lock_log
, const PathChar
* new_log_file
) {
210 lock_log_file
= lock_log
;
211 if (lock_log_file
== LOCK_LOG_FILE
) {
214 std::wstring safe_name
;
216 safe_name
= new_log_file
;
218 safe_name
= GetDefaultLogFile();
219 // \ is not a legal character in mutex names so we replace \ with /
220 std::replace(safe_name
.begin(), safe_name
.end(), '\\', '/');
221 std::wstring
t(L
"Global\\");
223 log_mutex
= ::CreateMutex(NULL
, FALSE
, t
.c_str());
225 if (log_mutex
== NULL
) {
227 // Keep the error code for debugging
228 int error
= GetLastError(); // NOLINT
229 base::debug::BreakDebugger();
231 // Return nicely without putting initialized to true.
237 log_lock
= new base::internal::LockImpl();
243 static void LockLogging() {
244 if (lock_log_file
== LOCK_LOG_FILE
) {
246 ::WaitForSingleObject(log_mutex
, INFINITE
);
247 // WaitForSingleObject could have returned WAIT_ABANDONED. We don't
248 // abort the process here. UI tests might be crashy sometimes,
249 // and aborting the test binary only makes the problem worse.
250 // We also don't use LOG macros because that might lead to an infinite
251 // loop. For more info see http://crbug.com/18028.
252 #elif defined(OS_POSIX)
253 pthread_mutex_lock(&log_mutex
);
261 static void UnlockLogging() {
262 if (lock_log_file
== LOCK_LOG_FILE
) {
264 ReleaseMutex(log_mutex
);
265 #elif defined(OS_POSIX)
266 pthread_mutex_unlock(&log_mutex
);
273 // The lock is used if log file locking is false. It helps us avoid problems
274 // with multiple threads writing to the log file at the same time. Use
275 // LockImpl directly instead of using Lock, because Lock makes logging calls.
276 static base::internal::LockImpl
* log_lock
;
278 // When we don't use a lock, we are using a global mutex. We need to do this
279 // because LockFileEx is not thread safe.
281 static MutexHandle log_mutex
;
282 #elif defined(OS_POSIX)
283 static pthread_mutex_t log_mutex
;
286 static bool initialized
;
287 static LogLockingState lock_log_file
;
291 bool LoggingLock::initialized
= false;
293 base::internal::LockImpl
* LoggingLock::log_lock
= NULL
;
295 LogLockingState
LoggingLock::lock_log_file
= LOCK_LOG_FILE
;
299 MutexHandle
LoggingLock::log_mutex
= NULL
;
300 #elif defined(OS_POSIX)
301 pthread_mutex_t
LoggingLock::log_mutex
= PTHREAD_MUTEX_INITIALIZER
;
304 // Called by logging functions to ensure that debug_file is initialized
305 // and can be used for writing. Returns false if the file could not be
306 // initialized. debug_file will be NULL in this case.
307 bool InitializeLogFileHandle() {
311 if (!log_file_name
) {
312 // Nobody has called InitLogging to specify a debug log file, so here we
313 // initialize the log file name to a default.
314 log_file_name
= new PathString(GetDefaultLogFile());
317 if ((logging_destination
& LOG_TO_FILE
) != 0) {
319 log_file
= CreateFile(log_file_name
->c_str(), GENERIC_WRITE
,
320 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
321 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
322 if (log_file
== INVALID_HANDLE_VALUE
|| log_file
== NULL
) {
323 // try the current directory
324 log_file
= CreateFile(L
".\\debug.log", GENERIC_WRITE
,
325 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
326 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
327 if (log_file
== INVALID_HANDLE_VALUE
|| log_file
== NULL
) {
332 SetFilePointer(log_file
, 0, 0, FILE_END
);
333 #elif defined(OS_POSIX)
334 log_file
= fopen(log_file_name
->c_str(), "a");
335 if (log_file
== NULL
)
343 void CloseFile(FileHandle log
) {
351 void CloseLogFileUnlocked() {
361 LoggingSettings::LoggingSettings()
362 : logging_dest(LOG_DEFAULT
),
364 lock_log(LOCK_LOG_FILE
),
365 delete_old(APPEND_TO_OLD_LOG_FILE
),
366 dcheck_state(DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS
) {}
368 bool BaseInitLoggingImpl(const LoggingSettings
& settings
) {
370 // Can log only to the system debug log.
371 CHECK_EQ(settings
.logging_dest
& ~LOG_TO_SYSTEM_DEBUG_LOG
, 0);
373 g_dcheck_state
= settings
.dcheck_state
;
374 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
375 // Don't bother initializing g_vlog_info unless we use one of the
377 if (command_line
->HasSwitch(switches::kV
) ||
378 command_line
->HasSwitch(switches::kVModule
)) {
379 // NOTE: If g_vlog_info has already been initialized, it might be in use
380 // by another thread. Don't delete the old VLogInfo, just create a second
381 // one. We keep track of both to avoid memory leak warnings.
382 CHECK(!g_vlog_info_prev
);
383 g_vlog_info_prev
= g_vlog_info
;
386 new VlogInfo(command_line
->GetSwitchValueASCII(switches::kV
),
387 command_line
->GetSwitchValueASCII(switches::kVModule
),
391 logging_destination
= settings
.logging_dest
;
393 // ignore file options unless logging to file is set.
394 if ((logging_destination
& LOG_TO_FILE
) == 0)
397 LoggingLock::Init(settings
.lock_log
, settings
.log_file
);
398 LoggingLock logging_lock
;
400 // Calling InitLogging twice or after some log call has already opened the
401 // default log file will re-initialize to the new options.
402 CloseLogFileUnlocked();
405 log_file_name
= new PathString();
406 *log_file_name
= settings
.log_file
;
407 if (settings
.delete_old
== DELETE_OLD_LOG_FILE
)
408 DeleteFilePath(*log_file_name
);
410 return InitializeLogFileHandle();
413 void SetMinLogLevel(int level
) {
414 min_log_level
= std::min(LOG_ERROR_REPORT
, level
);
417 int GetMinLogLevel() {
418 return min_log_level
;
421 int GetVlogVerbosity() {
422 return std::max(-1, LOG_INFO
- GetMinLogLevel());
425 int GetVlogLevelHelper(const char* file
, size_t N
) {
427 // Note: g_vlog_info may change on a different thread during startup
428 // (but will always be valid or NULL).
429 VlogInfo
* vlog_info
= g_vlog_info
;
431 vlog_info
->GetVlogLevel(base::StringPiece(file
, N
- 1)) :
435 void SetLogItems(bool enable_process_id
, bool enable_thread_id
,
436 bool enable_timestamp
, bool enable_tickcount
) {
437 log_process_id
= enable_process_id
;
438 log_thread_id
= enable_thread_id
;
439 log_timestamp
= enable_timestamp
;
440 log_tickcount
= enable_tickcount
;
443 void SetShowErrorDialogs(bool enable_dialogs
) {
444 show_error_dialogs
= enable_dialogs
;
447 void SetLogAssertHandler(LogAssertHandlerFunction handler
) {
448 log_assert_handler
= handler
;
451 void SetLogReportHandler(LogReportHandlerFunction handler
) {
452 log_report_handler
= handler
;
455 void SetLogMessageHandler(LogMessageHandlerFunction handler
) {
456 log_message_handler
= handler
;
459 LogMessageHandlerFunction
GetLogMessageHandler() {
460 return log_message_handler
;
463 // MSVC doesn't like complex extern templates and DLLs.
464 #if !defined(COMPILER_MSVC)
465 // Explicit instantiations for commonly used comparisons.
466 template std::string
* MakeCheckOpString
<int, int>(
467 const int&, const int&, const char* names
);
468 template std::string
* MakeCheckOpString
<unsigned long, unsigned long>(
469 const unsigned long&, const unsigned long&, const char* names
);
470 template std::string
* MakeCheckOpString
<unsigned long, unsigned int>(
471 const unsigned long&, const unsigned int&, const char* names
);
472 template std::string
* MakeCheckOpString
<unsigned int, unsigned long>(
473 const unsigned int&, const unsigned long&, const char* names
);
474 template std::string
* MakeCheckOpString
<std::string
, std::string
>(
475 const std::string
&, const std::string
&, const char* name
);
478 // Displays a message box to the user with the error message in it.
479 // Used for fatal messages, where we close the app simultaneously.
480 // This is for developers only; we don't use this in circumstances
481 // (like release builds) where users could see it, since users don't
482 // understand these messages anyway.
483 void DisplayDebugMessageInDialog(const std::string
& str
) {
487 if (!show_error_dialogs
)
491 // For Windows programs, it's possible that the message loop is
492 // messed up on a fatal error, and creating a MessageBox will cause
493 // that message loop to be run. Instead, we try to spawn another
494 // process that displays its command line. We look for "Debug
495 // Message.exe" in the same directory as the application. If it
496 // exists, we use it, otherwise, we use a regular message box.
497 wchar_t prog_name
[MAX_PATH
];
498 GetModuleFileNameW(NULL
, prog_name
, MAX_PATH
);
499 wchar_t* backslash
= wcsrchr(prog_name
, '\\');
502 wcscat_s(prog_name
, MAX_PATH
, L
"debug_message.exe");
504 std::wstring cmdline
= base::UTF8ToWide(str
);
508 STARTUPINFO startup_info
;
509 memset(&startup_info
, 0, sizeof(startup_info
));
510 startup_info
.cb
= sizeof(startup_info
);
512 PROCESS_INFORMATION process_info
;
513 if (CreateProcessW(prog_name
, &cmdline
[0], NULL
, NULL
, false, 0, NULL
,
514 NULL
, &startup_info
, &process_info
)) {
515 WaitForSingleObject(process_info
.hProcess
, INFINITE
);
516 CloseHandle(process_info
.hThread
);
517 CloseHandle(process_info
.hProcess
);
519 // debug process broken, let's just do a message box
520 MessageBoxW(NULL
, &cmdline
[0], L
"Fatal error",
521 MB_OK
| MB_ICONHAND
| MB_TOPMOST
);
524 // We intentionally don't implement a dialog on other platforms.
525 // You can just look at stderr.
530 LogMessage::SaveLastError::SaveLastError() : last_error_(::GetLastError()) {
533 LogMessage::SaveLastError::~SaveLastError() {
534 ::SetLastError(last_error_
);
536 #endif // defined(OS_WIN)
538 LogMessage::LogMessage(const char* file
, int line
, LogSeverity severity
,
540 : severity_(severity
), file_(file
), line_(line
) {
544 LogMessage::LogMessage(const char* file
, int line
)
545 : severity_(LOG_INFO
), file_(file
), line_(line
) {
549 LogMessage::LogMessage(const char* file
, int line
, LogSeverity severity
)
550 : severity_(severity
), file_(file
), line_(line
) {
554 LogMessage::LogMessage(const char* file
, int line
, std::string
* result
)
555 : severity_(LOG_FATAL
), file_(file
), line_(line
) {
557 stream_
<< "Check failed: " << *result
;
561 LogMessage::LogMessage(const char* file
, int line
, LogSeverity severity
,
563 : severity_(severity
), file_(file
), line_(line
) {
565 stream_
<< "Check failed: " << *result
;
569 LogMessage::~LogMessage() {
570 #if !defined(NDEBUG) && !defined(OS_NACL)
571 if (severity_
== LOG_FATAL
) {
572 // Include a stack trace on a fatal.
573 base::debug::StackTrace trace
;
574 stream_
<< std::endl
; // Newline to separate from log message.
575 trace
.OutputToStream(&stream_
);
578 stream_
<< std::endl
;
579 std::string
str_newline(stream_
.str());
581 // Give any log message handler first dibs on the message.
582 if (log_message_handler
&&
583 log_message_handler(severity_
, file_
, line_
,
584 message_start_
, str_newline
)) {
585 // The handler took care of it, no further processing.
589 if ((logging_destination
& LOG_TO_SYSTEM_DEBUG_LOG
) != 0) {
591 OutputDebugStringA(str_newline
.c_str());
592 #elif defined(OS_ANDROID)
593 android_LogPriority priority
=
594 (severity_
< 0) ? ANDROID_LOG_VERBOSE
: ANDROID_LOG_UNKNOWN
;
597 priority
= ANDROID_LOG_INFO
;
600 priority
= ANDROID_LOG_WARN
;
603 case LOG_ERROR_REPORT
:
604 priority
= ANDROID_LOG_ERROR
;
607 priority
= ANDROID_LOG_FATAL
;
610 __android_log_write(priority
, "chromium", str_newline
.c_str());
612 fprintf(stderr
, "%s", str_newline
.c_str());
614 } else if (severity_
>= kAlwaysPrintErrorLevel
) {
615 // When we're only outputting to a log file, above a certain log level, we
616 // should still output to stderr so that we can better detect and diagnose
617 // problems with unit tests, especially on the buildbots.
618 fprintf(stderr
, "%s", str_newline
.c_str());
623 if ((logging_destination
& LOG_TO_FILE
) != 0) {
624 // We can have multiple threads and/or processes, so try to prevent them
625 // from clobbering each other's writes.
626 // If the client app did not call InitLogging, and the lock has not
627 // been created do it now. We do this on demand, but if two threads try
628 // to do this at the same time, there will be a race condition to create
629 // the lock. This is why InitLogging should be called from the main
630 // thread at the beginning of execution.
631 LoggingLock::Init(LOCK_LOG_FILE
, NULL
);
632 LoggingLock logging_lock
;
633 if (InitializeLogFileHandle()) {
635 SetFilePointer(log_file
, 0, 0, SEEK_END
);
638 static_cast<const void*>(str_newline
.c_str()),
639 static_cast<DWORD
>(str_newline
.length()),
643 fprintf(log_file
, "%s", str_newline
.c_str());
649 if (severity_
== LOG_FATAL
) {
650 // Ensure the first characters of the string are on the stack so they
651 // are contained in minidumps for diagnostic purposes.
652 char str_stack
[1024];
653 str_newline
.copy(str_stack
, arraysize(str_stack
));
654 base::debug::Alias(str_stack
);
656 // display a message or break into the debugger on a fatal error
657 if (base::debug::BeingDebugged()) {
658 base::debug::BreakDebugger();
660 if (log_assert_handler
) {
661 // make a copy of the string for the handler out of paranoia
662 log_assert_handler(std::string(stream_
.str()));
664 // Don't use the string with the newline, get a fresh version to send to
665 // the debug message process. We also don't display assertions to the
666 // user in release mode. The enduser can't do anything with this
667 // information, and displaying message boxes when the application is
668 // hosed can cause additional problems.
670 DisplayDebugMessageInDialog(stream_
.str());
672 // Crash the process to generate a dump.
673 base::debug::BreakDebugger();
676 } else if (severity_
== LOG_ERROR_REPORT
) {
677 // We are here only if the user runs with --enable-dcheck in release mode.
678 if (log_report_handler
) {
679 log_report_handler(std::string(stream_
.str()));
681 DisplayDebugMessageInDialog(stream_
.str());
686 // writes the common header info to the stream
687 void LogMessage::Init(const char* file
, int line
) {
688 base::StringPiece
filename(file
);
689 size_t last_slash_pos
= filename
.find_last_of("\\/");
690 if (last_slash_pos
!= base::StringPiece::npos
)
691 filename
.remove_prefix(last_slash_pos
+ 1);
693 // TODO(darin): It might be nice if the columns were fixed width.
697 stream_
<< CurrentProcessId() << ':';
699 stream_
<< base::PlatformThread::CurrentId() << ':';
701 time_t t
= time(NULL
);
702 struct tm local_time
= {0};
704 localtime_s(&local_time
, &t
);
706 localtime_r(&t
, &local_time
);
708 struct tm
* tm_time
= &local_time
;
709 stream_
<< std::setfill('0')
710 << std::setw(2) << 1 + tm_time
->tm_mon
711 << std::setw(2) << tm_time
->tm_mday
713 << std::setw(2) << tm_time
->tm_hour
714 << std::setw(2) << tm_time
->tm_min
715 << std::setw(2) << tm_time
->tm_sec
719 stream_
<< TickCount() << ':';
721 stream_
<< log_severity_name(severity_
);
723 stream_
<< "VERBOSE" << -severity_
;
725 stream_
<< ":" << filename
<< "(" << line
<< ")] ";
727 message_start_
= stream_
.tellp();
731 // This has already been defined in the header, but defining it again as DWORD
732 // ensures that the type used in the header is equivalent to DWORD. If not,
733 // the redefinition is a compile error.
734 typedef DWORD SystemErrorCode
;
737 SystemErrorCode
GetLastSystemErrorCode() {
739 return ::GetLastError();
740 #elif defined(OS_POSIX)
743 #error Not implemented
748 Win32ErrorLogMessage::Win32ErrorLogMessage(const char* file
,
750 LogSeverity severity
,
755 log_message_(file
, line
, severity
) {
758 Win32ErrorLogMessage::Win32ErrorLogMessage(const char* file
,
760 LogSeverity severity
,
764 log_message_(file
, line
, severity
) {
767 Win32ErrorLogMessage::~Win32ErrorLogMessage() {
768 const int error_message_buffer_size
= 256;
769 char msgbuf
[error_message_buffer_size
];
770 DWORD flags
= FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
;
773 hmod
= GetModuleHandleA(module_
);
775 flags
|= FORMAT_MESSAGE_FROM_HMODULE
;
777 // This makes a nested Win32ErrorLogMessage. It will have module_ of NULL
778 // so it will not call GetModuleHandle, so recursive errors are
780 DPLOG(WARNING
) << "Couldn't open module " << module_
781 << " for error message query";
786 DWORD len
= FormatMessageA(flags
,
791 sizeof(msgbuf
) / sizeof(msgbuf
[0]),
795 isspace(static_cast<unsigned char>(msgbuf
[len
- 1]))) {
798 stream() << ": " << msgbuf
;
800 stream() << ": Error " << GetLastError() << " while retrieving error "
803 // We're about to crash (CHECK). Put |err_| on the stack (by placing it in a
804 // field) and use Alias in hopes that it makes it into crash dumps.
805 DWORD last_error
= err_
;
806 base::debug::Alias(&last_error
);
808 #elif defined(OS_POSIX)
809 ErrnoLogMessage::ErrnoLogMessage(const char* file
,
811 LogSeverity severity
,
814 log_message_(file
, line
, severity
) {
817 ErrnoLogMessage::~ErrnoLogMessage() {
818 stream() << ": " << safe_strerror(err_
);
822 void CloseLogFile() {
823 LoggingLock logging_lock
;
824 CloseLogFileUnlocked();
827 void RawLog(int level
, const char* message
) {
828 if (level
>= min_log_level
) {
829 size_t bytes_written
= 0;
830 const size_t message_len
= strlen(message
);
832 while (bytes_written
< message_len
) {
834 write(STDERR_FILENO
, message
+ bytes_written
,
835 message_len
- bytes_written
));
837 // Give up, nothing we can do now.
843 if (message_len
> 0 && message
[message_len
- 1] != '\n') {
845 rv
= HANDLE_EINTR(write(STDERR_FILENO
, "\n", 1));
847 // Give up, nothing we can do now.
854 if (level
== LOG_FATAL
)
855 base::debug::BreakDebugger();
858 // This was defined at the beginning of this file.
862 std::wstring
GetLogFileFullPath() {
864 return *log_file_name
;
865 return std::wstring();
869 } // namespace logging
871 std::ostream
& operator<<(std::ostream
& out
, const wchar_t* wstr
) {
872 return out
<< base::WideToUTF8(std::wstring(wstr
));