/* * Copyright 2015 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #ifndef RTC_BASE_FILE_ROTATING_STREAM_H_ #define RTC_BASE_FILE_ROTATING_STREAM_H_ #include <stddef.h> #include <memory> #include <string> #include <vector> #include "absl/strings/string_view.h" #include "rtc_base/system/file_wrapper.h" namespace rtc { // FileRotatingStream writes to a file in the directory specified in the // constructor. It rotates the files once the current file is full. The // individual file size and the number of files used is configurable in the // constructor. Open() must be called before using this stream. class FileRotatingStream { … }; // CallSessionFileRotatingStream is meant to be used in situations where we will // have limited disk space. Its purpose is to write logs up to a // maximum size. Once the maximum size is exceeded, logs from the middle are // deleted whereas logs from the beginning and end are preserved. The reason for // this is because we anticipate that in WebRTC the beginning and end of the // logs are most useful for call diagnostics. // // This implementation simply writes to a single file until // `max_total_log_size` / 2 bytes are written to it, and subsequently writes to // a set of rotating files. We do this by inheriting FileRotatingStream and // setting the appropriate internal variables so that we don't delete the last // (earliest) file on rotate, and that that file's size is bigger. // // Open() must be called before using this stream. // To read the logs produced by this class, one can use the companion class // CallSessionFileRotatingStreamReader. class CallSessionFileRotatingStream : public FileRotatingStream { … }; // This is a convenience class, to read all files produced by a // FileRotatingStream, all in one go. Typical use calls GetSize and ReadData // only once. The list of file names to read is based on the contents of the log // directory at construction time. class FileRotatingStreamReader { … }; class CallSessionFileRotatingStreamReader : public FileRotatingStreamReader { … }; } // namespace rtc #endif // RTC_BASE_FILE_ROTATING_STREAM_H_