ios - Optimize apple system logs -


+ (nsarray *)systemlogdictionariesforappname:(nsstring *)appname {      aslmsg q = asl_new(asl_type_query);   asl_set_query(q, asl_key_sender, [appname cstringusingencoding:nsasciistringencoding], asl_query_op_equal);   aslresponse r = asl_search(null, q);   aslmsg m;   uint32_t i;   const char *key, *val;   nsmutablearray *systemlogdictionaries = [nsmutablearray array];    while (null != (m = aslresponse_next(r)))   {       nsmutabledictionary *dictionary = [nsmutabledictionary dictionary];       (i = 0; (null != (key = asl_key(m, i))); i++)       {           val = asl_get(m, key);           nsstring *stringkey = [nsstring stringwithcstring:key encoding:nsutf8stringencoding];           nsstring *stringval = [nsstring stringwithcstring:val encoding:nsutf8stringencoding];            [dictionary setobject:stringval forkey:stringkey];       }       [systemlogdictionaries addobject:dictionary];   }   aslresponse_free(r);    return systemlogdictionaries; } 

above code apple system log. problem is, take around 8second pull logs apple system log (asl). there way optimize asl_set_query data faster or other way missing.

note: can create asl query take time stamp , can less number of data process. solve problem think.

asl supports few different logging levels, specify more restrictive level.

for example can add query (according man page joined via logical and):

    // ...     asl_set_query(q, asl_key_sender, [appname cstringusingencoding:nsasciistringencoding], asl_query_op_equal);     // 3 error messages     asl_set_query(q, asl_key_level, "3", asl_query_op_less_equal | asl_query_op_numeric);      //-- check time --//      /* dumped entry code looks like:           aslmessageid = 1825403;          "cflog local time" = "2013-07-20 08:33:12.943";          "cflog thread" = 951f;          facility = "com.apple.safari";          gid = 20;          host = "xxx.local";          level = 4;          message = "cfpropertylistcreatefromxmldata(): old-style plist parser: missing semicolon in dictionary on line 3. parsing abandoned. break on _cfpropertylistmissingsemicolon debug.";          pid = 183;          readuid = 501;          sender = safari;          time = 1374305592;          timenanosec = 943173000;          uid = 501;      time unix timestamp, can use in query asl_key_time , 1 of these operators: asl_query_op_equal, asl_query_op_greater, asl_query_op_greater_equal, asl_query_op_less, asl_query_op_less_equal, asl_query_op_not_equal      code below, generates unix timestamp yesterday , dumps messages occurred yesterday or later.      (nevermind dirty/hacky way generate timestamp, testing purposes) */     nsdate *yesterday = [nsdate datewithtimeintervalsincenow: -(60.0f*60.0f*24.0f)];     nsstring *thedate = [nsstring stringwithformat:@"%d", (int)[yesterday timeintervalsince1970]];      asl_set_query(q, asl_key_time, [thedate cstringusingencoding:nsasciistringencoding], asl_query_op_greater_equal | asl_query_op_numeric);     aslresponse r = asl_search(null, q);     //... 

for more information on different error levels check: http://www.cocoanetics.com/2011/03/accessing-the-ios-system-log/

note that, depending on level set , level log messages are, further filtering may have no effect (ie. if messages logged app of same level)

further note, unlike debug level querying, haven't yet used timestamp querying in productive code, in test seems work fine , doing supposed do.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -