[email protected] | 63e6680 | 2012-01-18 21:21:09 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
[email protected] | b16ef31 | 2008-08-19 18:36:23 | [diff] [blame] | 5 | #include "base/logging.h" |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 6 | |
avi | 51ba3e69 | 2015-12-26 17:30:50 | [diff] [blame] | 7 | #include <limits.h> |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame^] | 8 | #include <stdint.h> |
| 9 | |
| 10 | #include "base/macros.h" |
| 11 | #include "build/build_config.h" |
avi | 51ba3e69 | 2015-12-26 17:30:50 | [diff] [blame] | 12 | |
[email protected] | b16ef31 | 2008-08-19 18:36:23 | [diff] [blame] | 13 | #if defined(OS_WIN) |
[email protected] | e36ddc8 | 2009-12-08 04:22:50 | [diff] [blame] | 14 | #include <io.h> |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 15 | #include <windows.h> |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
| 17 | #include "base/files/file_util.h" |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 18 | typedef HANDLE FileHandle; |
| 19 | typedef HANDLE MutexHandle; |
[email protected] | e36ddc8 | 2009-12-08 04:22:50 | [diff] [blame] | 20 | // Windows warns on using write(). It prefers _write(). |
| 21 | #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count)) |
| 22 | // Windows doesn't define STDERR_FILENO. Define it here. |
| 23 | #define STDERR_FILENO 2 |
[email protected] | 052f1b5 | 2008-11-06 21:43:07 | [diff] [blame] | 24 | #elif defined(OS_MACOSX) |
mark | 4c7449c | 2015-11-10 19:53:42 | [diff] [blame] | 25 | #include <asl.h> |
| 26 | #include <CoreFoundation/CoreFoundation.h> |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 27 | #include <mach/mach.h> |
| 28 | #include <mach/mach_time.h> |
| 29 | #include <mach-o/dyld.h> |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 30 | #elif defined(OS_POSIX) |
[email protected] | 19ea84ca | 2010-11-12 08:37:08 | [diff] [blame] | 31 | #if defined(OS_NACL) |
thestig | 75f8735 | 2014-12-03 21:42:27 | [diff] [blame] | 32 | #include <sys/time.h> // timespec doesn't seem to be in <time.h> |
[email protected] | 19ea84ca | 2010-11-12 08:37:08 | [diff] [blame] | 33 | #else |
[email protected] | 052f1b5 | 2008-11-06 21:43:07 | [diff] [blame] | 34 | #include <sys/syscall.h> |
[email protected] | 19ea84ca | 2010-11-12 08:37:08 | [diff] [blame] | 35 | #endif |
[email protected] | 052f1b5 | 2008-11-06 21:43:07 | [diff] [blame] | 36 | #include <time.h> |
[email protected] | 614e9fa | 2008-08-11 22:52:59 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | #if defined(OS_POSIX) |
[email protected] | d8617a6 | 2009-10-09 23:52:20 | [diff] [blame] | 40 | #include <errno.h> |
mark | 4c7449c | 2015-11-10 19:53:42 | [diff] [blame] | 41 | #include <paths.h> |
[email protected] | 166326c6 | 2010-08-05 15:50:23 | [diff] [blame] | 42 | #include <pthread.h> |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 43 | #include <stdio.h> |
[email protected] | eb62f726 | 2013-03-30 14:29:00 | [diff] [blame] | 44 | #include <stdlib.h> |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 45 | #include <string.h> |
mark | 4c7449c | 2015-11-10 19:53:42 | [diff] [blame] | 46 | #include <sys/stat.h> |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 47 | #include <unistd.h> |
| 48 | #define MAX_PATH PATH_MAX |
| 49 | typedef FILE* FileHandle; |
| 50 | typedef pthread_mutex_t* MutexHandle; |
| 51 | #endif |
| 52 | |
[email protected] | 1f88b516 | 2011-04-01 00:02:29 | [diff] [blame] | 53 | #include <algorithm> |
| 54 | #include <cstring> |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 55 | #include <ctime> |
| 56 | #include <iomanip> |
[email protected] | 1f88b516 | 2011-04-01 00:02:29 | [diff] [blame] | 57 | #include <ostream> |
[email protected] | c914d8a | 2014-04-23 01:11:01 | [diff] [blame] | 58 | #include <string> |
[email protected] | b16ef31 | 2008-08-19 18:36:23 | [diff] [blame] | 59 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 60 | #include "base/base_switches.h" |
| 61 | #include "base/command_line.h" |
[email protected] | eb4c4d03 | 2012-04-03 18:45:05 | [diff] [blame] | 62 | #include "base/debug/alias.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 63 | #include "base/debug/debugger.h" |
| 64 | #include "base/debug/stack_trace.h" |
[email protected] | 2025d00 | 2012-11-14 20:54:35 | [diff] [blame] | 65 | #include "base/posix/eintr_wrapper.h" |
[email protected] | eb62f726 | 2013-03-30 14:29:00 | [diff] [blame] | 66 | #include "base/strings/string_piece.h" |
[email protected] | c914d8a | 2014-04-23 01:11:01 | [diff] [blame] | 67 | #include "base/strings/string_util.h" |
| 68 | #include "base/strings/stringprintf.h" |
mark | 4c7449c | 2015-11-10 19:53:42 | [diff] [blame] | 69 | #include "base/strings/sys_string_conversions.h" |
[email protected] | a4ea1f1 | 2013-06-07 18:37:07 | [diff] [blame] | 70 | #include "base/strings/utf_string_conversions.h" |
[email protected] | bc581a68 | 2011-01-01 23:16:20 | [diff] [blame] | 71 | #include "base/synchronization/lock_impl.h" |
[email protected] | 63e6680 | 2012-01-18 21:21:09 | [diff] [blame] | 72 | #include "base/threading/platform_thread.h" |
[email protected] | 99b7c57f | 2010-09-29 19:26:36 | [diff] [blame] | 73 | #include "base/vlog.h" |
[email protected] | 53c7ce4 | 2010-12-14 16:20:04 | [diff] [blame] | 74 | #if defined(OS_POSIX) |
brettw | 6ee6fd6 | 2015-06-09 18:05:24 | [diff] [blame] | 75 | #include "base/posix/safe_strerror.h" |
[email protected] | 53c7ce4 | 2010-12-14 16:20:04 | [diff] [blame] | 76 | #endif |
[email protected] | 52a261f | 2009-03-03 15:01:12 | [diff] [blame] | 77 | |
[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 78 | #if defined(OS_ANDROID) |
| 79 | #include <android/log.h> |
| 80 | #endif |
| 81 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 82 | namespace logging { |
| 83 | |
[email protected] | 064aa16 | 2011-12-03 00:30:08 | [diff] [blame] | 84 | namespace { |
| 85 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 86 | VlogInfo* g_vlog_info = nullptr; |
| 87 | VlogInfo* g_vlog_info_prev = nullptr; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 88 | |
| 89 | const char* const log_severity_names[LOG_NUM_SEVERITIES] = { |
[email protected] | f2c0549 | 2014-06-17 12:04:23 | [diff] [blame] | 90 | "INFO", "WARNING", "ERROR", "FATAL" }; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 91 | |
thestig | 75f8735 | 2014-12-03 21:42:27 | [diff] [blame] | 92 | const char* log_severity_name(int severity) { |
[email protected] | 80f360a | 2014-01-23 01:36:19 | [diff] [blame] | 93 | if (severity >= 0 && severity < LOG_NUM_SEVERITIES) |
| 94 | return log_severity_names[severity]; |
| 95 | return "UNKNOWN"; |
| 96 | } |
| 97 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 98 | int g_min_log_level = 0; |
[email protected] | 1d8c270 | 2008-08-19 23:39:32 | [diff] [blame] | 99 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 100 | LoggingDestination g_logging_destination = LOG_DEFAULT; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 101 | |
[email protected] | a33c989 | 2008-08-25 20:10:31 | [diff] [blame] | 102 | // For LOG_ERROR and above, always print to stderr. |
| 103 | const int kAlwaysPrintErrorLevel = LOG_ERROR; |
| 104 | |
[email protected] | 614e9fa | 2008-08-11 22:52:59 | [diff] [blame] | 105 | // Which log file to use? This is initialized by InitLogging or |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 106 | // will be lazily initialized to the default value when it is |
| 107 | // first needed. |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 108 | #if defined(OS_WIN) |
[email protected] | 614e9fa | 2008-08-11 22:52:59 | [diff] [blame] | 109 | typedef std::wstring PathString; |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 110 | #else |
[email protected] | 614e9fa | 2008-08-11 22:52:59 | [diff] [blame] | 111 | typedef std::string PathString; |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 112 | #endif |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 113 | PathString* g_log_file_name = nullptr; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 114 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 115 | // This file is lazily opened and the handle may be nullptr |
| 116 | FileHandle g_log_file = nullptr; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 117 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 118 | // What should be prepended to each message? |
| 119 | bool g_log_process_id = false; |
| 120 | bool g_log_thread_id = false; |
| 121 | bool g_log_timestamp = true; |
| 122 | bool g_log_tickcount = false; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 123 | |
[email protected] | 81e0a85 | 2010-08-17 00:38:12 | [diff] [blame] | 124 | // Should we pop up fatal debug messages in a dialog? |
| 125 | bool show_error_dialogs = false; |
| 126 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 127 | // An assert handler override specified by the client to be called instead of |
[email protected] | fb62a53 | 2009-02-12 01:19:05 | [diff] [blame] | 128 | // the debug message dialog and process termination. |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 129 | LogAssertHandlerFunction log_assert_handler = nullptr; |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 130 | // A log message handler that gets notified of every log message we process. |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 131 | LogMessageHandlerFunction log_message_handler = nullptr; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 132 | |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 133 | // Helper functions to wrap platform differences. |
| 134 | |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame^] | 135 | int32_t CurrentProcessId() { |
[email protected] | f858847 | 2008-11-05 23:17:24 | [diff] [blame] | 136 | #if defined(OS_WIN) |
| 137 | return GetCurrentProcessId(); |
| 138 | #elif defined(OS_POSIX) |
| 139 | return getpid(); |
| 140 | #endif |
| 141 | } |
| 142 | |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame^] | 143 | uint64_t TickCount() { |
[email protected] | f858847 | 2008-11-05 23:17:24 | [diff] [blame] | 144 | #if defined(OS_WIN) |
| 145 | return GetTickCount(); |
| 146 | #elif defined(OS_MACOSX) |
| 147 | return mach_absolute_time(); |
[email protected] | 19ea84ca | 2010-11-12 08:37:08 | [diff] [blame] | 148 | #elif defined(OS_NACL) |
| 149 | // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h |
| 150 | // So we have to use clock() for now. |
| 151 | return clock(); |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 152 | #elif defined(OS_POSIX) |
[email protected] | 052f1b5 | 2008-11-06 21:43:07 | [diff] [blame] | 153 | struct timespec ts; |
| 154 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 155 | |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame^] | 156 | uint64_t absolute_micro = static_cast<int64_t>(ts.tv_sec) * 1000000 + |
| 157 | static_cast<int64_t>(ts.tv_nsec) / 1000; |
[email protected] | 052f1b5 | 2008-11-06 21:43:07 | [diff] [blame] | 158 | |
| 159 | return absolute_micro; |
[email protected] | f858847 | 2008-11-05 23:17:24 | [diff] [blame] | 160 | #endif |
| 161 | } |
| 162 | |
[email protected] | 614e9fa | 2008-08-11 22:52:59 | [diff] [blame] | 163 | void DeleteFilePath(const PathString& log_name) { |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 164 | #if defined(OS_WIN) |
[email protected] | 614e9fa | 2008-08-11 22:52:59 | [diff] [blame] | 165 | DeleteFile(log_name.c_str()); |
thestig | 75f8735 | 2014-12-03 21:42:27 | [diff] [blame] | 166 | #elif defined(OS_NACL) |
[email protected] | ac07ec5 | 2013-04-22 17:32:45 | [diff] [blame] | 167 | // Do nothing; unlink() isn't supported on NaCl. |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 168 | #else |
[email protected] | 614e9fa | 2008-08-11 22:52:59 | [diff] [blame] | 169 | unlink(log_name.c_str()); |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 170 | #endif |
| 171 | } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 172 | |
[email protected] | 5f95d53 | 2010-10-01 17:16:58 | [diff] [blame] | 173 | PathString GetDefaultLogFile() { |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 174 | #if defined(OS_WIN) |
| 175 | // On Windows we use the same path as the exe. |
| 176 | wchar_t module_name[MAX_PATH]; |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 177 | GetModuleFileName(nullptr, module_name, MAX_PATH); |
[email protected] | 5f95d53 | 2010-10-01 17:16:58 | [diff] [blame] | 178 | |
scottmg | fc5b707 | 2015-01-27 21:46:28 | [diff] [blame] | 179 | PathString log_name = module_name; |
| 180 | PathString::size_type last_backslash = log_name.rfind('\\', log_name.size()); |
[email protected] | 5f95d53 | 2010-10-01 17:16:58 | [diff] [blame] | 181 | if (last_backslash != PathString::npos) |
scottmg | fc5b707 | 2015-01-27 21:46:28 | [diff] [blame] | 182 | log_name.erase(last_backslash + 1); |
| 183 | log_name += L"debug.log"; |
| 184 | return log_name; |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 185 | #elif defined(OS_POSIX) |
| 186 | // On other platforms we just use the current directory. |
[email protected] | 5f95d53 | 2010-10-01 17:16:58 | [diff] [blame] | 187 | return PathString("debug.log"); |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 188 | #endif |
| 189 | } |
| 190 | |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 191 | // We don't need locks on Windows for atomically appending to files. The OS |
| 192 | // provides this functionality. |
| 193 | #if !defined(OS_WIN) |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 194 | // This class acts as a wrapper for locking the logging files. |
| 195 | // LoggingLock::Init() should be called from the main thread before any logging |
| 196 | // is done. Then whenever logging, be sure to have a local LoggingLock |
| 197 | // instance on the stack. This will ensure that the lock is unlocked upon |
| 198 | // exiting the frame. |
| 199 | // LoggingLocks can not be nested. |
| 200 | class LoggingLock { |
| 201 | public: |
| 202 | LoggingLock() { |
| 203 | LockLogging(); |
| 204 | } |
| 205 | |
| 206 | ~LoggingLock() { |
| 207 | UnlockLogging(); |
| 208 | } |
| 209 | |
| 210 | static void Init(LogLockingState lock_log, const PathChar* new_log_file) { |
| 211 | if (initialized) |
| 212 | return; |
| 213 | lock_log_file = lock_log; |
[email protected] | 5f95d53 | 2010-10-01 17:16:58 | [diff] [blame] | 214 | |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 215 | if (lock_log_file != LOCK_LOG_FILE) |
[email protected] | bc581a68 | 2011-01-01 23:16:20 | [diff] [blame] | 216 | log_lock = new base::internal::LockImpl(); |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 217 | |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 218 | initialized = true; |
| 219 | } |
| 220 | |
| 221 | private: |
| 222 | static void LockLogging() { |
| 223 | if (lock_log_file == LOCK_LOG_FILE) { |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 224 | #if defined(OS_POSIX) |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 225 | pthread_mutex_lock(&log_mutex); |
| 226 | #endif |
| 227 | } else { |
| 228 | // use the lock |
| 229 | log_lock->Lock(); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | static void UnlockLogging() { |
| 234 | if (lock_log_file == LOCK_LOG_FILE) { |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 235 | #if defined(OS_POSIX) |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 236 | pthread_mutex_unlock(&log_mutex); |
| 237 | #endif |
| 238 | } else { |
| 239 | log_lock->Unlock(); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // The lock is used if log file locking is false. It helps us avoid problems |
| 244 | // with multiple threads writing to the log file at the same time. Use |
| 245 | // LockImpl directly instead of using Lock, because Lock makes logging calls. |
[email protected] | bc581a68 | 2011-01-01 23:16:20 | [diff] [blame] | 246 | static base::internal::LockImpl* log_lock; |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 247 | |
| 248 | // When we don't use a lock, we are using a global mutex. We need to do this |
| 249 | // because LockFileEx is not thread safe. |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 250 | #if defined(OS_POSIX) |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 251 | static pthread_mutex_t log_mutex; |
| 252 | #endif |
| 253 | |
| 254 | static bool initialized; |
| 255 | static LogLockingState lock_log_file; |
| 256 | }; |
| 257 | |
| 258 | // static |
| 259 | bool LoggingLock::initialized = false; |
| 260 | // static |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 261 | base::internal::LockImpl* LoggingLock::log_lock = nullptr; |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 262 | // static |
| 263 | LogLockingState LoggingLock::lock_log_file = LOCK_LOG_FILE; |
| 264 | |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 265 | #if defined(OS_POSIX) |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 266 | pthread_mutex_t LoggingLock::log_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 267 | #endif |
| 268 | |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 269 | #endif // OS_WIN |
| 270 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 271 | // Called by logging functions to ensure that |g_log_file| is initialized |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 272 | // and can be used for writing. Returns false if the file could not be |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 273 | // initialized. |g_log_file| will be nullptr in this case. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 274 | bool InitializeLogFileHandle() { |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 275 | if (g_log_file) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 276 | return true; |
| 277 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 278 | if (!g_log_file_name) { |
[email protected] | 614e9fa | 2008-08-11 22:52:59 | [diff] [blame] | 279 | // Nobody has called InitLogging to specify a debug log file, so here we |
| 280 | // initialize the log file name to a default. |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 281 | g_log_file_name = new PathString(GetDefaultLogFile()); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 282 | } |
| 283 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 284 | if ((g_logging_destination & LOG_TO_FILE) != 0) { |
[email protected] | 614e9fa | 2008-08-11 22:52:59 | [diff] [blame] | 285 | #if defined(OS_WIN) |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 286 | // The FILE_APPEND_DATA access mask ensures that the file is atomically |
| 287 | // appended to across accesses from multiple threads. |
| 288 | // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364399(v=vs.85).aspx |
| 289 | // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx |
| 290 | g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA, |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 291 | FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, |
| 292 | OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 293 | if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) { |
[email protected] | 1d8c270 | 2008-08-19 23:39:32 | [diff] [blame] | 294 | // try the current directory |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 295 | base::FilePath file_path; |
| 296 | if (!base::GetCurrentDirectory(&file_path)) |
| 297 | return false; |
| 298 | |
| 299 | *g_log_file_name = file_path.Append( |
| 300 | FILE_PATH_LITERAL("debug.log")).value(); |
| 301 | |
| 302 | g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA, |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 303 | FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, |
| 304 | OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 305 | if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) { |
| 306 | g_log_file = nullptr; |
[email protected] | 1d8c270 | 2008-08-19 23:39:32 | [diff] [blame] | 307 | return false; |
| 308 | } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 309 | } |
[email protected] | 78c6dd6 | 2009-06-08 23:29:11 | [diff] [blame] | 310 | #elif defined(OS_POSIX) |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 311 | g_log_file = fopen(g_log_file_name->c_str(), "a"); |
| 312 | if (g_log_file == nullptr) |
[email protected] | 78c6dd6 | 2009-06-08 23:29:11 | [diff] [blame] | 313 | return false; |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 314 | #endif |
[email protected] | 1d8c270 | 2008-08-19 23:39:32 | [diff] [blame] | 315 | } |
| 316 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 317 | return true; |
| 318 | } |
| 319 | |
[email protected] | 17dcf75 | 2013-07-15 21:47:09 | [diff] [blame] | 320 | void CloseFile(FileHandle log) { |
| 321 | #if defined(OS_WIN) |
| 322 | CloseHandle(log); |
| 323 | #else |
| 324 | fclose(log); |
| 325 | #endif |
| 326 | } |
| 327 | |
| 328 | void CloseLogFileUnlocked() { |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 329 | if (!g_log_file) |
[email protected] | 17dcf75 | 2013-07-15 21:47:09 | [diff] [blame] | 330 | return; |
| 331 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 332 | CloseFile(g_log_file); |
| 333 | g_log_file = nullptr; |
[email protected] | 17dcf75 | 2013-07-15 21:47:09 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | 064aa16 | 2011-12-03 00:30:08 | [diff] [blame] | 336 | } // namespace |
| 337 | |
[email protected] | 5e3f7c2 | 2013-06-21 21:15:33 | [diff] [blame] | 338 | LoggingSettings::LoggingSettings() |
| 339 | : logging_dest(LOG_DEFAULT), |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 340 | log_file(nullptr), |
[email protected] | 5e3f7c2 | 2013-06-21 21:15:33 | [diff] [blame] | 341 | lock_log(LOCK_LOG_FILE), |
[email protected] | 1a150551 | 2014-03-10 18:23:38 | [diff] [blame] | 342 | delete_old(APPEND_TO_OLD_LOG_FILE) {} |
[email protected] | 064aa16 | 2011-12-03 00:30:08 | [diff] [blame] | 343 | |
[email protected] | 5e3f7c2 | 2013-06-21 21:15:33 | [diff] [blame] | 344 | bool BaseInitLoggingImpl(const LoggingSettings& settings) { |
[email protected] | ac07ec5 | 2013-04-22 17:32:45 | [diff] [blame] | 345 | #if defined(OS_NACL) |
[email protected] | 5e3f7c2 | 2013-06-21 21:15:33 | [diff] [blame] | 346 | // Can log only to the system debug log. |
| 347 | CHECK_EQ(settings.logging_dest & ~LOG_TO_SYSTEM_DEBUG_LOG, 0); |
[email protected] | ac07ec5 | 2013-04-22 17:32:45 | [diff] [blame] | 348 | #endif |
pgal.u-szeged | 421dddb | 2014-11-25 12:55:02 | [diff] [blame] | 349 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 350 | // Don't bother initializing |g_vlog_info| unless we use one of the |
[email protected] | 99b7c57f | 2010-09-29 19:26:36 | [diff] [blame] | 351 | // vlog switches. |
| 352 | if (command_line->HasSwitch(switches::kV) || |
| 353 | command_line->HasSwitch(switches::kVModule)) { |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 354 | // NOTE: If |g_vlog_info| has already been initialized, it might be in use |
[email protected] | 064aa16 | 2011-12-03 00:30:08 | [diff] [blame] | 355 | // by another thread. Don't delete the old VLogInfo, just create a second |
| 356 | // one. We keep track of both to avoid memory leak warnings. |
| 357 | CHECK(!g_vlog_info_prev); |
| 358 | g_vlog_info_prev = g_vlog_info; |
| 359 | |
[email protected] | 99b7c57f | 2010-09-29 19:26:36 | [diff] [blame] | 360 | g_vlog_info = |
| 361 | new VlogInfo(command_line->GetSwitchValueASCII(switches::kV), |
[email protected] | 162ac0f | 2010-11-04 15:50:49 | [diff] [blame] | 362 | command_line->GetSwitchValueASCII(switches::kVModule), |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 363 | &g_min_log_level); |
[email protected] | 99b7c57f | 2010-09-29 19:26:36 | [diff] [blame] | 364 | } |
| 365 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 366 | g_logging_destination = settings.logging_dest; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 367 | |
[email protected] | 5e3f7c2 | 2013-06-21 21:15:33 | [diff] [blame] | 368 | // ignore file options unless logging to file is set. |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 369 | if ((g_logging_destination & LOG_TO_FILE) == 0) |
[email protected] | c7d5da99 | 2010-10-28 00:20:21 | [diff] [blame] | 370 | return true; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 371 | |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 372 | #if !defined(OS_WIN) |
[email protected] | 17dcf75 | 2013-07-15 21:47:09 | [diff] [blame] | 373 | LoggingLock::Init(settings.lock_log, settings.log_file); |
| 374 | LoggingLock logging_lock; |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 375 | #endif |
[email protected] | 17dcf75 | 2013-07-15 21:47:09 | [diff] [blame] | 376 | |
| 377 | // Calling InitLogging twice or after some log call has already opened the |
| 378 | // default log file will re-initialize to the new options. |
| 379 | CloseLogFileUnlocked(); |
| 380 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 381 | if (!g_log_file_name) |
| 382 | g_log_file_name = new PathString(); |
| 383 | *g_log_file_name = settings.log_file; |
[email protected] | 5e3f7c2 | 2013-06-21 21:15:33 | [diff] [blame] | 384 | if (settings.delete_old == DELETE_OLD_LOG_FILE) |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 385 | DeleteFilePath(*g_log_file_name); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 386 | |
[email protected] | c7d5da99 | 2010-10-28 00:20:21 | [diff] [blame] | 387 | return InitializeLogFileHandle(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | void SetMinLogLevel(int level) { |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 391 | g_min_log_level = std::min(LOG_FATAL, level); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | int GetMinLogLevel() { |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 395 | return g_min_log_level; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 396 | } |
| 397 | |
skobes | c78c0ad7 | 2015-12-07 20:21:23 | [diff] [blame] | 398 | bool ShouldCreateLogMessage(int severity) { |
| 399 | if (severity < g_min_log_level) |
| 400 | return false; |
| 401 | |
| 402 | // Return true here unless we know ~LogMessage won't do anything. Note that |
| 403 | // ~LogMessage writes to stderr if severity_ >= kAlwaysPrintErrorLevel, even |
| 404 | // when g_logging_destination is LOG_NONE. |
| 405 | return g_logging_destination != LOG_NONE || log_message_handler || |
| 406 | severity >= kAlwaysPrintErrorLevel; |
| 407 | } |
| 408 | |
[email protected] | 162ac0f | 2010-11-04 15:50:49 | [diff] [blame] | 409 | int GetVlogVerbosity() { |
| 410 | return std::max(-1, LOG_INFO - GetMinLogLevel()); |
| 411 | } |
| 412 | |
[email protected] | 99b7c57f | 2010-09-29 19:26:36 | [diff] [blame] | 413 | int GetVlogLevelHelper(const char* file, size_t N) { |
| 414 | DCHECK_GT(N, 0U); |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 415 | // Note: |g_vlog_info| may change on a different thread during startup |
| 416 | // (but will always be valid or nullptr). |
[email protected] | 064aa16 | 2011-12-03 00:30:08 | [diff] [blame] | 417 | VlogInfo* vlog_info = g_vlog_info; |
| 418 | return vlog_info ? |
| 419 | vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) : |
[email protected] | 162ac0f | 2010-11-04 15:50:49 | [diff] [blame] | 420 | GetVlogVerbosity(); |
[email protected] | 99b7c57f | 2010-09-29 19:26:36 | [diff] [blame] | 421 | } |
| 422 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 423 | void SetLogItems(bool enable_process_id, bool enable_thread_id, |
| 424 | bool enable_timestamp, bool enable_tickcount) { |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 425 | g_log_process_id = enable_process_id; |
| 426 | g_log_thread_id = enable_thread_id; |
| 427 | g_log_timestamp = enable_timestamp; |
| 428 | g_log_tickcount = enable_tickcount; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 429 | } |
| 430 | |
[email protected] | 81e0a85 | 2010-08-17 00:38:12 | [diff] [blame] | 431 | void SetShowErrorDialogs(bool enable_dialogs) { |
| 432 | show_error_dialogs = enable_dialogs; |
| 433 | } |
| 434 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 435 | void SetLogAssertHandler(LogAssertHandlerFunction handler) { |
| 436 | log_assert_handler = handler; |
| 437 | } |
| 438 | |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 439 | void SetLogMessageHandler(LogMessageHandlerFunction handler) { |
| 440 | log_message_handler = handler; |
| 441 | } |
| 442 | |
[email protected] | 64e5cc0 | 2010-11-03 19:20:27 | [diff] [blame] | 443 | LogMessageHandlerFunction GetLogMessageHandler() { |
| 444 | return log_message_handler; |
| 445 | } |
| 446 | |
[email protected] | 6d445d3 | 2010-09-30 19:10:03 | [diff] [blame] | 447 | // Explicit instantiations for commonly used comparisons. |
| 448 | template std::string* MakeCheckOpString<int, int>( |
| 449 | const int&, const int&, const char* names); |
| 450 | template std::string* MakeCheckOpString<unsigned long, unsigned long>( |
| 451 | const unsigned long&, const unsigned long&, const char* names); |
| 452 | template std::string* MakeCheckOpString<unsigned long, unsigned int>( |
| 453 | const unsigned long&, const unsigned int&, const char* names); |
| 454 | template std::string* MakeCheckOpString<unsigned int, unsigned long>( |
| 455 | const unsigned int&, const unsigned long&, const char* names); |
| 456 | template std::string* MakeCheckOpString<std::string, std::string>( |
| 457 | const std::string&, const std::string&, const char* name); |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 458 | |
[email protected] | f2c0549 | 2014-06-17 12:04:23 | [diff] [blame] | 459 | #if !defined(NDEBUG) |
[email protected] | d81baca4 | 2010-03-01 13:10:22 | [diff] [blame] | 460 | // Displays a message box to the user with the error message in it. |
| 461 | // Used for fatal messages, where we close the app simultaneously. |
[email protected] | 561513f | 2010-12-16 23:29:25 | [diff] [blame] | 462 | // This is for developers only; we don't use this in circumstances |
| 463 | // (like release builds) where users could see it, since users don't |
| 464 | // understand these messages anyway. |
[email protected] | d81baca4 | 2010-03-01 13:10:22 | [diff] [blame] | 465 | void DisplayDebugMessageInDialog(const std::string& str) { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 466 | if (str.empty()) |
| 467 | return; |
| 468 | |
[email protected] | 81e0a85 | 2010-08-17 00:38:12 | [diff] [blame] | 469 | if (!show_error_dialogs) |
[email protected] | 846ed9c3 | 2010-07-29 20:33:44 | [diff] [blame] | 470 | return; |
| 471 | |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 472 | #if defined(OS_WIN) |
brettw | e3352685 | 2015-10-03 00:46:01 | [diff] [blame] | 473 | MessageBoxW(nullptr, base::UTF8ToUTF16(str).c_str(), L"Fatal error", |
| 474 | MB_OK | MB_ICONHAND | MB_TOPMOST); |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 475 | #else |
[email protected] | 561513f | 2010-12-16 23:29:25 | [diff] [blame] | 476 | // We intentionally don't implement a dialog on other platforms. |
| 477 | // You can just look at stderr. |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 478 | #endif // defined(OS_WIN) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 479 | } |
[email protected] | f2c0549 | 2014-06-17 12:04:23 | [diff] [blame] | 480 | #endif // !defined(NDEBUG) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 481 | |
[email protected] | 3f85caa | 2009-04-14 16:52:11 | [diff] [blame] | 482 | #if defined(OS_WIN) |
| 483 | LogMessage::SaveLastError::SaveLastError() : last_error_(::GetLastError()) { |
| 484 | } |
| 485 | |
| 486 | LogMessage::SaveLastError::~SaveLastError() { |
| 487 | ::SetLastError(last_error_); |
| 488 | } |
| 489 | #endif // defined(OS_WIN) |
| 490 | |
[email protected] | eae9c06 | 2011-01-11 00:50:59 | [diff] [blame] | 491 | LogMessage::LogMessage(const char* file, int line, LogSeverity severity) |
| 492 | : severity_(severity), file_(file), line_(line) { |
| 493 | Init(file, line); |
| 494 | } |
| 495 | |
tnagel | 4a045d3f | 2015-07-12 14:19:28 | [diff] [blame] | 496 | LogMessage::LogMessage(const char* file, int line, const char* condition) |
| 497 | : severity_(LOG_FATAL), file_(file), line_(line) { |
| 498 | Init(file, line); |
| 499 | stream_ << "Check failed: " << condition << ". "; |
| 500 | } |
| 501 | |
[email protected] | 9c7132e | 2011-02-08 07:39:08 | [diff] [blame] | 502 | LogMessage::LogMessage(const char* file, int line, std::string* result) |
[email protected] | 162ac0f | 2010-11-04 15:50:49 | [diff] [blame] | 503 | : severity_(LOG_FATAL), file_(file), line_(line) { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 504 | Init(file, line); |
[email protected] | 9c7132e | 2011-02-08 07:39:08 | [diff] [blame] | 505 | stream_ << "Check failed: " << *result; |
| 506 | delete result; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 507 | } |
| 508 | |
[email protected] | fb62a53 | 2009-02-12 01:19:05 | [diff] [blame] | 509 | LogMessage::LogMessage(const char* file, int line, LogSeverity severity, |
[email protected] | 9c7132e | 2011-02-08 07:39:08 | [diff] [blame] | 510 | std::string* result) |
[email protected] | 162ac0f | 2010-11-04 15:50:49 | [diff] [blame] | 511 | : severity_(severity), file_(file), line_(line) { |
[email protected] | fb62a53 | 2009-02-12 01:19:05 | [diff] [blame] | 512 | Init(file, line); |
[email protected] | 9c7132e | 2011-02-08 07:39:08 | [diff] [blame] | 513 | stream_ << "Check failed: " << *result; |
| 514 | delete result; |
[email protected] | fb62a53 | 2009-02-12 01:19:05 | [diff] [blame] | 515 | } |
| 516 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 517 | LogMessage::~LogMessage() { |
jam | 79dc59a | 2015-08-17 03:38:16 | [diff] [blame] | 518 | #if !defined(OFFICIAL_BUILD) && !defined(OS_NACL) && !defined(__UCLIBC__) |
brucedawson | 7c559eb | 2015-09-05 00:34:42 | [diff] [blame] | 519 | if (severity_ == LOG_FATAL && !base::debug::BeingDebugged()) { |
| 520 | // Include a stack trace on a fatal, unless a debugger is attached. |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 521 | base::debug::StackTrace trace; |
[email protected] | d1ccc35a | 2010-03-24 05:03:24 | [diff] [blame] | 522 | stream_ << std::endl; // Newline to separate from log message. |
| 523 | trace.OutputToStream(&stream_); |
| 524 | } |
[email protected] | 1d8c270 | 2008-08-19 23:39:32 | [diff] [blame] | 525 | #endif |
[email protected] | d1ccc35a | 2010-03-24 05:03:24 | [diff] [blame] | 526 | stream_ << std::endl; |
| 527 | std::string str_newline(stream_.str()); |
| 528 | |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 529 | // Give any log message handler first dibs on the message. |
[email protected] | 5e3f7c2 | 2013-06-21 21:15:33 | [diff] [blame] | 530 | if (log_message_handler && |
| 531 | log_message_handler(severity_, file_, line_, |
| 532 | message_start_, str_newline)) { |
[email protected] | 162ac0f | 2010-11-04 15:50:49 | [diff] [blame] | 533 | // The handler took care of it, no further processing. |
[email protected] | 2b07b841 | 2009-11-25 15:26:34 | [diff] [blame] | 534 | return; |
[email protected] | 162ac0f | 2010-11-04 15:50:49 | [diff] [blame] | 535 | } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 536 | |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 537 | if ((g_logging_destination & LOG_TO_SYSTEM_DEBUG_LOG) != 0) { |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 538 | #if defined(OS_WIN) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 539 | OutputDebugStringA(str_newline.c_str()); |
mark | 4c7449c | 2015-11-10 19:53:42 | [diff] [blame] | 540 | #elif defined(OS_MACOSX) |
| 541 | // In LOG_TO_SYSTEM_DEBUG_LOG mode, log messages are always written to |
| 542 | // stderr. If stderr is /dev/null, also log via ASL (Apple System Log). If |
| 543 | // there's something weird about stderr, assume that log messages are going |
| 544 | // nowhere and log via ASL too. Messages logged via ASL show up in |
| 545 | // Console.app. |
| 546 | // |
| 547 | // Programs started by launchd, as UI applications normally are, have had |
| 548 | // stderr connected to /dev/null since OS X 10.8. Prior to that, stderr was |
| 549 | // a pipe to launchd, which logged what it received (see log_redirect_fd in |
| 550 | // 10.7.5 launchd-392.39/launchd/src/launchd_core_logic.c). |
| 551 | // |
| 552 | // Another alternative would be to determine whether stderr is a pipe to |
| 553 | // launchd and avoid logging via ASL only in that case. See 10.7.5 |
| 554 | // CF-635.21/CFUtilities.c also_do_stderr(). This would result in logging to |
| 555 | // both stderr and ASL even in tests, where it's undesirable to log to the |
| 556 | // system log at all. |
| 557 | // |
| 558 | // Note that the ASL client by default discards messages whose levels are |
| 559 | // below ASL_LEVEL_NOTICE. It's possible to change that with |
| 560 | // asl_set_filter(), but this is pointless because syslogd normally applies |
| 561 | // the same filter. |
| 562 | const bool log_via_asl = []() { |
| 563 | struct stat stderr_stat; |
| 564 | if (fstat(fileno(stderr), &stderr_stat) == -1) { |
| 565 | return true; |
| 566 | } |
| 567 | if (!S_ISCHR(stderr_stat.st_mode)) { |
| 568 | return false; |
| 569 | } |
| 570 | |
| 571 | struct stat dev_null_stat; |
| 572 | if (stat(_PATH_DEVNULL, &dev_null_stat) == -1) { |
| 573 | return true; |
| 574 | } |
| 575 | |
| 576 | return !S_ISCHR(dev_null_stat.st_mode) || |
| 577 | stderr_stat.st_rdev == dev_null_stat.st_rdev; |
| 578 | }(); |
| 579 | |
| 580 | if (log_via_asl) { |
| 581 | // Log roughly the same way that CFLog() and NSLog() would. See 10.10.5 |
| 582 | // CF-1153.18/CFUtilities.c __CFLogCString(). |
| 583 | // |
| 584 | // The ASL facility is set to the main bundle ID if available. Otherwise, |
| 585 | // "com.apple.console" is used. |
| 586 | CFBundleRef main_bundle = CFBundleGetMainBundle(); |
| 587 | CFStringRef main_bundle_id_cf = |
| 588 | main_bundle ? CFBundleGetIdentifier(main_bundle) : nullptr; |
| 589 | std::string asl_facility = |
| 590 | main_bundle_id_cf ? base::SysCFStringRefToUTF8(main_bundle_id_cf) |
| 591 | : std::string("com.apple.console"); |
| 592 | |
| 593 | class ASLClient { |
| 594 | public: |
| 595 | explicit ASLClient(const std::string& asl_facility) |
| 596 | : client_(asl_open(nullptr, |
| 597 | asl_facility.c_str(), |
| 598 | ASL_OPT_NO_DELAY)) {} |
| 599 | ~ASLClient() { asl_close(client_); } |
| 600 | |
| 601 | aslclient get() const { return client_; } |
| 602 | |
| 603 | private: |
| 604 | aslclient client_; |
| 605 | DISALLOW_COPY_AND_ASSIGN(ASLClient); |
| 606 | } asl_client(asl_facility); |
| 607 | |
| 608 | class ASLMessage { |
| 609 | public: |
| 610 | ASLMessage() : message_(asl_new(ASL_TYPE_MSG)) {} |
| 611 | ~ASLMessage() { asl_free(message_); } |
| 612 | |
| 613 | aslmsg get() const { return message_; } |
| 614 | |
| 615 | private: |
| 616 | aslmsg message_; |
| 617 | DISALLOW_COPY_AND_ASSIGN(ASLMessage); |
| 618 | } asl_message; |
| 619 | |
| 620 | // By default, messages are only readable by the admin group. Explicitly |
| 621 | // make them readable by the user generating the messages. |
| 622 | char euid_string[12]; |
| 623 | snprintf(euid_string, arraysize(euid_string), "%d", geteuid()); |
| 624 | asl_set(asl_message.get(), ASL_KEY_READ_UID, euid_string); |
| 625 | |
| 626 | // Map Chrome log severities to ASL log levels. |
| 627 | const char* const asl_level_string = [](LogSeverity severity) { |
| 628 | // ASL_LEVEL_* are ints, but ASL needs equivalent strings. This |
| 629 | // non-obvious two-step macro trick achieves what's needed. |
| 630 | // https://gcc.gnu.org/onlinedocs/cpp/Stringification.html |
| 631 | #define ASL_LEVEL_STR(level) ASL_LEVEL_STR_X(level) |
| 632 | #define ASL_LEVEL_STR_X(level) #level |
| 633 | switch (severity) { |
| 634 | case LOG_INFO: |
| 635 | return ASL_LEVEL_STR(ASL_LEVEL_INFO); |
| 636 | case LOG_WARNING: |
| 637 | return ASL_LEVEL_STR(ASL_LEVEL_WARNING); |
| 638 | case LOG_ERROR: |
| 639 | return ASL_LEVEL_STR(ASL_LEVEL_ERR); |
| 640 | case LOG_FATAL: |
| 641 | return ASL_LEVEL_STR(ASL_LEVEL_CRIT); |
| 642 | default: |
| 643 | return severity < 0 ? ASL_LEVEL_STR(ASL_LEVEL_DEBUG) |
| 644 | : ASL_LEVEL_STR(ASL_LEVEL_NOTICE); |
| 645 | } |
| 646 | #undef ASL_LEVEL_STR |
| 647 | #undef ASL_LEVEL_STR_X |
| 648 | }(severity_); |
| 649 | asl_set(asl_message.get(), ASL_KEY_LEVEL, asl_level_string); |
| 650 | |
| 651 | asl_set(asl_message.get(), ASL_KEY_MSG, str_newline.c_str()); |
| 652 | |
| 653 | asl_send(asl_client.get(), asl_message.get()); |
| 654 | } |
[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 655 | #elif defined(OS_ANDROID) |
[email protected] | efbae7da | 2013-05-21 22:39:25 | [diff] [blame] | 656 | android_LogPriority priority = |
| 657 | (severity_ < 0) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_UNKNOWN; |
[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 658 | switch (severity_) { |
| 659 | case LOG_INFO: |
| 660 | priority = ANDROID_LOG_INFO; |
| 661 | break; |
| 662 | case LOG_WARNING: |
| 663 | priority = ANDROID_LOG_WARN; |
| 664 | break; |
| 665 | case LOG_ERROR: |
[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 666 | priority = ANDROID_LOG_ERROR; |
| 667 | break; |
| 668 | case LOG_FATAL: |
| 669 | priority = ANDROID_LOG_FATAL; |
| 670 | break; |
| 671 | } |
| 672 | __android_log_write(priority, "chromium", str_newline.c_str()); |
[email protected] | 107bc0f1 | 2008-08-26 17:48:18 | [diff] [blame] | 673 | #endif |
[email protected] | 5110538 | 2014-03-14 17:02:15 | [diff] [blame] | 674 | ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr)); |
[email protected] | 469006c | 2010-09-24 15:43:06 | [diff] [blame] | 675 | fflush(stderr); |
[email protected] | a33c989 | 2008-08-25 20:10:31 | [diff] [blame] | 676 | } else if (severity_ >= kAlwaysPrintErrorLevel) { |
| 677 | // When we're only outputting to a log file, above a certain log level, we |
| 678 | // should still output to stderr so that we can better detect and diagnose |
| 679 | // problems with unit tests, especially on the buildbots. |
[email protected] | 5110538 | 2014-03-14 17:02:15 | [diff] [blame] | 680 | ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr)); |
[email protected] | 1ce4105 | 2009-12-02 00:34:02 | [diff] [blame] | 681 | fflush(stderr); |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 682 | } |
[email protected] | 52a261f | 2009-03-03 15:01:12 | [diff] [blame] | 683 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 684 | // write to log file |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 685 | if ((g_logging_destination & LOG_TO_FILE) != 0) { |
[email protected] | 17dcf75 | 2013-07-15 21:47:09 | [diff] [blame] | 686 | // We can have multiple threads and/or processes, so try to prevent them |
| 687 | // from clobbering each other's writes. |
| 688 | // If the client app did not call InitLogging, and the lock has not |
| 689 | // been created do it now. We do this on demand, but if two threads try |
| 690 | // to do this at the same time, there will be a race condition to create |
| 691 | // the lock. This is why InitLogging should be called from the main |
| 692 | // thread at the beginning of execution. |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 693 | #if !defined(OS_WIN) |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 694 | LoggingLock::Init(LOCK_LOG_FILE, nullptr); |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 695 | LoggingLock logging_lock; |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 696 | #endif |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 697 | if (InitializeLogFileHandle()) { |
[email protected] | f6abeba | 2008-08-08 13:27:28 | [diff] [blame] | 698 | #if defined(OS_WIN) |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 699 | DWORD num_written; |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 700 | WriteFile(g_log_file, |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 701 | static_cast<const void*>(str_newline.c_str()), |
| 702 | static_cast<DWORD>(str_newline.length()), |
| 703 | &num_written, |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 704 | nullptr); |
[email protected] | cba2196 | 2010-08-31 22:35:55 | [diff] [blame] | 705 | #else |
[email protected] | 5110538 | 2014-03-14 17:02:15 | [diff] [blame] | 706 | ignore_result(fwrite( |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 707 | str_newline.data(), str_newline.size(), 1, g_log_file)); |
| 708 | fflush(g_log_file); |
[email protected] | cba2196 | 2010-08-31 22:35:55 | [diff] [blame] | 709 | #endif |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
| 713 | if (severity_ == LOG_FATAL) { |
[email protected] | eb4c4d03 | 2012-04-03 18:45:05 | [diff] [blame] | 714 | // Ensure the first characters of the string are on the stack so they |
| 715 | // are contained in minidumps for diagnostic purposes. |
| 716 | char str_stack[1024]; |
| 717 | str_newline.copy(str_stack, arraysize(str_stack)); |
| 718 | base::debug::Alias(str_stack); |
| 719 | |
[email protected] | 82d89ab | 2014-02-28 18:25:34 | [diff] [blame] | 720 | if (log_assert_handler) { |
| 721 | // Make a copy of the string for the handler out of paranoia. |
| 722 | log_assert_handler(std::string(stream_.str())); |
[email protected] | 1ffe08c1 | 2008-08-13 11:15:11 | [diff] [blame] | 723 | } else { |
[email protected] | 82d89ab | 2014-02-28 18:25:34 | [diff] [blame] | 724 | // Don't use the string with the newline, get a fresh version to send to |
| 725 | // the debug message process. We also don't display assertions to the |
| 726 | // user in release mode. The enduser can't do anything with this |
| 727 | // information, and displaying message boxes when the application is |
| 728 | // hosed can cause additional problems. |
[email protected] | 4d590127 | 2008-11-06 00:33:50 | [diff] [blame] | 729 | #ifndef NDEBUG |
brucedawson | 7c559eb | 2015-09-05 00:34:42 | [diff] [blame] | 730 | if (!base::debug::BeingDebugged()) { |
| 731 | // Displaying a dialog is unnecessary when debugging and can complicate |
| 732 | // debugging. |
| 733 | DisplayDebugMessageInDialog(stream_.str()); |
| 734 | } |
[email protected] | 4d590127 | 2008-11-06 00:33:50 | [diff] [blame] | 735 | #endif |
[email protected] | 82d89ab | 2014-02-28 18:25:34 | [diff] [blame] | 736 | // Crash the process to generate a dump. |
| 737 | base::debug::BreakDebugger(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
[email protected] | eae9c06 | 2011-01-11 00:50:59 | [diff] [blame] | 742 | // writes the common header info to the stream |
| 743 | void LogMessage::Init(const char* file, int line) { |
| 744 | base::StringPiece filename(file); |
| 745 | size_t last_slash_pos = filename.find_last_of("\\/"); |
| 746 | if (last_slash_pos != base::StringPiece::npos) |
| 747 | filename.remove_prefix(last_slash_pos + 1); |
| 748 | |
| 749 | // TODO(darin): It might be nice if the columns were fixed width. |
| 750 | |
| 751 | stream_ << '['; |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 752 | if (g_log_process_id) |
[email protected] | eae9c06 | 2011-01-11 00:50:59 | [diff] [blame] | 753 | stream_ << CurrentProcessId() << ':'; |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 754 | if (g_log_thread_id) |
[email protected] | 63e6680 | 2012-01-18 21:21:09 | [diff] [blame] | 755 | stream_ << base::PlatformThread::CurrentId() << ':'; |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 756 | if (g_log_timestamp) { |
| 757 | time_t t = time(nullptr); |
[email protected] | eae9c06 | 2011-01-11 00:50:59 | [diff] [blame] | 758 | struct tm local_time = {0}; |
mostynb | 7e42a8f | 2014-12-19 12:47:46 | [diff] [blame] | 759 | #ifdef _MSC_VER |
[email protected] | eae9c06 | 2011-01-11 00:50:59 | [diff] [blame] | 760 | localtime_s(&local_time, &t); |
| 761 | #else |
| 762 | localtime_r(&t, &local_time); |
| 763 | #endif |
| 764 | struct tm* tm_time = &local_time; |
| 765 | stream_ << std::setfill('0') |
| 766 | << std::setw(2) << 1 + tm_time->tm_mon |
| 767 | << std::setw(2) << tm_time->tm_mday |
| 768 | << '/' |
| 769 | << std::setw(2) << tm_time->tm_hour |
| 770 | << std::setw(2) << tm_time->tm_min |
| 771 | << std::setw(2) << tm_time->tm_sec |
| 772 | << ':'; |
| 773 | } |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 774 | if (g_log_tickcount) |
[email protected] | eae9c06 | 2011-01-11 00:50:59 | [diff] [blame] | 775 | stream_ << TickCount() << ':'; |
| 776 | if (severity_ >= 0) |
[email protected] | 80f360a | 2014-01-23 01:36:19 | [diff] [blame] | 777 | stream_ << log_severity_name(severity_); |
[email protected] | eae9c06 | 2011-01-11 00:50:59 | [diff] [blame] | 778 | else |
| 779 | stream_ << "VERBOSE" << -severity_; |
| 780 | |
| 781 | stream_ << ":" << filename << "(" << line << ")] "; |
| 782 | |
pkasting | 9cf9b94 | 2014-10-01 22:18:43 | [diff] [blame] | 783 | message_start_ = stream_.str().length(); |
[email protected] | eae9c06 | 2011-01-11 00:50:59 | [diff] [blame] | 784 | } |
| 785 | |
[email protected] | d8617a6 | 2009-10-09 23:52:20 | [diff] [blame] | 786 | #if defined(OS_WIN) |
| 787 | // This has already been defined in the header, but defining it again as DWORD |
| 788 | // ensures that the type used in the header is equivalent to DWORD. If not, |
| 789 | // the redefinition is a compile error. |
| 790 | typedef DWORD SystemErrorCode; |
| 791 | #endif |
| 792 | |
| 793 | SystemErrorCode GetLastSystemErrorCode() { |
| 794 | #if defined(OS_WIN) |
| 795 | return ::GetLastError(); |
| 796 | #elif defined(OS_POSIX) |
| 797 | return errno; |
| 798 | #else |
| 799 | #error Not implemented |
| 800 | #endif |
| 801 | } |
| 802 | |
| 803 | #if defined(OS_WIN) |
[email protected] | c914d8a | 2014-04-23 01:11:01 | [diff] [blame] | 804 | BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code) { |
thestig | 75f8735 | 2014-12-03 21:42:27 | [diff] [blame] | 805 | const int kErrorMessageBufferSize = 256; |
| 806 | char msgbuf[kErrorMessageBufferSize]; |
[email protected] | c914d8a | 2014-04-23 01:11:01 | [diff] [blame] | 807 | DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 808 | DWORD len = FormatMessageA(flags, nullptr, error_code, 0, msgbuf, |
| 809 | arraysize(msgbuf), nullptr); |
[email protected] | c914d8a | 2014-04-23 01:11:01 | [diff] [blame] | 810 | if (len) { |
| 811 | // Messages returned by system end with line breaks. |
| 812 | return base::CollapseWhitespaceASCII(msgbuf, true) + |
| 813 | base::StringPrintf(" (0x%X)", error_code); |
| 814 | } |
| 815 | return base::StringPrintf("Error (0x%X) while retrieving error. (0x%X)", |
| 816 | GetLastError(), error_code); |
[email protected] | d8617a6 | 2009-10-09 23:52:20 | [diff] [blame] | 817 | } |
[email protected] | c914d8a | 2014-04-23 01:11:01 | [diff] [blame] | 818 | #elif defined(OS_POSIX) |
| 819 | BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code) { |
brettw | 6ee6fd6 | 2015-06-09 18:05:24 | [diff] [blame] | 820 | return base::safe_strerror(error_code); |
[email protected] | c914d8a | 2014-04-23 01:11:01 | [diff] [blame] | 821 | } |
| 822 | #else |
| 823 | #error Not implemented |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 824 | #endif // defined(OS_WIN) |
[email protected] | d8617a6 | 2009-10-09 23:52:20 | [diff] [blame] | 825 | |
[email protected] | c914d8a | 2014-04-23 01:11:01 | [diff] [blame] | 826 | |
| 827 | #if defined(OS_WIN) |
[email protected] | d8617a6 | 2009-10-09 23:52:20 | [diff] [blame] | 828 | Win32ErrorLogMessage::Win32ErrorLogMessage(const char* file, |
| 829 | int line, |
| 830 | LogSeverity severity, |
| 831 | SystemErrorCode err) |
| 832 | : err_(err), |
[email protected] | d8617a6 | 2009-10-09 23:52:20 | [diff] [blame] | 833 | log_message_(file, line, severity) { |
| 834 | } |
| 835 | |
| 836 | Win32ErrorLogMessage::~Win32ErrorLogMessage() { |
[email protected] | c914d8a | 2014-04-23 01:11:01 | [diff] [blame] | 837 | stream() << ": " << SystemErrorCodeToString(err_); |
[email protected] | 20909e7 | 2012-04-05 16:57:06 | [diff] [blame] | 838 | // We're about to crash (CHECK). Put |err_| on the stack (by placing it in a |
| 839 | // field) and use Alias in hopes that it makes it into crash dumps. |
| 840 | DWORD last_error = err_; |
| 841 | base::debug::Alias(&last_error); |
[email protected] | d8617a6 | 2009-10-09 23:52:20 | [diff] [blame] | 842 | } |
| 843 | #elif defined(OS_POSIX) |
| 844 | ErrnoLogMessage::ErrnoLogMessage(const char* file, |
| 845 | int line, |
| 846 | LogSeverity severity, |
| 847 | SystemErrorCode err) |
| 848 | : err_(err), |
| 849 | log_message_(file, line, severity) { |
| 850 | } |
| 851 | |
| 852 | ErrnoLogMessage::~ErrnoLogMessage() { |
[email protected] | c914d8a | 2014-04-23 01:11:01 | [diff] [blame] | 853 | stream() << ": " << SystemErrorCodeToString(err_); |
[email protected] | d8617a6 | 2009-10-09 23:52:20 | [diff] [blame] | 854 | } |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 855 | #endif // defined(OS_WIN) |
[email protected] | d8617a6 | 2009-10-09 23:52:20 | [diff] [blame] | 856 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 857 | void CloseLogFile() { |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 858 | #if !defined(OS_WIN) |
[email protected] | 5b84fe3 | 2010-09-14 22:24:55 | [diff] [blame] | 859 | LoggingLock logging_lock; |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 860 | #endif |
[email protected] | 17dcf75 | 2013-07-15 21:47:09 | [diff] [blame] | 861 | CloseLogFileUnlocked(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 862 | } |
| 863 | |
[email protected] | e36ddc8 | 2009-12-08 04:22:50 | [diff] [blame] | 864 | void RawLog(int level, const char* message) { |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 865 | if (level >= g_min_log_level) { |
[email protected] | e36ddc8 | 2009-12-08 04:22:50 | [diff] [blame] | 866 | size_t bytes_written = 0; |
| 867 | const size_t message_len = strlen(message); |
| 868 | int rv; |
| 869 | while (bytes_written < message_len) { |
| 870 | rv = HANDLE_EINTR( |
| 871 | write(STDERR_FILENO, message + bytes_written, |
| 872 | message_len - bytes_written)); |
| 873 | if (rv < 0) { |
| 874 | // Give up, nothing we can do now. |
| 875 | break; |
| 876 | } |
| 877 | bytes_written += rv; |
| 878 | } |
| 879 | |
| 880 | if (message_len > 0 && message[message_len - 1] != '\n') { |
| 881 | do { |
| 882 | rv = HANDLE_EINTR(write(STDERR_FILENO, "\n", 1)); |
| 883 | if (rv < 0) { |
| 884 | // Give up, nothing we can do now. |
| 885 | break; |
| 886 | } |
| 887 | } while (rv != 1); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | if (level == LOG_FATAL) |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 892 | base::debug::BreakDebugger(); |
[email protected] | e36ddc8 | 2009-12-08 04:22:50 | [diff] [blame] | 893 | } |
| 894 | |
[email protected] | 34a90773 | 2012-01-20 06:33:27 | [diff] [blame] | 895 | // This was defined at the beginning of this file. |
| 896 | #undef write |
| 897 | |
[email protected] | f01b88a | 2013-02-27 22:04:00 | [diff] [blame] | 898 | #if defined(OS_WIN) |
ananta | 61762fb | 2015-09-18 01:00:09 | [diff] [blame] | 899 | bool IsLoggingToFileEnabled() { |
| 900 | return g_logging_destination & LOG_TO_FILE; |
| 901 | } |
| 902 | |
[email protected] | f01b88a | 2013-02-27 22:04:00 | [diff] [blame] | 903 | std::wstring GetLogFileFullPath() { |
thestig | 3e4787d | 2015-05-19 19:31:52 | [diff] [blame] | 904 | if (g_log_file_name) |
| 905 | return *g_log_file_name; |
[email protected] | f01b88a | 2013-02-27 22:04:00 | [diff] [blame] | 906 | return std::wstring(); |
| 907 | } |
| 908 | #endif |
| 909 | |
tnagel | 80388e68 | 2015-05-26 13:27:56 | [diff] [blame] | 910 | BASE_EXPORT void LogErrorNotReached(const char* file, int line) { |
tnagel | ff3f34a | 2015-05-24 12:59:14 | [diff] [blame] | 911 | LogMessage(file, line, LOG_ERROR).stream() |
| 912 | << "NOTREACHED() hit."; |
| 913 | } |
| 914 | |
[email protected] | 96fd003 | 2009-04-24 00:13:08 | [diff] [blame] | 915 | } // namespace logging |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 916 | |
[email protected] | 81411c6 | 2014-07-08 23:03:06 | [diff] [blame] | 917 | std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { |
thestig | 75f8735 | 2014-12-03 21:42:27 | [diff] [blame] | 918 | return out << base::WideToUTF8(wstr); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 919 | } |