-
Notifications
You must be signed in to change notification settings - Fork 127
/
MFLogReader.m
97 lines (76 loc) · 2.3 KB
/
MFLogReader.m
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// MFLogReader.m
// MacFusion2
//
// Created by Michael Gorbach on 3/24/08.
// Copyright 2008 Michael Gorbach. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "MFLogReader.h"
#import <asl.h>
#import "MFLogging.h"
@interface MFLogReader(PrivatAPI)
@property(readwrite, retain) NSMutableArray *logMessages;
@end
@implementation MFLogReader
static MFLogReader *sharedReader;
+ (MFLogReader *)sharedReader {
if (sharedReader == nil) {
[[self alloc] init];
}
return sharedReader;
}
+ (id)allocWithZone:(NSZone *)zone {
if (sharedReader == nil) {
sharedReader = [super allocWithZone: zone];
return sharedReader;
}
return nil;
}
- (void)addASLEntries:(NSArray*)array {
[self willChangeValueForKey:@"logMessages"];
[logMessages addObjectsFromArray: array];
[self didChangeValueForKey:@"logMessages"];
}
- (void)readEntriesFromASL {
aslmsg q = asl_new(ASL_TYPE_QUERY);
aslmsg m;
asl_set_query(q, ASL_KEY_FACILITY, MF_ASL_SERVICE_NAME, ASL_QUERY_OP_EQUAL);
aslresponse r = asl_search(NULL, q);
NSMutableArray *logMessagesToAdd = [NSMutableArray array];
while (NULL != (m = aslresponse_next(r))) {
NSDictionary *dict = dictFromASLMessage(m);
[logMessagesToAdd addObject:dict];
}
aslresponse_free(r);
[self performSelectorOnMainThread:@selector(addASLEntries:) withObject:logMessagesToAdd waitUntilDone:NO];
}
- (void)recordASLMessageDict:(NSDictionary*)messageDict {
[[self mutableArrayValueForKey: @"logMessages"] addObject:messageDict];
}
- (id)init {
if (self = [super init]) {
logMessages = [NSMutableArray array];
[NSThread detachNewThreadSelector:@selector(readEntriesFromASL) toTarget:self withObject:nil];
isRunning = NO;
}
return self;
}
- (BOOL)isRunning {
return isRunning;
}
- (void)start {
isRunning = YES;
}
@synthesize logMessages;
@end