Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDFileLogger: fixed crash that occured in case if application name == nil #198

Merged
merged 2 commits into from
Dec 27, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions Lumberjack/DDFileLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,7 @@ - (NSString *)logsDirectory
**/
- (BOOL)isLogFile:(NSString *)fileName
{
#if TARGET_OS_IPHONE
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
#else
NSString *appName = [[NSProcessInfo processInfo] processName];
#endif
NSString *appName = [self applicationName];

BOOL hasProperPrefix = [fileName hasPrefix:appName];
BOOL hasProperSuffix = [fileName hasSuffix:@".log"];
Expand Down Expand Up @@ -416,11 +412,7 @@ - (NSArray *)sortedLogFileInfos
**/
- (NSString *)generateLogFileNameWithAttempt:(NSUInteger)attempt
{
#if TARGET_OS_IPHONE
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
#else
NSString *appName = [[NSProcessInfo processInfo] processName];
#endif
NSString *appName = [self applicationName];

NSDateFormatter *dateFormatter = [self logFileDateFormatter];
NSString *formattedDate = [dateFormatter stringFromDate:[NSDate date]];
Expand Down Expand Up @@ -482,6 +474,31 @@ - (NSString *)createNewLogFile
} while(YES);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Utility
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

- (NSString *)applicationName
{
#if TARGET_OS_IPHONE
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];

if (! appName)
{
appName = [[NSProcessInfo processInfo] processName];
}
#else
NSString *appName = [[NSProcessInfo processInfo] processName];
#endif

if (! appName)
{
appName = @"";
}

return appName;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that for performance this method should be wrapped inside a dispatch_once block and store the value in a static _appName.


@end

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down