RTCFileLogger.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #import <Foundation/Foundation.h>
  11. #import "RTCMacros.h"
  12. typedef NS_ENUM(NSUInteger, RTCFileLoggerSeverity) {
  13. RTCFileLoggerSeverityVerbose,
  14. RTCFileLoggerSeverityInfo,
  15. RTCFileLoggerSeverityWarning,
  16. RTCFileLoggerSeverityError
  17. };
  18. typedef NS_ENUM(NSUInteger, RTCFileLoggerRotationType) {
  19. RTCFileLoggerTypeCall,
  20. RTCFileLoggerTypeApp,
  21. };
  22. NS_ASSUME_NONNULL_BEGIN
  23. // This class intercepts WebRTC logs and saves them to a file. The file size
  24. // will not exceed the given maximum bytesize. When the maximum bytesize is
  25. // reached, logs are rotated according to the rotationType specified.
  26. // For kRTCFileLoggerTypeCall, logs from the beginning and the end
  27. // are preserved while the middle section is overwritten instead.
  28. // For kRTCFileLoggerTypeApp, the oldest log is overwritten.
  29. // This class is not threadsafe.
  30. RTC_OBJC_EXPORT
  31. @interface RTC_OBJC_TYPE (RTCFileLogger) : NSObject
  32. // The severity level to capture. The default is kRTCFileLoggerSeverityInfo.
  33. @property(nonatomic, assign) RTCFileLoggerSeverity severity;
  34. // The rotation type for this file logger. The default is
  35. // kRTCFileLoggerTypeCall.
  36. @property(nonatomic, readonly) RTCFileLoggerRotationType rotationType;
  37. // Disables buffering disk writes. Should be set before |start|. Buffering
  38. // is enabled by default for performance.
  39. @property(nonatomic, assign) BOOL shouldDisableBuffering;
  40. // Default constructor provides default settings for dir path, file size and
  41. // rotation type.
  42. - (instancetype)init;
  43. // Create file logger with default rotation type.
  44. - (instancetype)initWithDirPath:(NSString *)dirPath maxFileSize:(NSUInteger)maxFileSize;
  45. - (instancetype)initWithDirPath:(NSString *)dirPath
  46. maxFileSize:(NSUInteger)maxFileSize
  47. rotationType:(RTCFileLoggerRotationType)rotationType NS_DESIGNATED_INITIALIZER;
  48. // Starts writing WebRTC logs to disk if not already started. Overwrites any
  49. // existing file(s).
  50. - (void)start;
  51. // Stops writing WebRTC logs to disk. This method is also called on dealloc.
  52. - (void)stop;
  53. // Returns the current contents of the logs, or nil if start has been called
  54. // without a stop.
  55. - (nullable NSData *)logData;
  56. @end
  57. NS_ASSUME_NONNULL_END