OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <cstring> | 10 #include <cstring> |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 // make each log outut atomic. Other writers will block. | 158 // make each log outut atomic. Other writers will block. |
159 // | 159 // |
160 // All processes writing to the log file must have their locking set for it to | 160 // All processes writing to the log file must have their locking set for it to |
161 // work properly. Defaults to DONT_LOCK_LOG_FILE. | 161 // work properly. Defaults to DONT_LOCK_LOG_FILE. |
162 enum LogLockingState { LOCK_LOG_FILE, DONT_LOCK_LOG_FILE }; | 162 enum LogLockingState { LOCK_LOG_FILE, DONT_LOCK_LOG_FILE }; |
163 | 163 |
164 // On startup, should we delete or append to an existing log file (if any)? | 164 // On startup, should we delete or append to an existing log file (if any)? |
165 // Defaults to APPEND_TO_OLD_LOG_FILE. | 165 // Defaults to APPEND_TO_OLD_LOG_FILE. |
166 enum OldFileDeletionState { DELETE_OLD_LOG_FILE, APPEND_TO_OLD_LOG_FILE }; | 166 enum OldFileDeletionState { DELETE_OLD_LOG_FILE, APPEND_TO_OLD_LOG_FILE }; |
167 | 167 |
168 enum DcheckState { | |
169 DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS, | |
170 ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS | |
171 }; | |
172 | |
168 // TODO(avi): do we want to do a unification of character types here? | 173 // TODO(avi): do we want to do a unification of character types here? |
169 #if defined(OS_WIN) | 174 #if defined(OS_WIN) |
170 typedef wchar_t PathChar; | 175 typedef wchar_t PathChar; |
171 #else | 176 #else |
172 typedef char PathChar; | 177 typedef char PathChar; |
173 #endif | 178 #endif |
174 | 179 |
175 // Define different names for the BaseInitLoggingImpl() function depending on | 180 // Define different names for the BaseInitLoggingImpl() function depending on |
176 // whether NDEBUG is defined or not so that we'll fail to link if someone tries | 181 // whether NDEBUG is defined or not so that we'll fail to link if someone tries |
177 // to compile logging.cc with NDEBUG but includes logging.h without defining it, | 182 // to compile logging.cc with NDEBUG but includes logging.h without defining it, |
178 // or vice versa. | 183 // or vice versa. |
179 #if NDEBUG | 184 #if NDEBUG |
180 #define BaseInitLoggingImpl BaseInitLoggingImpl_built_with_NDEBUG | 185 #define BaseInitLoggingImpl BaseInitLoggingImpl_built_with_NDEBUG |
181 #else | 186 #else |
182 #define BaseInitLoggingImpl BaseInitLoggingImpl_built_without_NDEBUG | 187 #define BaseInitLoggingImpl BaseInitLoggingImpl_built_without_NDEBUG |
183 #endif | 188 #endif |
184 | 189 |
185 // Implementation of the InitLogging() method declared below. We use a | 190 // Implementation of the InitLogging() method declared below. We use a |
186 // more-specific name so we can #define it above without affecting other code | 191 // more-specific name so we can #define it above without affecting other code |
187 // that has named stuff "InitLogging". | 192 // that has named stuff "InitLogging". |
188 bool BaseInitLoggingImpl(const PathChar* log_file, | 193 bool BaseInitLoggingImpl(const PathChar* log_file, |
189 LoggingDestination logging_dest, | 194 LoggingDestination logging_dest, |
190 LogLockingState lock_log, | 195 LogLockingState lock_log, |
191 OldFileDeletionState delete_old); | 196 OldFileDeletionState delete_old, |
197 DcheckState dcheck_state); | |
192 | 198 |
193 // Sets the log file name and other global logging state. Calling this function | 199 // Sets the log file name and other global logging state. Calling this function |
194 // is recommended, and is normally done at the beginning of application init. | 200 // is recommended, and is normally done at the beginning of application init. |
195 // If you don't call it, all the flags will be initialized to their default | 201 // If you don't call it, all the flags will be initialized to their default |
196 // values, and there is a race condition that may leak a critical section | 202 // values, and there is a race condition that may leak a critical section |
197 // object if two threads try to do the first log at the same time. | 203 // object if two threads try to do the first log at the same time. |
198 // See the definition of the enums above for descriptions and default values. | 204 // See the definition of the enums above for descriptions and default values. |
199 // | 205 // |
200 // The default log file is initialized to "debug.log" in the application | 206 // The default log file is initialized to "debug.log" in the application |
201 // directory. You probably don't want this, especially since the program | 207 // directory. You probably don't want this, especially since the program |
202 // directory may not be writable on an enduser's system. | 208 // directory may not be writable on an enduser's system. |
203 inline bool InitLogging(const PathChar* log_file, | 209 inline bool InitLogging(const PathChar* log_file, |
204 LoggingDestination logging_dest, | 210 LoggingDestination logging_dest, |
205 LogLockingState lock_log, | 211 LogLockingState lock_log, |
206 OldFileDeletionState delete_old) { | 212 OldFileDeletionState delete_old, |
207 return BaseInitLoggingImpl(log_file, logging_dest, lock_log, delete_old); | 213 DcheckState dcheck_state) { |
214 return BaseInitLoggingImpl(log_file, logging_dest, lock_log, | |
215 delete_old, dcheck_state); | |
208 } | 216 } |
209 | 217 |
210 // Sets the log level. Anything at or above this level will be written to the | 218 // Sets the log level. Anything at or above this level will be written to the |
211 // log file/displayed to the user (if applicable). Anything below this level | 219 // log file/displayed to the user (if applicable). Anything below this level |
212 // will be silently ignored. The log level defaults to 0 (everything is logged | 220 // will be silently ignored. The log level defaults to 0 (everything is logged |
213 // up to level INFO) if this function is not called. | 221 // up to level INFO) if this function is not called. |
214 // Note that log messages for VLOG(x) are logged at level -x, so setting | 222 // Note that log messages for VLOG(x) are logged at level -x, so setting |
215 // the min log level to negative values enables verbose logging. | 223 // the min log level to negative values enables verbose logging. |
216 void SetMinLogLevel(int level); | 224 void SetMinLogLevel(int level); |
217 | 225 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 // Definitions for DCHECK et al. | 601 // Definitions for DCHECK et al. |
594 | 602 |
595 #if ENABLE_DCHECK | 603 #if ENABLE_DCHECK |
596 | 604 |
597 #if defined(NDEBUG) | 605 #if defined(NDEBUG) |
598 | 606 |
599 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ | 607 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ |
600 COMPACT_GOOGLE_LOG_EX_ERROR_REPORT(ClassName , ##__VA_ARGS__) | 608 COMPACT_GOOGLE_LOG_EX_ERROR_REPORT(ClassName , ##__VA_ARGS__) |
601 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_ERROR_REPORT | 609 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_ERROR_REPORT |
602 const LogSeverity LOG_DCHECK = LOG_ERROR_REPORT; | 610 const LogSeverity LOG_DCHECK = LOG_ERROR_REPORT; |
603 // This is set to true in InitLogging when we want to enable the | 611 // This is set to true in InitLogging when we want to enable the |
brettw
2011/01/03 06:53:32
Can you bring this comment up-to-date? Or maybe it
akalin
2011/01/04 19:26:45
Done.
| |
604 // DCHECKs in release. | 612 // DCHECKs in release. |
605 extern bool g_enable_dcheck; | 613 extern DcheckState g_dcheck_state; |
606 #define DCHECK_IS_ON() (::logging::g_enable_dcheck && LOG_IS_ON(DCHECK)) | 614 #define DCHECK_IS_ON() \ |
615 ((::logging::g_dcheck_state == \ | |
616 ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS) && \ | |
617 LOG_IS_ON(DCHECK)) | |
607 | 618 |
608 #else // defined(NDEBUG) | 619 #else // defined(NDEBUG) |
609 | 620 |
610 // On a regular debug build, we want to have DCHECKs enabled. | 621 // On a regular debug build, we want to have DCHECKs enabled. |
611 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ | 622 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ |
612 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__) | 623 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__) |
613 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL | 624 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL |
614 const LogSeverity LOG_DCHECK = LOG_FATAL; | 625 const LogSeverity LOG_DCHECK = LOG_FATAL; |
615 #define DCHECK_IS_ON() true | 626 #define DCHECK_IS_ON() true |
616 | 627 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
904 #elif NOTIMPLEMENTED_POLICY == 4 | 915 #elif NOTIMPLEMENTED_POLICY == 4 |
905 #define NOTIMPLEMENTED() LOG(ERROR) << NOTIMPLEMENTED_MSG | 916 #define NOTIMPLEMENTED() LOG(ERROR) << NOTIMPLEMENTED_MSG |
906 #elif NOTIMPLEMENTED_POLICY == 5 | 917 #elif NOTIMPLEMENTED_POLICY == 5 |
907 #define NOTIMPLEMENTED() do {\ | 918 #define NOTIMPLEMENTED() do {\ |
908 static int count = 0;\ | 919 static int count = 0;\ |
909 LOG_IF(ERROR, 0 == count++) << NOTIMPLEMENTED_MSG;\ | 920 LOG_IF(ERROR, 0 == count++) << NOTIMPLEMENTED_MSG;\ |
910 } while(0) | 921 } while(0) |
911 #endif | 922 #endif |
912 | 923 |
913 #endif // BASE_LOGGING_H_ | 924 #endif // BASE_LOGGING_H_ |
OLD | NEW |