Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: base/logging.cc

Issue 1429953004: win: Use FormatMessage[W]() instead of FormatMessageA() for logging (Closed) Base URL: https://chromium.googlesource.com/chromium/mini_chromium@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include <iomanip> 10 #include <iomanip>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 void SetLogMessageHandler(LogMessageHandlerFunction log_message_handler) { 47 void SetLogMessageHandler(LogMessageHandlerFunction log_message_handler) {
48 g_log_message_handler = log_message_handler; 48 g_log_message_handler = log_message_handler;
49 } 49 }
50 50
51 LogMessageHandlerFunction GetLogMessageHandler() { 51 LogMessageHandlerFunction GetLogMessageHandler() {
52 return g_log_message_handler; 52 return g_log_message_handler;
53 } 53 }
54 54
55 #if defined(OS_WIN) 55 #if defined(OS_WIN)
56 std::string SystemErrorCodeToString(unsigned long error_code) { 56 std::string SystemErrorCodeToString(unsigned long error_code) {
57 char msgbuf[256]; 57 wchar_t msgbuf[256];
58 DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | 58 DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
59 FORMAT_MESSAGE_MAX_WIDTH_MASK; 59 FORMAT_MESSAGE_MAX_WIDTH_MASK;
60 DWORD len = FormatMessageA( 60 DWORD len = FormatMessage(
61 flags, NULL, error_code, 0, msgbuf, arraysize(msgbuf), NULL); 61 flags, nullptr, error_code, 0, msgbuf, arraysize(msgbuf), nullptr);
62 if (len) { 62 if (len) {
63 return msgbuf + base::StringPrintf(" (0x%X)", error_code); 63 // Most system messages end in a period and a space. Remove the space if
64 // it’s there, because the following StringPrintf() includes one.
65 if (len >= 1 && msgbuf[len - 1] == ' ') {
66 msgbuf[len - 1] = '\0';
67 }
68 return base::StringPrintf("%s (%u)",
69 base::UTF16ToUTF8(msgbuf).c_str(), error_code);
64 } 70 }
65 return base::StringPrintf("Error (0x%X) while retrieving error. (0x%X)", 71 return base::StringPrintf("Error %u while retrieving error %u",
66 GetLastError(), 72 GetLastError(),
67 error_code); 73 error_code);
68 } 74 }
69 #endif // OS_WIN 75 #endif // OS_WIN
70 76
71 LogMessage::LogMessage(const char* function, 77 LogMessage::LogMessage(const char* function,
72 const char* file_path, 78 const char* file_path,
73 int line, 79 int line,
74 LogSeverity severity) 80 LogSeverity severity)
75 : stream_(), 81 : stream_(),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 156
151 stream_ << '[' 157 stream_ << '['
152 << pid 158 << pid
153 << ':' 159 << ':'
154 << thread 160 << thread
155 << ':' 161 << ':'
156 << std::setfill('0'); 162 << std::setfill('0');
157 163
158 #if defined(OS_POSIX) 164 #if defined(OS_POSIX)
159 timeval tv; 165 timeval tv;
160 gettimeofday(&tv, NULL); 166 gettimeofday(&tv, nullptr);
161 tm local_time; 167 tm local_time;
162 localtime_r(&tv.tv_sec, &local_time); 168 localtime_r(&tv.tv_sec, &local_time);
163 stream_ << std::setw(4) << local_time.tm_year + 1900 169 stream_ << std::setw(4) << local_time.tm_year + 1900
164 << std::setw(2) << local_time.tm_mon + 1 170 << std::setw(2) << local_time.tm_mon + 1
165 << std::setw(2) << local_time.tm_mday 171 << std::setw(2) << local_time.tm_mday
166 << ',' 172 << ','
167 << std::setw(2) << local_time.tm_hour 173 << std::setw(2) << local_time.tm_hour
168 << std::setw(2) << local_time.tm_min 174 << std::setw(2) << local_time.tm_min
169 << std::setw(2) << local_time.tm_sec 175 << std::setw(2) << local_time.tm_sec
170 << '.' 176 << '.'
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 stream() << ": " 239 stream() << ": "
234 << base::safe_strerror(err_) 240 << base::safe_strerror(err_)
235 << " (" 241 << " ("
236 << err_ 242 << err_
237 << ")"; 243 << ")";
238 } 244 }
239 245
240 #endif // OS_POSIX 246 #endif // OS_POSIX
241 247
242 } // namespace logging 248 } // namespace logging
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698