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