blob: ac8a9104c153e2d3d89def0845a835c42878b5af [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
tkchin9eeb6242016-04-27 01:54:20 -070013#import <WebRTC/RTCMacros.h>
tkchin8b577ed2016-04-19 10:04:41 -070014
Jon Hjelle6140fcc2016-02-24 16:33:12 -080015typedef NS_ENUM(NSUInteger, RTCFileLoggerSeverity) {
tkchin8b9ca952016-03-31 12:08:03 -070016 RTCFileLoggerSeverityVerbose,
17 RTCFileLoggerSeverityInfo,
18 RTCFileLoggerSeverityWarning,
19 RTCFileLoggerSeverityError
Jon Hjelle6140fcc2016-02-24 16:33:12 -080020};
21
22typedef NS_ENUM(NSUInteger, RTCFileLoggerRotationType) {
tkchin8b9ca952016-03-31 12:08:03 -070023 RTCFileLoggerTypeCall,
24 RTCFileLoggerTypeApp,
Jon Hjelle6140fcc2016-02-24 16:33:12 -080025};
26
tkchin8b9ca952016-03-31 12:08:03 -070027NS_ASSUME_NONNULL_BEGIN
28
Jon Hjelle6140fcc2016-02-24 16:33:12 -080029// 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.
tkchin8b577ed2016-04-19 10:04:41 -070036RTC_EXPORT
Jon Hjelle6140fcc2016-02-24 16:33:12 -080037@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 Gerey665174f2018-06-19 15:03:05 +020055- (instancetype)initWithDirPath:(NSString *)dirPath maxFileSize:(NSUInteger)maxFileSize;
Jon Hjelle6140fcc2016-02-24 16:33:12 -080056
57- (instancetype)initWithDirPath:(NSString *)dirPath
58 maxFileSize:(NSUInteger)maxFileSize
Yves Gerey665174f2018-06-19 15:03:05 +020059 rotationType:(RTCFileLoggerRotationType)rotationType NS_DESIGNATED_INITIALIZER;
Jon Hjelle6140fcc2016-02-24 16:33:12 -080060
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 Hanspersd9b64cd2018-01-12 16:16:18 +010070- (nullable NSData *)logData;
Jon Hjelle6140fcc2016-02-24 16:33:12 -080071
72@end
tkchin8b9ca952016-03-31 12:08:03 -070073
74NS_ASSUME_NONNULL_END