-
Notifications
You must be signed in to change notification settings - Fork 0
/
GDASLLog.m
104 lines (89 loc) · 2.73 KB
/
GDASLLog.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
98
99
100
101
102
103
104
//copyright 2009 aaronsmith
#import "GDASLLog.h"
#import "GDASLLogManager.h"
@implementation GDASLLog
@synthesize logToStdOut;
- (id) initWithSender:(NSString *) sender facility:(NSString *) facility connectImmediately:(Boolean) connectImmediately {
if(self = [self init]) {
manager = [GDASLLogManager sharedInstance];
uint32_t ops = 0;
if(connectImmediately) ops |= ASL_OPT_NO_DELAY;
client = asl_open([sender UTF8String],[facility UTF8String],ops);
}
return self;
}
- (int) setLogFile:(NSString *) logFile {
if(fd > -1) {
asl_remove_log_file(client,fd);
close(fd);
}
fd = open([logFile UTF8String], O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|S_IWOTH);
if(fd < 0) return fd;
asl_add_log_file(client,fd);
return 0;
}
- (void) alert:(NSString *) message {
if(![manager enabled]) return;
if(logToStdOut) printf("%s",[message UTF8String]);
aslmsg m = asl_new(ASL_TYPE_MSG);
asl_log(client,m,ASL_LEVEL_ALERT,[message UTF8String],NULL);
asl_free(m);
}
- (void) critical:(NSString *) message {
if(![manager enabled]) return;
if(logToStdOut) printf("%s",[message UTF8String]);
aslmsg m = asl_new(ASL_TYPE_MSG);
asl_log(client,m,ASL_LEVEL_CRIT,[message UTF8String],NULL);
asl_free(m);
}
- (void) debug:(NSString *) message {
if(![manager enabled]) return;
if(logToStdOut) printf("%s",[message UTF8String]);
aslmsg m = asl_new(ASL_TYPE_MSG);
asl_log(client,m,ASL_LEVEL_DEBUG,[message UTF8String],NULL);
asl_free(m);
}
- (void) emergency:(NSString *) message {
if(![manager enabled]) return;
if(logToStdOut) printf("%s",[message UTF8String]);
aslmsg m = asl_new(ASL_TYPE_MSG);
asl_log(client,m,ASL_LEVEL_EMERG,[message UTF8String],NULL);
asl_free(m);
}
- (void) error:(NSString *) message {
if(![manager enabled]) return;
if(logToStdOut) printf("%s",[message UTF8String]);
aslmsg m = asl_new(ASL_TYPE_MSG);
asl_log(client,m,ASL_LEVEL_ERR,[message UTF8String],NULL);
asl_free(m);
}
- (void) info:(NSString *) message {
if(![manager enabled]) return;
if(logToStdOut) printf("%s",[message UTF8String]);
aslmsg m = asl_new(ASL_TYPE_MSG);
asl_log(client,m,ASL_LEVEL_INFO,[message UTF8String],NULL);
asl_free(m);
}
- (void) notice:(NSString *) message {
if(![manager enabled]) return;
if(logToStdOut) printf("%s",[message UTF8String]);
aslmsg m = asl_new(ASL_TYPE_MSG);
asl_log(client,m,ASL_LEVEL_NOTICE,[message UTF8String],NULL);
asl_free(m);
}
- (void) warning:(NSString *) message {
if(![manager enabled]) return;
if(logToStdOut) printf("%s",[message UTF8String]);
aslmsg m = asl_new(ASL_TYPE_MSG);
asl_log(client,m,ASL_LEVEL_WARNING,[message UTF8String],NULL);
asl_free(m);
}
- (void) close {
if(fd>0)asl_remove_log_file(client,fd);
asl_close(client);
}
- (void) dealloc {
[self close];
[super dealloc];
}
@end