-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathFFTAbstractLogger.m
More file actions
61 lines (48 loc) · 1.33 KB
/
FFTAbstractLogger.m
File metadata and controls
61 lines (48 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// FFTAbstractLogger.m
// FFmpegTutorial
//
// Created by Matt Reach on 2021/7/5.
//
#import "FFTAbstractLogger.h"
@interface FFTAbstractLogger ()
@property (nonatomic, copy) void (^logRecipient)(MRALLevel, NSString * _Nonnull);
@property (nonatomic, strong) NSDateFormatter *formatter;
@end
@implementation FFTAbstractLogger
+ (instancetype)sharedLogger
{
static id instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc] init];
});
return nil;
}
- (instancetype)init
{
self = [super init];
if (self) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM-dd HH:mm:ss"];
self.formatter = formatter;
}
return self;
}
- (void)registerLogRecipient:(void (^)(MRALLevel, NSString * _Nonnull))block
{
self.logRecipient = block;
}
- (void)write:(MRALLevel)level fmt:(NSString *)fmt,...
{
if (self.logRecipient) {
va_list ap;
va_start(ap, fmt);
NSString *log = [[NSString alloc] initWithFormat:fmt arguments:ap];
va_end(ap);
NSDate *date = [NSDate date];
NSString *dateString = [self.formatter stringFromDate:date];
self.logRecipient(level, [NSString stringWithFormat:@"[%@] %@",dateString,log]);
}
}
@end