blob: af43f8ad27160a36270ba194dde972006db5eaeb [file] [log] [blame]
Zeke Chin2d3b7e22015-07-14 12:55:44 -07001/*
2 * libjingle
3 * Copyright 2015 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#import <Foundation/Foundation.h>
29
30// TODO(tkchin): Move this to a common location.
31#ifndef NS_DESIGNATED_INITIALIZER
32#define NS_DESIGNATED_INITIALIZER
33#endif
34
35typedef NS_ENUM(NSUInteger, RTCFileLoggerSeverity) {
36 kRTCFileLoggerSeverityVerbose,
37 kRTCFileLoggerSeverityInfo,
38 kRTCFileLoggerSeverityWarning,
39 kRTCFileLoggerSeverityError
40};
41
hayscd02b0fa2015-12-08 13:59:05 -080042typedef NS_ENUM(NSUInteger, RTCFileLoggerRotationType) {
43 kRTCFileLoggerTypeCall,
44 kRTCFileLoggerTypeApp,
45};
46
Zeke Chin2d3b7e22015-07-14 12:55:44 -070047// This class intercepts WebRTC logs and saves them to a file. The file size
48// will not exceed the given maximum bytesize. When the maximum bytesize is
hayscd02b0fa2015-12-08 13:59:05 -080049// reached, logs are rotated according to the rotationType specified.
50// For kRTCFileLoggerTypeCall, logs from the beginning and the end
51// are preserved while the middle section is overwritten instead.
52// For kRTCFileLoggerTypeApp, the oldest log is overwritten.
Zeke Chin2d3b7e22015-07-14 12:55:44 -070053// This class is not threadsafe.
54@interface RTCFileLogger : NSObject
55
56// The severity level to capture. The default is kRTCFileLoggerSeverityInfo.
57@property(nonatomic, assign) RTCFileLoggerSeverity severity;
58
hayscd02b0fa2015-12-08 13:59:05 -080059// The rotation type for this file logger. The default is
60// kRTCFileLoggerTypeCall.
61@property(nonatomic, readonly) RTCFileLoggerRotationType rotationType;
62
tkchind162a5e2016-01-27 15:11:47 -080063// Disables buffering disk writes. Should be set before |start|. Buffering
64// is enabled by default for performance.
65@property(nonatomic, assign) BOOL shouldDisableBuffering;
66
hayscd02b0fa2015-12-08 13:59:05 -080067// Default constructor provides default settings for dir path, file size and
68// rotation type.
Zeke Chin2d3b7e22015-07-14 12:55:44 -070069- (instancetype)init;
70
hayscd02b0fa2015-12-08 13:59:05 -080071// Create file logger with default rotation type.
72- (instancetype)initWithDirPath:(NSString *)dirPath
73 maxFileSize:(NSUInteger)maxFileSize;
74
tkchin28bae022015-07-23 12:27:02 -070075- (instancetype)initWithDirPath:(NSString *)dirPath
76 maxFileSize:(NSUInteger)maxFileSize
hayscd02b0fa2015-12-08 13:59:05 -080077 rotationType:(RTCFileLoggerRotationType)rotationType
Zeke Chin2d3b7e22015-07-14 12:55:44 -070078 NS_DESIGNATED_INITIALIZER;
79
tkchin28bae022015-07-23 12:27:02 -070080// Starts writing WebRTC logs to disk if not already started. Overwrites any
81// existing file(s).
Zeke Chin2d3b7e22015-07-14 12:55:44 -070082- (void)start;
83
tkchin28bae022015-07-23 12:27:02 -070084// Stops writing WebRTC logs to disk. This method is also called on dealloc.
Zeke Chin2d3b7e22015-07-14 12:55:44 -070085- (void)stop;
86
tkchin28bae022015-07-23 12:27:02 -070087// Returns the current contents of the logs, or nil if start has been called
88// without a stop.
Zeke Chin2d3b7e22015-07-14 12:55:44 -070089- (NSData *)logData;
90
91@end