You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2015 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "rtc_base/log_sinks.h"
  11. #include <string.h>
  12. #include <cstdio>
  13. #include <string>
  14. #include "rtc_base/checks.h"
  15. #include "rtc_base/stream.h"
  16. namespace rtc {
  17. FileRotatingLogSink::FileRotatingLogSink(const std::string& log_dir_path,
  18. const std::string& log_prefix,
  19. size_t max_log_size,
  20. size_t num_log_files)
  21. : FileRotatingLogSink(new FileRotatingStream(log_dir_path,
  22. log_prefix,
  23. max_log_size,
  24. num_log_files)) {}
  25. FileRotatingLogSink::FileRotatingLogSink(FileRotatingStream* stream)
  26. : stream_(stream) {
  27. RTC_DCHECK(stream);
  28. }
  29. FileRotatingLogSink::~FileRotatingLogSink() {}
  30. void FileRotatingLogSink::OnLogMessage(const std::string& message) {
  31. if (stream_->GetState() != SS_OPEN) {
  32. std::fprintf(stderr, "Init() must be called before adding this sink.\n");
  33. return;
  34. }
  35. stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr);
  36. }
  37. void FileRotatingLogSink::OnLogMessage(const std::string& message,
  38. LoggingSeverity sev,
  39. const char* tag) {
  40. if (stream_->GetState() != SS_OPEN) {
  41. std::fprintf(stderr, "Init() must be called before adding this sink.\n");
  42. return;
  43. }
  44. stream_->WriteAll(tag, strlen(tag), nullptr, nullptr);
  45. stream_->WriteAll(": ", 2, nullptr, nullptr);
  46. stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr);
  47. }
  48. bool FileRotatingLogSink::Init() {
  49. return stream_->Open();
  50. }
  51. bool FileRotatingLogSink::DisableBuffering() {
  52. return stream_->DisableBuffering();
  53. }
  54. CallSessionFileRotatingLogSink::CallSessionFileRotatingLogSink(
  55. const std::string& log_dir_path,
  56. size_t max_total_log_size)
  57. : FileRotatingLogSink(
  58. new CallSessionFileRotatingStream(log_dir_path, max_total_log_size)) {
  59. }
  60. CallSessionFileRotatingLogSink::~CallSessionFileRotatingLogSink() {}
  61. } // namespace rtc