Created
August 13, 2012 00:47
-
-
Save Wevah/3335928 to your computer and use it in GitHub Desktop.
AEDebug redirect attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DebugAppleEvents"]) { | |
NSError *error = nil; | |
NSFileManager *fm = [NSFileManager defaultManager]; | |
NSURL *logsDir = [fm URLForDirectory:NSLibraryDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil]; | |
logsDir = [logsDir URLByAppendingPathComponent:@"Logs"]; | |
logsDir = [logsDir URLByAppendingPathComponent:@"Paparazzi!"]; | |
if (![logsDir checkResourceIsReachableAndReturnError:&error]) { | |
if (![fm createDirectoryAtURL:logsDir withIntermediateDirectories:YES attributes:nil error:&error]) | |
NSLog(@"Couldn't create Paparazzi! logs directory: %@", error); | |
} | |
NSURL *logFile = [logsDir URLByAppendingPathComponent:@"AEDebugLog.log"]; | |
NSFileHandle *fh = nil; | |
if (![logFile checkResourceIsReachableAndReturnError:&error]) { | |
int fd = open(logFile.path.UTF8String, O_WRONLY | O_CREAT | O_EXCL, S_IRWXU); | |
if (fd != -1) | |
fh = [[NSFileHandle alloc] initWithFileDescriptor:fd closeOnDealloc:YES]; | |
} else | |
fh = [[NSFileHandle fileHandleForUpdatingURL:logFile error:&error] retain]; | |
if (!fh) | |
NSLog(@"Couldn't open log for writing: %@", error); | |
int err = dup2([fh fileDescriptor], STDERR_FILENO); | |
if (err == -1) | |
NSLog(@"dup2 got error: %d", errno); | |
setenv("AEDebugSends", "1", 1); | |
setenv("AEDebugReceives", "1", 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment