{"id":41,"date":"2013-01-27T20:51:35","date_gmt":"2013-01-27T20:51:35","guid":{"rendered":"http:\/\/www.appinf.com\/blog\/?p=41"},"modified":"2013-01-27T21:16:05","modified_gmt":"2013-01-27T21:16:05","slug":"logging-with-poco-on-ios","status":"publish","type":"post","link":"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/","title":{"rendered":"Logging with POCO on iOS"},"content":{"rendered":"<p>The <a href=\"http:\/\/pocoproject.org\">POCO C++ Libraries<\/a> come with a powerful logging framework that supports different logging channels like log files, console, syslog or the Windows Event Log. All of these channels (except maybe the FileChannel) are not very useful when developing applications for the iPhone. So what should one do when porting existing C++ code that uses the POCO logging framework to the iPhone? Wouldn't it be nice to see the logging output in the Xcode debugger's output window? As easy as pie! Since the POCO logging framework is extensible with new channel types, we simply create a new Channel class that uses the iOS NSLog() function. We'll call the new class NSLogChannel. The implementation is just a few lines of code. We create a new subclass of Poco::Channel and override the log() member function. The header file for NSLogChannel is shown below:<\/p>\r\n\r\n<code>\/*\r\n* NSLogChannel.h\r\n*\r\n*\/\r\n\r\n#ifndef NSLogChannel_INCLUDED\r\n#define NSLogChannel_INCLUDED\r\n\r\n#include \"Poco\/Channel.h\"\r\n\r\nclass NSLogChannel: public Poco::Channel\r\n{\r\npublic:\r\n    void log(const Poco::Message&amp; msg);\r\n};\r\n\r\n#endif \/\/ NSLogChannel_INCLUDED<\/code>\r\n\r\n<p>In the log() method, we just call NSLog(), passing int he message source and text. We could actually omit the message source and use a FormattingChannel to format the log message prior to passing it to the channel, but we'll keep things simple.<\/p>\r\n\r\n<code>\/*\r\n* NSLogChannel.cpp\r\n*\r\n*\/\r\n\r\n#include \"NSLogChannel.h\"\r\n#include \"Poco\/Message.h\"\r\n#import &lt;Foundation\/Foundation.h&gt;\r\n\r\nvoid NSLogChannel::log(const Poco::Message&amp; msg)\r\n{\r\n    NSLog(@\"%s: %s\", msg.getSource().c_str(), msg.getText().c_str());\r\n}<\/code>\r\n\r\n<p>Now that we have the NSLogChannel class, we need to register it with the logging framework. A good place to do this is the application's main() function. We're going to mix Objective-C and C++ code in the same file, so the file containing the main() function should have the extension \".M\" (note the uppercase M), so Xcode will compile the file as Objective-C++.<\/p>\r\n\r\n<code>#import &lt;UIKit\/UIKit.h&gt;\r\n#import \"NSLogChannel.h\"\r\n#import \"Poco\/Logger.h\"\r\n\r\nint main(int argc, char *argv[]) {\r\n\r\n    Poco::Logger::root().setChannel(new NSLogChannel);\r\n\r\n    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];\r\n    int retVal = UIApplicationMain(argc, argv, nil, nil);\r\n    [pool release];\r\n    return retVal;\r\n}<\/code>\r\n\r\n<p>That's it. Everything logged using the POCO logging framework will now appear in the debug output in Xcode.<\/p>","protected":false},"excerpt":{"rendered":"<p>The POCO C++ Libraries come with a powerful logging framework that supports different logging channels like log files, console, syslog or the Windows Event Log. All of these channels (except maybe the FileChannel) are not very useful when developing applications for the iPhone. So what should one do when porting existing C++ code that uses [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_eb_attr":"","footnotes":""},"categories":[14,13],"tags":[15,16,17,7],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Logging with POCO on iOS - macchina.io Blog [STAGING]<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Logging with POCO on iOS - macchina.io Blog [STAGING]\" \/>\n<meta property=\"og:description\" content=\"The POCO C++ Libraries come with a powerful logging framework that supports different logging channels like log files, console, syslog or the Windows Event Log. All of these channels (except maybe the FileChannel) are not very useful when developing applications for the iPhone. So what should one do when porting existing C++ code that uses [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/\" \/>\n<meta property=\"og:site_name\" content=\"macchina.io Blog [STAGING]\" \/>\n<meta property=\"article:published_time\" content=\"2013-01-27T20:51:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-01-27T21:16:05+00:00\" \/>\n<meta name=\"author\" content=\"G\u00fcnter Obiltschnig\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@macchina_io\" \/>\n<meta name=\"twitter:site\" content=\"@macchina_io\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"G\u00fcnter Obiltschnig\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/\"},\"author\":{\"name\":\"G\u00fcnter Obiltschnig\",\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/#\/schema\/person\/85e732123d4102689b6436b2807a626b\"},\"headline\":\"Logging with POCO on iOS\",\"datePublished\":\"2013-01-27T20:51:35+00:00\",\"dateModified\":\"2013-01-27T21:16:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/\"},\"wordCount\":278,\"publisher\":{\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/#organization\"},\"keywords\":[\"iOS\",\"logging\",\"NSLog\",\"poco\"],\"articleSection\":[\"POCO C++ Libraries\",\"Tips &amp; Tricks\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/\",\"url\":\"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/\",\"name\":\"Logging with POCO on iOS - macchina.io Blog [STAGING]\",\"isPartOf\":{\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/#website\"},\"datePublished\":\"2013-01-27T20:51:35+00:00\",\"dateModified\":\"2013-01-27T21:16:05+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/web-staging.macchina.io\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Logging with POCO on iOS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/#website\",\"url\":\"https:\/\/web-staging.macchina.io\/blog\/\",\"name\":\"macchina.io Blog [STAGING]\",\"description\":\"Internet of Things, edge computing, IoT device software, C++\",\"publisher\":{\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/web-staging.macchina.io\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/#organization\",\"name\":\"macchina.io\",\"url\":\"https:\/\/web-staging.macchina.io\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2018\/08\/macchina.io_emp_logo.png\",\"contentUrl\":\"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2018\/08\/macchina.io_emp_logo.png\",\"width\":1537,\"height\":529,\"caption\":\"macchina.io\"},\"image\":{\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/macchina_io\",\"https:\/\/www.linkedin.com\/showcase\/37869369\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/web-staging.macchina.io\/blog\/#\/schema\/person\/85e732123d4102689b6436b2807a626b\",\"name\":\"G\u00fcnter Obiltschnig\",\"sameAs\":[\"http:\/\/www.appinf.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Logging with POCO on iOS - macchina.io Blog [STAGING]","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/","og_locale":"en_US","og_type":"article","og_title":"Logging with POCO on iOS - macchina.io Blog [STAGING]","og_description":"The POCO C++ Libraries come with a powerful logging framework that supports different logging channels like log files, console, syslog or the Windows Event Log. All of these channels (except maybe the FileChannel) are not very useful when developing applications for the iPhone. So what should one do when porting existing C++ code that uses [&hellip;]","og_url":"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/","og_site_name":"macchina.io Blog [STAGING]","article_published_time":"2013-01-27T20:51:35+00:00","article_modified_time":"2013-01-27T21:16:05+00:00","author":"G\u00fcnter Obiltschnig","twitter_card":"summary_large_image","twitter_creator":"@macchina_io","twitter_site":"@macchina_io","twitter_misc":{"Written by":"G\u00fcnter Obiltschnig","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/#article","isPartOf":{"@id":"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/"},"author":{"name":"G\u00fcnter Obiltschnig","@id":"https:\/\/web-staging.macchina.io\/blog\/#\/schema\/person\/85e732123d4102689b6436b2807a626b"},"headline":"Logging with POCO on iOS","datePublished":"2013-01-27T20:51:35+00:00","dateModified":"2013-01-27T21:16:05+00:00","mainEntityOfPage":{"@id":"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/"},"wordCount":278,"publisher":{"@id":"https:\/\/web-staging.macchina.io\/blog\/#organization"},"keywords":["iOS","logging","NSLog","poco"],"articleSection":["POCO C++ Libraries","Tips &amp; Tricks"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/","url":"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/","name":"Logging with POCO on iOS - macchina.io Blog [STAGING]","isPartOf":{"@id":"https:\/\/web-staging.macchina.io\/blog\/#website"},"datePublished":"2013-01-27T20:51:35+00:00","dateModified":"2013-01-27T21:16:05+00:00","breadcrumb":{"@id":"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/web-staging.macchina.io\/blog\/tips-tricks\/logging-with-poco-on-ios\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/web-staging.macchina.io\/blog\/"},{"@type":"ListItem","position":2,"name":"Logging with POCO on iOS"}]},{"@type":"WebSite","@id":"https:\/\/web-staging.macchina.io\/blog\/#website","url":"https:\/\/web-staging.macchina.io\/blog\/","name":"macchina.io Blog [STAGING]","description":"Internet of Things, edge computing, IoT device software, C++","publisher":{"@id":"https:\/\/web-staging.macchina.io\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/web-staging.macchina.io\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/web-staging.macchina.io\/blog\/#organization","name":"macchina.io","url":"https:\/\/web-staging.macchina.io\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/web-staging.macchina.io\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2018\/08\/macchina.io_emp_logo.png","contentUrl":"https:\/\/macchina.io\/blog\/wp-content\/uploads\/2018\/08\/macchina.io_emp_logo.png","width":1537,"height":529,"caption":"macchina.io"},"image":{"@id":"https:\/\/web-staging.macchina.io\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/macchina_io","https:\/\/www.linkedin.com\/showcase\/37869369"]},{"@type":"Person","@id":"https:\/\/web-staging.macchina.io\/blog\/#\/schema\/person\/85e732123d4102689b6436b2807a626b","name":"G\u00fcnter Obiltschnig","sameAs":["http:\/\/www.appinf.com"]}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/web-staging.macchina.io\/blog\/wp-json\/wp\/v2\/posts\/41"}],"collection":[{"href":"https:\/\/web-staging.macchina.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/web-staging.macchina.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/web-staging.macchina.io\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/web-staging.macchina.io\/blog\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":10,"href":"https:\/\/web-staging.macchina.io\/blog\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":43,"href":"https:\/\/web-staging.macchina.io\/blog\/wp-json\/wp\/v2\/posts\/41\/revisions\/43"}],"wp:attachment":[{"href":"https:\/\/web-staging.macchina.io\/blog\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/web-staging.macchina.io\/blog\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/web-staging.macchina.io\/blog\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}