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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_COMMON_LOGGING_CHROME_H__ 6 #define CHROME_COMMON_LOGGING_CHROME_H__ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/logging.h" 12 #include "base/time/time.h" 13 14 namespace base { 15 class CommandLine; 16 class FilePath; 17 } 18 19 namespace logging { 20 21 // Call to initialize logging for Chrome. This sets up the chrome-specific 22 // logfile naming scheme and might do other things like log modules and 23 // setting levels in the future. 24 // 25 // The main process might want to delete any old log files on startup by 26 // setting delete_old_log_file, but the renderer processes should not, or 27 // they will delete each others' logs. 28 // 29 // XXX 30 // Setting suppress_error_dialogs to true disables any dialogs that would 31 // normally appear for assertions and crashes, and makes any catchable 32 // errors (namely assertions) available via GetSilencedErrorCount() 33 // and GetSilencedError(). 34 void InitChromeLogging(const base::CommandLine& command_line, 35 OldFileDeletionState delete_old_log_file); 36 37 #if defined(OS_CHROMEOS) 38 // Get the log file directory path. 39 base::FilePath GetSessionLogDir(const base::CommandLine& command_line); 40 41 // Get the log file location. 42 base::FilePath GetSessionLogFile(const base::CommandLine& command_line); 43 44 // Redirects chrome logging to the appropriate session log dir. 45 void RedirectChromeLogging(const base::CommandLine& command_line); 46 #endif 47 48 // Call when done using logging for Chrome. 49 void CleanupChromeLogging(); 50 51 // Returns the fully-qualified name of the log file. 52 base::FilePath GetLogFileName(); 53 54 // Returns true when error/assertion dialogs are to be shown, 55 // false otherwise. 56 bool DialogsAreSuppressed(); 57 58 typedef std::vector<std::wstring> AssertionList; 59 60 // Gets the list of fatal assertions in the current log file, and 61 // returns the number of fatal assertions. (If you don't care 62 // about the actual list of assertions, you can pass in NULL.) 63 // NOTE: Since this reads the log file to determine the assertions, 64 // this operation is O(n) over the length of the log. 65 // NOTE: This can fail if the file is locked for writing. However, 66 // this is unlikely as this function is most useful after 67 // the program writing the log has terminated. 68 size_t GetFatalAssertions(AssertionList* assertions); 69 70 // Inserts timestamp before file extension in the format 71 // "_yymmdd-hhmmss". 72 base::FilePath GenerateTimestampedName(const base::FilePath& base_path, 73 base::Time timestamp); 74 } // namespace logging 75 76 #endif // CHROME_COMMON_LOGGING_CHROME_H_ 77