forked from macoscope/CodePilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MCLog.m
113 lines (85 loc) · 3.62 KB
/
MCLog.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
105
106
107
108
109
110
111
112
113
//
// MCLog.m
// Macoscope Commons Library
//
// Created by Daniel on 08-11-03.
// Copyright 2008 Macosope. All rights reserved.
//
#import "MCLog.h"
#import "CPCodePilotConfig.h"
@implementation MCLog
+ (void)prefix:(NSString *)prefixString format:(NSString *)format, ...
{
@autoreleasepool {
va_list ap;
NSString *message;
va_start(ap,format);
message = [[NSString alloc] initWithFormat:format arguments:ap];
va_end(ap);
NSLog(@"%@ %@", prefixString, message);
}
}
+ (void)file:(char *)sourceFile function:(char *)functionName lineNumber:(int)lineNumber format:(NSString *)format, ...
{
@autoreleasepool {
va_list ap;
NSString *print, *file, *function;
va_start(ap,format);
file = [[NSString alloc] initWithBytes:sourceFile length:strlen(sourceFile) encoding:NSUTF8StringEncoding];
function = [NSString stringWithCString:functionName encoding:NSASCIIStringEncoding];
print = [[NSString alloc] initWithFormat:format arguments:ap];
va_end(ap);
NSString *fileLocation = [file lastPathComponent];
NSLog(@"%@:%d %@; %@", fileLocation, lineNumber, function, print);
}
}
+ (NSString *)messageWithFile:(char *)sourceFile function:(char *)functionName lineNumber:(int)lineNumber format:(NSString *)format, ...
{
@autoreleasepool {
va_list ap;
NSString *print, *file, *function;
va_start(ap,format);
file = [[NSString alloc] initWithBytes:sourceFile length:strlen(sourceFile) encoding:NSUTF8StringEncoding];
function = [NSString stringWithCString:functionName encoding:NSASCIIStringEncoding];
print = [[NSString alloc] initWithFormat:format arguments:ap];
va_end(ap);
NSString * buffer = [NSString stringWithFormat:@"%@:%d %@; %@", [file lastPathComponent], lineNumber, function, print];
return buffer;
}
}
NSString * MCToStringFromTypeAndValue(const char * typeCode, void * value)
{
if (strcmp(typeCode, @encode(NSPoint)) == 0) {
return NSStringFromPoint(*(NSPoint *)value);
} else if (strcmp(typeCode, @encode(NSSize)) == 0) {
return NSStringFromSize(*(NSSize *)value);
} else if (strcmp(typeCode, @encode(NSRect)) == 0) {
return NSStringFromRect(*(NSRect *)value);
} else if (strcmp(typeCode, @encode(Class)) == 0) {
return NSStringFromClass(*(Class *)value);
} else if (strcmp(typeCode, @encode(SEL)) == 0) {
return NSStringFromSelector(*(SEL *)value);
} else if (strcmp(typeCode, @encode(NSRange)) == 0) {
return NSStringFromRange(*(NSRange *)value);
} else if (strcmp(typeCode, @encode(id)) == 0) {
return MCNSStringWithFormat(@"%@", (__bridge id)(value));
} else if (strcmp(typeCode, @encode(BOOL)) == 0) {
return (*(BOOL *)value) ? @"YES" : @"NO";
} else if (strcmp(typeCode, @encode(int)) == 0) {
return MCNSStringWithFormat(@"%d", *(int *)value);
} else if (strcmp(typeCode, @encode(NSUInteger)) == 0) {
return MCNSStringWithFormat(@"%lu", *(NSUInteger *)value);
} else if (strcmp(typeCode, @encode(unichar)) == 0) {
return MCNSStringWithFormat(@"%d", *(unichar *)value);
} else if (strcmp(typeCode, @encode(CGFloat)) == 0) {
return MCNSStringWithFormat(@"%f", *(CGFloat *)value);
} else if (strcmp(typeCode, @encode(CGPoint)) == 0) {
return NSStringFromPoint(NSPointFromCGPoint(*(CGPoint *)value));
} else if (strcmp(typeCode, @encode(CGRect)) == 0) {
return NSStringFromRect(NSRectFromCGRect(*(CGRect *)value));
} else if (strcmp(typeCode, @encode(CGSize)) == 0) {
return NSStringFromSize(NSSizeFromCGSize(*(CGSize *)value));
}
return MCNSStringWithFormat(@"? <%s>", typeCode);
}
@end