blob: 4340566a800cc3ca0121d3a1d23a776e9f2014f3 [file] [log] [blame]
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/singleton.h"
namespace base {
class FilePath;
// This class manages redirecting stderr output to a file. Redirection can be
// started and stopped multiple times, but there must be a call to
// StopRedirectingToFile() between any two calls to StartRedirectingToFile().
class CWTStderrLogger {
// Returns the singleton instance of this class.
static CWTStderrLogger* GetInstance();
CWTStderrLogger(const CWTStderrLogger&) = delete;
CWTStderrLogger& operator=(const CWTStderrLogger&) = delete;
// Starts redirecting stderr output to the file with the given path. This
// file must already exist. Any existing content will not be overwritten;
// instead, new content is appended to the file..
void StartRedirectingToFile(const base::FilePath& file_path);
// Stops redirecting stderr output to a file.
void StopRedirectingToFile();
friend struct base::DefaultSingletonTraits<CWTStderrLogger>;
CWTStderrLogger() = default;
// When redirection is active, this saves a copy of the old stderr file
// descriptor, which is restored as the destination of stderr after
// redirection is stopped.
int saved_stderr_file_descriptor_ = -1;
// While redirection is active, this stores the file descriptor for the
// destination file.
int redirection_destination_file_descriptor_ = -1;