Jon Hjelle | 6140fcc | 2016-02-24 16:33:12 -0800 | [diff] [blame] | 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 | |
| 11 | #import <Foundation/Foundation.h> |
| 12 | |
tkchin | 9eeb624 | 2016-04-27 01:54:20 -0700 | [diff] [blame] | 13 | #import <WebRTC/RTCMacros.h> |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame] | 14 | |
Jon Hjelle | 6140fcc | 2016-02-24 16:33:12 -0800 | [diff] [blame] | 15 | typedef NS_ENUM(NSUInteger, RTCFileLoggerSeverity) { |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 16 | RTCFileLoggerSeverityVerbose, |
| 17 | RTCFileLoggerSeverityInfo, |
| 18 | RTCFileLoggerSeverityWarning, |
| 19 | RTCFileLoggerSeverityError |
Jon Hjelle | 6140fcc | 2016-02-24 16:33:12 -0800 | [diff] [blame] | 20 | }; |
| 21 | |
| 22 | typedef NS_ENUM(NSUInteger, RTCFileLoggerRotationType) { |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 23 | RTCFileLoggerTypeCall, |
| 24 | RTCFileLoggerTypeApp, |
Jon Hjelle | 6140fcc | 2016-02-24 16:33:12 -0800 | [diff] [blame] | 25 | }; |
| 26 | |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 27 | NS_ASSUME_NONNULL_BEGIN |
| 28 | |
Jon Hjelle | 6140fcc | 2016-02-24 16:33:12 -0800 | [diff] [blame] | 29 | // This class intercepts WebRTC logs and saves them to a file. The file size |
| 30 | // will not exceed the given maximum bytesize. When the maximum bytesize is |
| 31 | // reached, logs are rotated according to the rotationType specified. |
| 32 | // For kRTCFileLoggerTypeCall, logs from the beginning and the end |
| 33 | // are preserved while the middle section is overwritten instead. |
| 34 | // For kRTCFileLoggerTypeApp, the oldest log is overwritten. |
| 35 | // This class is not threadsafe. |
tkchin | 8b577ed | 2016-04-19 10:04:41 -0700 | [diff] [blame] | 36 | RTC_EXPORT |
Jon Hjelle | 6140fcc | 2016-02-24 16:33:12 -0800 | [diff] [blame] | 37 | @interface RTCFileLogger : NSObject |
| 38 | |
| 39 | // The severity level to capture. The default is kRTCFileLoggerSeverityInfo. |
| 40 | @property(nonatomic, assign) RTCFileLoggerSeverity severity; |
| 41 | |
| 42 | // The rotation type for this file logger. The default is |
| 43 | // kRTCFileLoggerTypeCall. |
| 44 | @property(nonatomic, readonly) RTCFileLoggerRotationType rotationType; |
| 45 | |
| 46 | // Disables buffering disk writes. Should be set before |start|. Buffering |
| 47 | // is enabled by default for performance. |
| 48 | @property(nonatomic, assign) BOOL shouldDisableBuffering; |
| 49 | |
| 50 | // Default constructor provides default settings for dir path, file size and |
| 51 | // rotation type. |
| 52 | - (instancetype)init; |
| 53 | |
| 54 | // Create file logger with default rotation type. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 55 | - (instancetype)initWithDirPath:(NSString *)dirPath maxFileSize:(NSUInteger)maxFileSize; |
Jon Hjelle | 6140fcc | 2016-02-24 16:33:12 -0800 | [diff] [blame] | 56 | |
| 57 | - (instancetype)initWithDirPath:(NSString *)dirPath |
| 58 | maxFileSize:(NSUInteger)maxFileSize |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 59 | rotationType:(RTCFileLoggerRotationType)rotationType NS_DESIGNATED_INITIALIZER; |
Jon Hjelle | 6140fcc | 2016-02-24 16:33:12 -0800 | [diff] [blame] | 60 | |
| 61 | // Starts writing WebRTC logs to disk if not already started. Overwrites any |
| 62 | // existing file(s). |
| 63 | - (void)start; |
| 64 | |
| 65 | // Stops writing WebRTC logs to disk. This method is also called on dealloc. |
| 66 | - (void)stop; |
| 67 | |
| 68 | // Returns the current contents of the logs, or nil if start has been called |
| 69 | // without a stop. |
Peter Hanspers | d9b64cd | 2018-01-12 16:16:18 +0100 | [diff] [blame] | 70 | - (nullable NSData *)logData; |
Jon Hjelle | 6140fcc | 2016-02-24 16:33:12 -0800 | [diff] [blame] | 71 | |
| 72 | @end |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 73 | |
| 74 | NS_ASSUME_NONNULL_END |