Is there a way to access iphone crash log file via programmatically. I trying to write a crash report feature that when you launch the app after a crash, it will offer to send the crash report to the server. I can't find how to get the crash log within the app.
Asked
Active
Viewed 2,504 times
2
-
Perhaps one of the answers to a similar question helps you: http://stackoverflow.com/questions/4737701/get-previous-run-crash-logs-on-iphone?rq=1 – Christian Mar 26 '14 at 07:28
-
check this one,may it will help: http://stackoverflow.com/questions/9715127/programmatically-getting-crash-reports-inside-an-ios-app – Dhaval Bhadania Mar 26 '14 at 07:30
-
@Christian thanks.actually i am making my own debugger library so dont want use other library or framework to do that so i check . – Charlie Mar 26 '14 at 07:38
1 Answers
2
You can use the following logic for the same.
aslmsg q, m;
int i;
const char *key, *val;
float how_old = fTime ;
q = asl_new(ASL_TYPE_QUERY);
asl_set_query(q, ASL_KEY_LEVEL, strLoggerLevel ,ASL_QUERY_OP_LESS_EQUAL);
asl_set_query(q, ASL_KEY_FACILITY, [@"YourBundleIdOfAPP" UTF8String] ,ASL_QUERY_OP_EQUAL);
asl_set_query(q, ASL_KEY_TIME, [[NSString stringWithFormat:@"%.f", [[NSDate date] timeIntervalSince1970] - how_old] UTF8String], ASL_QUERY_OP_GREATER_EQUAL);
int goInside=0;
aslresponse r = asl_search(NULL, q);
while (NULL != (m = aslresponse_next(r)))
{
NSString *cValueToWrite;
NSMutableDictionary *tmpDict = [NSMutableDictionary dictionary];
for (i = 0; (NULL != (key = asl_key(m, i))); i++)
{
//get the only required fields
if(i==12 || i==10 || i==11 || i==8 || i==9 ||i==3)
{
NSString *keyString = [NSString stringWithUTF8String:(char *)key];
val = asl_get(m, key);
NSString *string = [NSString stringWithUTF8String:val];
[tmpDict setObject:string forKey:keyString];
}
}
cValueToWrite=[[NSString alloc]initWithFormat:@"\n--------------[Debug]----------------\nDateTime: %@\nApplication: %@\nInfo: %@",[tmpDict valueForKey:@"CFLog Local Time"],[tmpDict valueForKey:@"Sender"],[tmpDict valueForKey:@"Message"]];
}
strLoggerLevel
is the NSString
which holds the logger type which you want which ranges upto 7.
-
can you please tell me what to use in place of fTime in your given solution and i m implementing this can it will solve my purpose? – Charlie Mar 26 '14 at 08:31
-
Its a float value which shows the time in seconds. Means u want log before 1 hr then use 3600.0 – svrushal Mar 26 '14 at 08:33
-
ok.thanks...so i can put Debugging(level Name) in place of strLoggerLevel for getting crash logs? – Charlie Mar 26 '14 at 08:37
-
i tried this code with debugger level ASL_STRING_DEBUG and how_old = 3600.0 but i am getting this output:logFile: --------------[Debug]---------------- DateTime: (null) Application: (null) Info: (null) Is It working code to get crash logs.? – Charlie Mar 26 '14 at 09:09
-
Yes yaar its working fine for me. I have created the library using same code. try to print tmpDict. what it will give. Have you replaced the @"YourBundleIdOfAPP"?? – svrushal Mar 26 '14 at 09:12
-
-
do one thing also check whether it is going into the if loop or not?? – svrushal Mar 26 '14 at 09:16
-
-
yes it's going on loop but in log i am getting this output:- DateTime: (null) Application: (null) Info: (null) – Charlie Mar 26 '14 at 09:42
-
thanks friend its giving me the logs of app and working fine but my work is to get crash logs file of when app crashed last time. – Charlie Mar 26 '14 at 10:06
-
I know. But for that better choice is we ask user who faced the crash issue to send that file of logger in which we logged the crash data. Try with the warning or error which will give you the exact log. also give user facility like drop down for Time and logger level. so that user can send u log of before 1 or 2 or 3 hrs. – svrushal Mar 26 '14 at 10:39