15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_COMMON_LOGGING_CHROME_H__
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_COMMON_LOGGING_CHROME_H__
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base {
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class CommandLine;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FilePath;
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace logging {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Call to initialize logging for Chrome. This sets up the chrome-specific
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// logfile naming scheme and might do other things like log modules and
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// setting levels in the future.
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The main process might want to delete any old log files on startup by
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// setting delete_old_log_file, but the renderer processes should not, or
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// they will delete each others' logs.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// XXX
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Setting suppress_error_dialogs to true disables any dialogs that would
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// normally appear for assertions and crashes, and makes any catchable
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// errors (namely assertions) available via GetSilencedErrorCount()
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and GetSilencedError().
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void InitChromeLogging(const base::CommandLine& command_line,
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       OldFileDeletionState delete_old_log_file);
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_CHROMEOS)
385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Get the log file directory path.
395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)base::FilePath GetSessionLogDir(const base::CommandLine& command_line);
405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get the log file location.
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)base::FilePath GetSessionLogFile(const base::CommandLine& command_line);
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Redirects chrome logging to the appropriate session log dir.
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RedirectChromeLogging(const base::CommandLine& command_line);
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Call when done using logging for Chrome.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CleanupChromeLogging();
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the fully-qualified name of the log file.
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)base::FilePath GetLogFileName();
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns true when error/assertion dialogs are to be shown,
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// false otherwise.
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool DialogsAreSuppressed();
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef std::vector<std::wstring> AssertionList;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Gets the list of fatal assertions in the current log file, and
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// returns the number of fatal assertions.  (If you don't care
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// about the actual list of assertions, you can pass in NULL.)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: Since this reads the log file to determine the assertions,
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this operation is O(n) over the length of the log.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: This can fail if the file is locked for writing.  However,
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this is unlikely as this function is most useful after
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the program writing the log has terminated.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)size_t GetFatalAssertions(AssertionList* assertions);
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Inserts timestamp before file extension in the format
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// "_yymmdd-hhmmss".
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)base::FilePath GenerateTimestampedName(const base::FilePath& base_path,
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                       base::Time timestamp);
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace logging
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_COMMON_LOGGING_CHROME_H_
77