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

Side by Side Diff: base/logging.h

Issue 2692273008: Hacky slashy (Closed)
Patch Set: wip Created 3 years, 10 months 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
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 #ifndef BASE_LOGGING_H_ 5 #ifndef BASE_LOGGING_H_
6 #define BASE_LOGGING_H_ 6 #define BASE_LOGGING_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <cassert> 10 #include <cassert>
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 LOG_TO_FILE = 1 << 0, 157 LOG_TO_FILE = 1 << 0,
158 LOG_TO_SYSTEM_DEBUG_LOG = 1 << 1, 158 LOG_TO_SYSTEM_DEBUG_LOG = 1 << 1,
159 159
160 LOG_TO_ALL = LOG_TO_FILE | LOG_TO_SYSTEM_DEBUG_LOG, 160 LOG_TO_ALL = LOG_TO_FILE | LOG_TO_SYSTEM_DEBUG_LOG,
161 161
162 // On Windows, use a file next to the exe; on POSIX platforms, where 162 // On Windows, use a file next to the exe; on POSIX platforms, where
163 // it may not even be possible to locate the executable on disk, use 163 // it may not even be possible to locate the executable on disk, use
164 // stderr. 164 // stderr.
165 #if defined(OS_WIN) 165 #if defined(OS_WIN)
166 LOG_DEFAULT = LOG_TO_FILE, 166 LOG_DEFAULT = LOG_TO_FILE,
167 #elif defined(OS_POSIX) 167 #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
168 LOG_DEFAULT = LOG_TO_SYSTEM_DEBUG_LOG, 168 LOG_DEFAULT = LOG_TO_SYSTEM_DEBUG_LOG,
169 #endif 169 #endif
170 }; 170 };
171 171
172 // Indicates that the log file should be locked when being written to. 172 // Indicates that the log file should be locked when being written to.
173 // Unless there is only one single-threaded process that is logging to 173 // Unless there is only one single-threaded process that is logging to
174 // the log file, the file should be locked during writes to make each 174 // the log file, the file should be locked during writes to make each
175 // log output atomic. Other writers will block. 175 // log output atomic. Other writers will block.
176 // 176 //
177 // All processes writing to the log file must have their locking set for it to 177 // All processes writing to the log file must have their locking set for it to
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level)) 421 LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))
422 422
423 #define VLOG_IF(verbose_level, condition) \ 423 #define VLOG_IF(verbose_level, condition) \
424 LAZY_STREAM(VLOG_STREAM(verbose_level), \ 424 LAZY_STREAM(VLOG_STREAM(verbose_level), \
425 VLOG_IS_ON(verbose_level) && (condition)) 425 VLOG_IS_ON(verbose_level) && (condition))
426 426
427 #if defined (OS_WIN) 427 #if defined (OS_WIN)
428 #define VPLOG_STREAM(verbose_level) \ 428 #define VPLOG_STREAM(verbose_level) \
429 ::logging::Win32ErrorLogMessage(__FILE__, __LINE__, -verbose_level, \ 429 ::logging::Win32ErrorLogMessage(__FILE__, __LINE__, -verbose_level, \
430 ::logging::GetLastSystemErrorCode()).stream() 430 ::logging::GetLastSystemErrorCode()).stream()
431 #elif defined(OS_POSIX) 431 #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
432 #define VPLOG_STREAM(verbose_level) \ 432 #define VPLOG_STREAM(verbose_level) \
433 ::logging::ErrnoLogMessage(__FILE__, __LINE__, -verbose_level, \ 433 ::logging::ErrnoLogMessage(__FILE__, __LINE__, -verbose_level, \
434 ::logging::GetLastSystemErrorCode()).stream() 434 ::logging::GetLastSystemErrorCode()).stream()
435 #endif 435 #endif
436 436
437 #define VPLOG(verbose_level) \ 437 #define VPLOG(verbose_level) \
438 LAZY_STREAM(VPLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level)) 438 LAZY_STREAM(VPLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))
439 439
440 #define VPLOG_IF(verbose_level, condition) \ 440 #define VPLOG_IF(verbose_level, condition) \
441 LAZY_STREAM(VPLOG_STREAM(verbose_level), \ 441 LAZY_STREAM(VPLOG_STREAM(verbose_level), \
442 VLOG_IS_ON(verbose_level) && (condition)) 442 VLOG_IS_ON(verbose_level) && (condition))
443 443
444 // TODO(akalin): Add more VLOG variants, e.g. VPLOG. 444 // TODO(akalin): Add more VLOG variants, e.g. VPLOG.
445 445
446 #define LOG_ASSERT(condition) \ 446 #define LOG_ASSERT(condition) \
447 LOG_IF(FATAL, !ANALYZER_ASSUME_TRUE(condition)) \ 447 LOG_IF(FATAL, !ANALYZER_ASSUME_TRUE(condition)) \
448 << "Assert failed: " #condition ". " 448 << "Assert failed: " #condition ". "
449 449
450 #if defined(OS_WIN) 450 #if defined(OS_WIN)
451 #define PLOG_STREAM(severity) \ 451 #define PLOG_STREAM(severity) \
452 COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \ 452 COMPACT_GOOGLE_LOG_EX_ ## severity(Win32ErrorLogMessage, \
453 ::logging::GetLastSystemErrorCode()).stream() 453 ::logging::GetLastSystemErrorCode()).stream()
454 #elif defined(OS_POSIX) 454 #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
455 #define PLOG_STREAM(severity) \ 455 #define PLOG_STREAM(severity) \
456 COMPACT_GOOGLE_LOG_EX_ ## severity(ErrnoLogMessage, \ 456 COMPACT_GOOGLE_LOG_EX_ ## severity(ErrnoLogMessage, \
457 ::logging::GetLastSystemErrorCode()).stream() 457 ::logging::GetLastSystemErrorCode()).stream()
458 #endif 458 #endif
459 459
460 #define PLOG(severity) \ 460 #define PLOG(severity) \
461 LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity)) 461 LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity))
462 462
463 #define PLOG_IF(severity, condition) \ 463 #define PLOG_IF(severity, condition) \
464 LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition)) 464 LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition))
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 class LogMessageVoidify { 907 class LogMessageVoidify {
908 public: 908 public:
909 LogMessageVoidify() { } 909 LogMessageVoidify() { }
910 // This has to be an operator with a precedence lower than << but 910 // This has to be an operator with a precedence lower than << but
911 // higher than ?: 911 // higher than ?:
912 void operator&(std::ostream&) { } 912 void operator&(std::ostream&) { }
913 }; 913 };
914 914
915 #if defined(OS_WIN) 915 #if defined(OS_WIN)
916 typedef unsigned long SystemErrorCode; 916 typedef unsigned long SystemErrorCode;
917 #elif defined(OS_POSIX) 917 #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
918 typedef int SystemErrorCode; 918 typedef int SystemErrorCode;
919 #endif 919 #endif
920 920
921 // Alias for ::GetLastError() on Windows and errno on POSIX. Avoids having to 921 // Alias for ::GetLastError() on Windows and errno on POSIX. Avoids having to
922 // pull in windows.h just for GetLastError() and DWORD. 922 // pull in windows.h just for GetLastError() and DWORD.
923 BASE_EXPORT SystemErrorCode GetLastSystemErrorCode(); 923 BASE_EXPORT SystemErrorCode GetLastSystemErrorCode();
924 BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code); 924 BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code);
925 925
926 #if defined(OS_WIN) 926 #if defined(OS_WIN)
927 // Appends a formatted system message of the GetLastError() type. 927 // Appends a formatted system message of the GetLastError() type.
928 class BASE_EXPORT Win32ErrorLogMessage { 928 class BASE_EXPORT Win32ErrorLogMessage {
929 public: 929 public:
930 Win32ErrorLogMessage(const char* file, 930 Win32ErrorLogMessage(const char* file,
931 int line, 931 int line,
932 LogSeverity severity, 932 LogSeverity severity,
933 SystemErrorCode err); 933 SystemErrorCode err);
934 934
935 // Appends the error message before destructing the encapsulated class. 935 // Appends the error message before destructing the encapsulated class.
936 ~Win32ErrorLogMessage(); 936 ~Win32ErrorLogMessage();
937 937
938 std::ostream& stream() { return log_message_.stream(); } 938 std::ostream& stream() { return log_message_.stream(); }
939 939
940 private: 940 private:
941 SystemErrorCode err_; 941 SystemErrorCode err_;
942 LogMessage log_message_; 942 LogMessage log_message_;
943 943
944 DISALLOW_COPY_AND_ASSIGN(Win32ErrorLogMessage); 944 DISALLOW_COPY_AND_ASSIGN(Win32ErrorLogMessage);
945 }; 945 };
946 #elif defined(OS_POSIX) 946 #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
947 // Appends a formatted system message of the errno type 947 // Appends a formatted system message of the errno type
948 class BASE_EXPORT ErrnoLogMessage { 948 class BASE_EXPORT ErrnoLogMessage {
949 public: 949 public:
950 ErrnoLogMessage(const char* file, 950 ErrnoLogMessage(const char* file,
951 int line, 951 int line,
952 LogSeverity severity, 952 LogSeverity severity,
953 SystemErrorCode err); 953 SystemErrorCode err);
954 954
955 // Appends the error message before destructing the encapsulated class. 955 // Appends the error message before destructing the encapsulated class.
956 ~ErrnoLogMessage(); 956 ~ErrnoLogMessage();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 #elif NOTIMPLEMENTED_POLICY == 5 1057 #elif NOTIMPLEMENTED_POLICY == 5
1058 #define NOTIMPLEMENTED() do {\ 1058 #define NOTIMPLEMENTED() do {\
1059 static bool logged_once = false;\ 1059 static bool logged_once = false;\
1060 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1060 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
1061 logged_once = true;\ 1061 logged_once = true;\
1062 } while(0);\ 1062 } while(0);\
1063 EAT_STREAM_PARAMETERS 1063 EAT_STREAM_PARAMETERS
1064 #endif 1064 #endif
1065 1065
1066 #endif // BASE_LOGGING_H_ 1066 #endif // BASE_LOGGING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698