Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically find the user's logging directory?

Given an app called ExampleApp, I want to find "~/Library/Logs/ExampleApp" basically without using hard coded paths. There exists NSSearchPathForDirectoriesInDomains, which you can use to find things like "~/Library/Application Support/ExampleApp" using the NSApplicationSupportDirectory search term, but there doesn't seem to be a search term for logging.

I don't think ~/Library/Logs is non-standard, since CrashReporter puts its logs there.

like image 390
Nick Sonneveld Avatar asked Mar 18 '26 10:03

Nick Sonneveld


1 Answers

Try this :

NSString* libraryPath = [NSHomeDirectory stringByAppendingPathComponent:@"Library/Logs"];

Update (~/Library/Logs/AppName) :

NSString* bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
NSString* logsPath = [NSString stringWithFormat:@"Library/Logs/%@",bundleName];

NSString* libraryPath = [NSHomeDirectory stringByAppendingPathComponent:logsPath];
like image 99
Dr.Kameleon Avatar answered Mar 20 '26 05:03

Dr.Kameleon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!