Re: Custom log file for NSLog
Re: Custom log file for NSLog
- Subject: Re: Custom log file for NSLog
- From: Citizen <email@hidden>
- Date: Tue, 5 May 2009 09:40:07 +0100
You may find this series of articles on ASL useful as well:
http://boredzo.org/blog/archives/2008-01-20/why-asl
Regards,
Dave
On 5 May 2009, at 01:05, Torsten Curdt wrote:
Have a look here:
http://github.com/tcurdt/feedbackreporter/blob/443300c21f6b7c5b70298edd861b4b2017a97b00/Sources/Main/FRConsoleLog.m
HTH
--
Torsten
On Mon, May 4, 2009 at 22:49, Randall Meadows <email@hidden>
wrote:
I want to have a custom log file for my app, so that my client can
send it
to me when things go "different".
In reading the docs for NSLog, it seems that it is just a front-end
for asl.
So here's what I thought should work:
directories = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES);
NSString *logFileName = nil;
int result = 0;
if ([directories count] > 0) {
logFileName = [directories objectAtIndex:0];
logFileName = [logFileName stringByAppendingPathComponent:@"Logs"];
if ([fileMgr createDirectoryAtPath:logFileName
withIntermediateDirectories:YES attributes:nil error:nil]) {
logFileName = [logFileName
stringByAppendingPathComponent:@"MyLogFile.log"];
int fd = open([logFileName fileSystemRepresentation],
(O_RDWR|O_CREAT|O_TRUNC), (S_IRWXU|S_IRWXG|S_IRWXO));
if (fd != -1) {
result = asl_add_log_file(NULL, fd);
}
}
}
This results in the file being created, but nothing ever being
written to
it. In Console.app, I can see the messages when I select "All
Messages",
"Console Messages", and "system.log", but *not* "MyLogFile.log".
I assume it has something to do with this comment in the docs for
NSLogv
(which NSLog calls): "If the STDERR_FILENO file descriptor has been
redirected away from the default or is going to a tty, it will also
be
written there. If you want to direct output elsewhere, you need to
use a
custom logging facility." This seems contradictory to the
statement that
NSLog "Logs an error message to the Apple System Log facility." If
anyone
would like to educate me on my obvious misunderstanding of this, I'd
appreciate it.
Anyway, I tried it, and yes, redirecting stderr to my log file does
put all
my NSLogs into my log file. But, it also prevents the messages
from being
seen in Xcode's Console window.
How can I have my cake and eat it too?
randy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden