blob: 3900cb6fbeb5199913be877f246b3677ba1c6aae [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
42// This class intercepts WebRTC logs and saves them to a file. The file size
43// will not exceed the given maximum bytesize. When the maximum bytesize is
44// reached logs from the beginning and the end are preserved while the middle
45// section is overwritten instead.
46// This class is not threadsafe.
47@interface RTCFileLogger : NSObject
48
49// The severity level to capture. The default is kRTCFileLoggerSeverityInfo.
50@property(nonatomic, assign) RTCFileLoggerSeverity severity;
51
tkchin28bae022015-07-23 12:27:02 -070052// Default constructor provides default settings for dir path and file size.
Zeke Chin2d3b7e22015-07-14 12:55:44 -070053- (instancetype)init;
54
tkchin28bae022015-07-23 12:27:02 -070055- (instancetype)initWithDirPath:(NSString *)dirPath
56 maxFileSize:(NSUInteger)maxFileSize
Zeke Chin2d3b7e22015-07-14 12:55:44 -070057 NS_DESIGNATED_INITIALIZER;
58
tkchin28bae022015-07-23 12:27:02 -070059// Starts writing WebRTC logs to disk if not already started. Overwrites any
60// existing file(s).
Zeke Chin2d3b7e22015-07-14 12:55:44 -070061- (void)start;
62
tkchin28bae022015-07-23 12:27:02 -070063// Stops writing WebRTC logs to disk. This method is also called on dealloc.
Zeke Chin2d3b7e22015-07-14 12:55:44 -070064- (void)stop;
65
tkchin28bae022015-07-23 12:27:02 -070066// Returns the current contents of the logs, or nil if start has been called
67// without a stop.
Zeke Chin2d3b7e22015-07-14 12:55:44 -070068- (NSData *)logData;
69
70@end