• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
35 typedef NS_ENUM(NSUInteger, RTCFileLoggerSeverity) {
36   kRTCFileLoggerSeverityVerbose,
37   kRTCFileLoggerSeverityInfo,
38   kRTCFileLoggerSeverityWarning,
39   kRTCFileLoggerSeverityError
40 };
41 
42 typedef NS_ENUM(NSUInteger, RTCFileLoggerRotationType) {
43   kRTCFileLoggerTypeCall,
44   kRTCFileLoggerTypeApp,
45 };
46 
47 // 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
49 // 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.
53 // 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 
59 // The rotation type for this file logger. The default is
60 // kRTCFileLoggerTypeCall.
61 @property(nonatomic, readonly) RTCFileLoggerRotationType rotationType;
62 
63 // Default constructor provides default settings for dir path, file size and
64 // rotation type.
65 - (instancetype)init;
66 
67 // Create file logger with default rotation type.
68 - (instancetype)initWithDirPath:(NSString *)dirPath
69                     maxFileSize:(NSUInteger)maxFileSize;
70 
71 - (instancetype)initWithDirPath:(NSString *)dirPath
72                     maxFileSize:(NSUInteger)maxFileSize
73                    rotationType:(RTCFileLoggerRotationType)rotationType
74     NS_DESIGNATED_INITIALIZER;
75 
76 // Starts writing WebRTC logs to disk if not already started. Overwrites any
77 // existing file(s).
78 - (void)start;
79 
80 // Stops writing WebRTC logs to disk. This method is also called on dealloc.
81 - (void)stop;
82 
83 // Returns the current contents of the logs, or nil if start has been called
84 // without a stop.
85 - (NSData *)logData;
86 
87 @end
88