{"id":101,"date":"2008-08-05T23:44:37","date_gmt":"2008-08-06T04:44:37","guid":{"rendered":"http:\/\/vgable.com\/blog\/2008\/08\/05\/simpler-logging-2\/"},"modified":"2008-09-16T19:52:43","modified_gmt":"2008-09-17T00:52:43","slug":"simpler-logging-2","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2008\/08\/05\/simpler-logging-2\/","title":{"rendered":"Simplified Logging"},"content":{"rendered":"<p>I have noticed a pattern in my Cocoa code, which I have been able to simplify.  I often print out the value of a variable for debugging.  99 times out of 100, the code looks like this: <code>NSLog(@\"actionURL = %@\", actionURL);<\/code>, where <code>actionURL<\/code> is some variable.<\/p>\n<p>But using the macros, I can say <b><code>LOG_ID(actionURL);<\/code><\/b>.  This is <em>shorter<\/em>, and <em>non-repetitive<\/em>.<\/p>\n<p><strong>The macros I use to simplify debugging (2008-09-16):<\/strong><br \/>\n<code><br \/>\n#define FourCharCode2NSString(err)\tNSFileTypeForHFSTypeCode(err)<\/p>\n<p>#define LOG_4CC(x)\t\tNSLog(@\"%s = %@\", # x, FourCharCode2NSString(x))<br \/>\n#define LOG_FUNCTION()\tNSLog(@\"%s\", __FUNCTION__)<br \/>\n#define LOG_ID(o)\t\tNSLog(@\"%s = %@\", # o, o)<br \/>\n#define LOG_INT(i)\t\tNSLog(@\"%s = %d\", # i, i)<br \/>\n#define LOG_INT64(ll)   NSLog(@\"%s = %lld\", # ll, ll)<br \/>\n#define LOG_FLOAT(f)\tNSLog(@\"%s = %f\", # f, f)<br \/>\n#define LOG_LONG_FLOAT(f) NSLog(@\"%s = %Lf\", # f, f)<br \/>\n#define LOG_OBJECT(o)\tLOG_ID(o)<br \/>\n#define LOG_POINT(p)\tNSLog(@\"%s = %@\", # p, NSStringFromPoint(p))<br \/>\n#define LOG_RECT(r)\t\tNSLog(@\"%s = %@\", # r, NSStringFromRect(r))<br \/>\n#define LOG_SIZE(s)\t\tNSLog(@\"%s = %@\", # s, NSStringFromSize(s))<\/code><\/p>\n<p>Look in <code>assert.h<\/code> for insight on how to roll your own debugging macros.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have noticed a pattern in my Cocoa code, which I have been able to simplify. I often print out the value of a variable for debugging. 99 times out of 100, the code looks like this: NSLog(@&#8221;actionURL = %@&#8221;, actionURL);, where actionURL is some variable. But using the macros, I can say LOG_ID(actionURL);. This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3,5,4,13,10,8],"tags":[77,80,83],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-cocoa","category-macosx","category-objective-c","category-programming","category-sample-code","category-tips","category-usability","tag-debugging","tag-macros","tag-nslog"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":0,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}