-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGeniusDocument_DebugLogging.m
More file actions
102 lines (83 loc) · 3.45 KB
/
GeniusDocument_DebugLogging.m
File metadata and controls
102 lines (83 loc) · 3.45 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
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
//
// GeniusDocument_DebugLogging.m
// Genius
//
// Created by Chris Miner on 09.01.08.
// Copyright 2008 Chris Miner. All rights reserved.
//
#import "GeniusDocument_DebugLogging.h"
#import <JRSwizzle/JRSwizzle.h>
//! Simple swizzle based logging code.
@implementation GeniusDocument(DebugLogging)
//! replaces some methods with logging versions.
+ (void) installLogging
{
NSError *error = nil;
// insertObject:inPairsAtIndex:
[GeniusDocument jr_swizzleMethod:@selector(insertObject:inPairsAtIndex:) withMethod:@selector(insertObject:inPairsAtIndex:) error:&error];
NSAssert1(error == nil, @"Swizzle Unexpectedly Failed %@", error);
// removeObjectFromPairsAtIndex:
[GeniusDocument jr_swizzleMethod:@selector(removeObjectFromPairsAtIndex:) withMethod:@selector(log_removeObjectFromPairsAtIndex:) error:&error];
NSAssert1(error == nil, @"Swizzle Unexpectedly Failed %@", error);
// setPairs:
[GeniusDocument jr_swizzleMethod:@selector(setPairs:) withMethod:@selector(log_setPairs:) error:&error];
NSAssert1(error == nil, @"Swizzle Unexpectedly Failed %@", error);
// observeValueForKeyPath:ofObject:change:context:
[GeniusDocument jr_swizzleMethod:@selector(observeValueForKeyPath:ofObject:change:context:) withMethod:@selector(log_observeValueForKeyPath:ofObject:change:context:) error:&error];
NSAssert1(error == nil, @"Swizzle Unexpectedly Failed %@", error);
// updateChangeCount:
[GeniusDocument jr_swizzleMethod:@selector(updateChangeCount:) withMethod:@selector(log_updateChangeCount:) error:&error];
NSAssert1(error == nil, @"Swizzle Unexpectedly Failed %@", error);
}
//! logs referenced call to referenced method executes it
- (void)log_updateChangeCount:(NSDocumentChangeType)change
{
NSString *changeString = nil;
switch(change)
{
case NSChangeDone:
changeString = @"NSChangeDone";
break;
case NSChangeUndone:
changeString = @"NSChangeUndone";
break;
case NSChangeCleared:
changeString = @"NSChangeCleared";
break;
case NSChangeReadOtherContents:
changeString = @"NSChangeReadOtherContents";
break;
case NSChangeAutosaved:
changeString = @"NSChangeAutosaved";
break;
}
NSLog(@"_cmd: %s change: %@", _cmd, changeString);
[self log_updateChangeCount:change];
}
//! logs referenced call to referenced method executes it
- (void)log_observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
id newValue = [change valueForKey:NSKeyValueChangeNewKey];
Class class = [object class];
NSLog(@"Changed %@ instance %@ to %@", class, keyPath, newValue);
[self log_observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
//! logs referenced call to referenced method executes it
- (void) log_insertObject:(GeniusPair*) pair inPairsAtIndex:(int)index
{
NSLog(@"_cmd: %s", _cmd);
[self log_insertObject:pair inPairsAtIndex:index];
}
//! logs referenced call to referenced method executes it
- (void) log_removeObjectFromPairsAtIndex:(int) index
{
NSLog(@"_cmd: %s", _cmd);
[self log_removeObjectFromPairsAtIndex:index];
}
//! logs referenced call to referenced method executes it
- (void) log_setPairs: (NSMutableArray*) values
{
NSLog(@"_cmd: %s", _cmd);
return [self log_setPairs:values];
}
@end