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