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

Side by Side Diff: base/logging.cc

Issue 773373002: Update from https://crrev.com/306706 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 | « DEPS ('k') | base/process/kill.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <io.h> 8 #include <io.h>
9 #include <windows.h> 9 #include <windows.h>
10 typedef HANDLE FileHandle; 10 typedef HANDLE FileHandle;
11 typedef HANDLE MutexHandle; 11 typedef HANDLE MutexHandle;
12 // Windows warns on using write(). It prefers _write(). 12 // Windows warns on using write(). It prefers _write().
13 #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count)) 13 #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count))
14 // Windows doesn't define STDERR_FILENO. Define it here. 14 // Windows doesn't define STDERR_FILENO. Define it here.
15 #define STDERR_FILENO 2 15 #define STDERR_FILENO 2
16 #elif defined(OS_MACOSX) 16 #elif defined(OS_MACOSX)
17 #include <mach/mach.h> 17 #include <mach/mach.h>
18 #include <mach/mach_time.h> 18 #include <mach/mach_time.h>
19 #include <mach-o/dyld.h> 19 #include <mach-o/dyld.h>
20 #elif defined(OS_POSIX) 20 #elif defined(OS_POSIX)
21 #if defined(OS_NACL) 21 #if defined(OS_NACL)
22 #include <sys/time.h> // timespec doesn't seem to be in <time.h> 22 #include <sys/time.h> // timespec doesn't seem to be in <time.h>
23 #else 23 #else
24 #include <sys/syscall.h> 24 #include <sys/syscall.h>
25 #endif 25 #endif
26 #include <time.h> 26 #include <time.h>
27 #endif 27 #endif
28 28
29 #if defined(OS_POSIX) 29 #if defined(OS_POSIX)
30 #include <errno.h> 30 #include <errno.h>
31 #include <pthread.h> 31 #include <pthread.h>
32 #include <stdio.h> 32 #include <stdio.h>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 namespace logging { 69 namespace logging {
70 70
71 namespace { 71 namespace {
72 72
73 VlogInfo* g_vlog_info = NULL; 73 VlogInfo* g_vlog_info = NULL;
74 VlogInfo* g_vlog_info_prev = NULL; 74 VlogInfo* g_vlog_info_prev = NULL;
75 75
76 const char* const log_severity_names[LOG_NUM_SEVERITIES] = { 76 const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
77 "INFO", "WARNING", "ERROR", "FATAL" }; 77 "INFO", "WARNING", "ERROR", "FATAL" };
78 78
79 const char* log_severity_name(int severity) 79 const char* log_severity_name(int severity) {
80 {
81 if (severity >= 0 && severity < LOG_NUM_SEVERITIES) 80 if (severity >= 0 && severity < LOG_NUM_SEVERITIES)
82 return log_severity_names[severity]; 81 return log_severity_names[severity];
83 return "UNKNOWN"; 82 return "UNKNOWN";
84 } 83 }
85 84
86 int min_log_level = 0; 85 int min_log_level = 0;
87 86
88 LoggingDestination logging_destination = LOG_DEFAULT; 87 LoggingDestination logging_destination = LOG_DEFAULT;
89 88
90 // For LOG_ERROR and above, always print to stderr. 89 // For LOG_ERROR and above, always print to stderr.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 static_cast<int64>(ts.tv_sec) * 1000000 + 144 static_cast<int64>(ts.tv_sec) * 1000000 +
146 static_cast<int64>(ts.tv_nsec) / 1000; 145 static_cast<int64>(ts.tv_nsec) / 1000;
147 146
148 return absolute_micro; 147 return absolute_micro;
149 #endif 148 #endif
150 } 149 }
151 150
152 void DeleteFilePath(const PathString& log_name) { 151 void DeleteFilePath(const PathString& log_name) {
153 #if defined(OS_WIN) 152 #if defined(OS_WIN)
154 DeleteFile(log_name.c_str()); 153 DeleteFile(log_name.c_str());
155 #elif defined (OS_NACL) 154 #elif defined(OS_NACL)
156 // Do nothing; unlink() isn't supported on NaCl. 155 // Do nothing; unlink() isn't supported on NaCl.
157 #else 156 #else
158 unlink(log_name.c_str()); 157 unlink(log_name.c_str());
159 #endif 158 #endif
160 } 159 }
161 160
162 PathString GetDefaultLogFile() { 161 PathString GetDefaultLogFile() {
163 #if defined(OS_WIN) 162 #if defined(OS_WIN)
164 // On Windows we use the same path as the exe. 163 // On Windows we use the same path as the exe.
165 wchar_t module_name[MAX_PATH]; 164 wchar_t module_name[MAX_PATH];
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 return ::GetLastError(); 698 return ::GetLastError();
700 #elif defined(OS_POSIX) 699 #elif defined(OS_POSIX)
701 return errno; 700 return errno;
702 #else 701 #else
703 #error Not implemented 702 #error Not implemented
704 #endif 703 #endif
705 } 704 }
706 705
707 #if defined(OS_WIN) 706 #if defined(OS_WIN)
708 BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code) { 707 BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code) {
709 const int error_message_buffer_size = 256; 708 const int kErrorMessageBufferSize = 256;
710 char msgbuf[error_message_buffer_size]; 709 char msgbuf[kErrorMessageBufferSize];
711 DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; 710 DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
712 DWORD len = FormatMessageA(flags, NULL, error_code, 0, msgbuf, 711 DWORD len = FormatMessageA(flags, NULL, error_code, 0, msgbuf,
713 arraysize(msgbuf), NULL); 712 arraysize(msgbuf), NULL);
714 if (len) { 713 if (len) {
715 // Messages returned by system end with line breaks. 714 // Messages returned by system end with line breaks.
716 return base::CollapseWhitespaceASCII(msgbuf, true) + 715 return base::CollapseWhitespaceASCII(msgbuf, true) +
717 base::StringPrintf(" (0x%X)", error_code); 716 base::StringPrintf(" (0x%X)", error_code);
718 } 717 }
719 return base::StringPrintf("Error (0x%X) while retrieving error. (0x%X)", 718 return base::StringPrintf("Error (0x%X) while retrieving error. (0x%X)",
720 GetLastError(), error_code); 719 GetLastError(), error_code);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 std::wstring GetLogFileFullPath() { 800 std::wstring GetLogFileFullPath() {
802 if (log_file_name) 801 if (log_file_name)
803 return *log_file_name; 802 return *log_file_name;
804 return std::wstring(); 803 return std::wstring();
805 } 804 }
806 #endif 805 #endif
807 806
808 } // namespace logging 807 } // namespace logging
809 808
810 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { 809 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) {
811 return out << base::WideToUTF8(std::wstring(wstr)); 810 return out << base::WideToUTF8(wstr);
812 } 811 }
OLDNEW
« no previous file with comments | « DEPS ('k') | base/process/kill.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698