-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMLog.m
44 lines (38 loc) · 916 Bytes
/
MLog.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
#import "MLog.h"
//MLog.m
static BOOL __MLogOn=NO;
@implementation MStringLog
+(void)initialize
{
#if defined (MLOGTRACE)
char * env=getenv("MLogOn");
if(strcmp(env==NULL?"":env,"NO")!=0)
__MLogOn=YES;
#endif
}
+(void)logFile:(char*)sourceFile lineNumber:(int)lineNumber
format:(NSString*)format, ...;
{
va_list ap;
NSString *print,*file;
if(__MLogOn==NO)
return;
va_start(ap,format);
file=[[NSString alloc] initWithBytes:sourceFile
length:strlen(sourceFile)
encoding:NSUTF8StringEncoding];
print=[[NSString alloc] initWithFormat:format arguments:ap];
va_end(ap);
//MLog handles synchronization issues
NSString *log = [NSString stringWithFormat:@"%s:%d %@",[[file lastPathComponent] UTF8String],
lineNumber,print];
NSLog(log);
[print release];
[file release];
return;
}
+(void)setLogOn:(BOOL)logOn
{
__MLogOn=logOn;
}
@end