webrtc/rtc_base/log_sinks.cc
Philipp Hancke b2ea936d33 Modernize deprecated headers in api/, pc/ and rtc_base/
Done using
  tools/clang/scripts/build_clang_tools_extra.py \
    --fetch out/Default clang-tidy clang-apply-replacements
  ninja -C out/Default
  gn gen out/Default --export-compile-commands
  cd out/Default
  tools/clang/third_party/llvm/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py -p . \
    -clang-tidy-binary out/Default/tools/clang/third_party/llvm/build/bin/clang-tidy \
    -clang-apply-replacements-binary \
        out/Default/tools/clang/third_party/llvm/build/bin/clang-apply-replacements \
    -checks='-*,modernize-deprecated-headers' \
    -fix api/ pc/ rtc_base/
followed by
  git cl format
and a round of IWYU followed by more git cl format

Bug: webrtc:424706384
Change-Id: I8add6fe713fba9d6ef4cc3783bdb7e7f975aaa0a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/400921
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Philipp Hancke <phancke@meta.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45182}
2025-07-21 00:02:35 -07:00

88 lines
2.8 KiB
C++

/*
* 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.
*/
#include "rtc_base/log_sinks.h"
#include <cstdio>
#include <cstring>
#include <string>
#include "absl/strings/string_view.h"
#include "rtc_base/checks.h"
#include "rtc_base/file_rotating_stream.h"
#include "rtc_base/logging.h"
namespace webrtc {
FileRotatingLogSink::FileRotatingLogSink(absl::string_view log_dir_path,
absl::string_view log_prefix,
size_t max_log_size,
size_t num_log_files)
: FileRotatingLogSink(new FileRotatingStream(log_dir_path,
log_prefix,
max_log_size,
num_log_files)) {}
FileRotatingLogSink::FileRotatingLogSink(FileRotatingStream* stream)
: stream_(stream) {
RTC_DCHECK(stream);
}
FileRotatingLogSink::~FileRotatingLogSink() {}
void FileRotatingLogSink::OnLogMessage(const std::string& message) {
OnLogMessage(absl::string_view(message));
}
void FileRotatingLogSink::OnLogMessage(absl::string_view message) {
if (!stream_->IsOpen()) {
std::fprintf(stderr, "Init() must be called before adding this sink.\n");
return;
}
stream_->Write(message.data(), message.size());
}
void FileRotatingLogSink::OnLogMessage(const std::string& message,
LoggingSeverity sev,
const char* tag) {
OnLogMessage(absl::string_view(message), sev, tag);
}
void FileRotatingLogSink::OnLogMessage(absl::string_view message,
LoggingSeverity sev,
const char* tag) {
if (!stream_->IsOpen()) {
std::fprintf(stderr, "Init() must be called before adding this sink.\n");
return;
}
stream_->Write(tag, strlen(tag));
stream_->Write(": ", 2);
stream_->Write(message.data(), message.size());
}
bool FileRotatingLogSink::Init() {
return stream_->Open();
}
bool FileRotatingLogSink::DisableBuffering() {
return stream_->DisableBuffering();
}
CallSessionFileRotatingLogSink::CallSessionFileRotatingLogSink(
absl::string_view log_dir_path,
size_t max_total_log_size)
: FileRotatingLogSink(
new CallSessionFileRotatingStream(log_dir_path, max_total_log_size)) {
}
CallSessionFileRotatingLogSink::~CallSessionFileRotatingLogSink() {}
} // namespace webrtc