Created
April 7, 2013 09:55
-
-
Save enzo-yang/5329839 to your computer and use it in GitHub Desktop.
Get Log Outputs In Objective C Program Programmatically
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
| #import <asl.h> | |
| - (void)updateLogs { | |
| NSDateFormatter *formater = [[NSDateFormatter alloc] init]; | |
| [formater setDateFormat:@"MM-dd HH:mm:ss"]; | |
| aslmsg query = NULL, message = NULL; | |
| aslresponse response = NULL; | |
| query = asl_new(ASL_TYPE_QUERY); | |
| const char *time = [[NSString stringWithFormat:@"%d", _lastTime] UTF8String]; | |
| asl_set_query(query, ASL_KEY_TIME, time, ASL_QUERY_OP_GREATER | ASL_QUERY_OP_NUMERIC); | |
| asl_set_query(query, ASL_KEY_FACILITY, [[[NSBundle mainBundle] bundleIdentifier] UTF8String], ASL_QUERY_OP_EQUAL); | |
| response = asl_search(NULL, query); | |
| while (NULL != (message = aslresponse_next(response))) { | |
| const char *content = asl_get(message, ASL_KEY_MSG); | |
| const char *time = asl_get(message, ASL_KEY_TIME); | |
| _lastTime = atoi(time); | |
| LogRecord *record = [[LogRecord new] autorelease]; | |
| record.content = [[[NSString alloc] initWithUTF8String:content] autorelease]; | |
| record.time = [formater stringFromDate:[NSDate dateWithTimeIntervalSince1970:_lastTime]]; | |
| [((NSMutableArray *)self.logs) addObject:record]; | |
| } | |
| aslresponse_free(response); | |
| asl_free(query); | |
| [formater release]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment