{"id":1183,"date":"2015-09-28T05:29:21","date_gmt":"2015-09-27T20:29:21","guid":{"rendered":"https:\/\/ecoop.net\/memo\/?p=1183"},"modified":"2015-09-28T05:30:49","modified_gmt":"2015-09-27T20:30:49","slug":"swift2_disable_debug_log_in_production","status":"publish","type":"post","link":"https:\/\/www.ecoop.net\/memo\/archives\/swift2_disable_debug_log_in_production.html","title":{"rendered":"Swift2\u3067\u30ea\u30ea\u30fc\u30b9\u30d3\u30eb\u30c9\u306e\u6642\u306b\u30ed\u30b0\u8868\u793a\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b"},"content":{"rendered":"<p>Xcode7(Swift2) \u3067\u30c7\u30d0\u30c3\u30b0\u30d3\u30eb\u30c9\u306e\u6642\u3060\u3051\u30c7\u30d0\u30c3\u30b0\u51fa\u529b\u3057\u3066\u3001\u30d7\u30ed\u30c0\u30af\u30b7\u30e7\u30f3\u30d3\u30eb\u30c9\u306e\u6642\u306f\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306e\u305f\u3081\u30c7\u30d0\u30c3\u30b0\u30ed\u30b0\u3092\u524a\u308b\u65b9\u6cd5\u306e\u30e1\u30e2\u3002<\/p>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306b\u3088\u308a\u3001print, debugPrintln, NSLog\u306e\u51fa\u529b\u3092\u5236\u5fa1\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u4e8b\u524d\u6e96\u5099<\/h2>\n<p>Xcode\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306eBuild Settings \u2192 Swift Compiler \u2192 Other Swift Flags \u306e Debug \u306b\u300c-DDEBUG\u300d\u3092\u8ffd\u52a0\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\n<h2>\u30b3\u30fc\u30c9<\/h2>\n<p>AppDelegate.swift \u306e\u5192\u982d\u306b\u4ee5\u4e0b\u306e\u30b0\u30ed\u30fc\u30d0\u30eb\u95a2\u6570\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u4ed6\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u307b\u3046\u304c\u308f\u304b\u308a\u3084\u3059\u3051\u308c\u3070AppDelegate\u4ee5\u5916\u3067\u3082\u5927\u4e08\u592b\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\/\/ \u30ea\u30ea\u30fc\u30b9\u30d3\u30eb\u30c9\u3067print, debugPrint\u3092\u7121\u52b9\u5316\r\nfunc print(object: Any) {\r\n  #if DEBUG\r\n    Swift.print(object, terminator: &quot;&quot;)\r\n  #endif\r\n}\r\n\r\nfunc debugPrint(object: Any) {\r\n  #if DEBUG\r\n    Swift.debugPrint(object, terminator: &quot;&quot;)\r\n  #endif\r\n}\r\n\r\n\/\/ \u30ea\u30ea\u30fc\u30b9\u30d3\u30eb\u30c9\u3067NSLog\u7121\u52b9\u5316\r\nfunc NSLog(message:String){\r\n  #if DEBUG\r\n    Foundation.NSLog(message)\r\n  #endif\r\n}\r\nfunc NSLog(format:String, _ args:CVarArgType...){\r\n  #if DEBUG\r\n    Foundation.NSLog(String(format: format, arguments: args))\r\n  #endif\r\n\r\n}\r\n<\/pre>\n<h2>\u3053\u306e\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u7406\u7531<\/h2>\n<p>print, debugPrint\u306f\u51fa\u3066\u304d\u307e\u3059\u304c\u3001Swift\u3067NSLog\u3092\u975e\u8868\u793a\u306b\u3059\u308b\u65b9\u6cd5\u304c\u3069\u3046\u3057\u3066\u3082\u51fa\u3066\u3053\u306a\u304b\u3063\u305f\u306e\u3067\u8a18\u4e8b\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>Swift2\u304b\u3089\u5ec3\u6b62\u3055\u308c\u305fprintln, debugPrintln\u306f\u3053\u3053\u306b\u66f8\u3044\u3066\u3044\u307e\u305b\u3093\u304c\u3001print, debugPrint \u3068\u540c\u69d8\u306e\u65b9\u6cd5\u3067\u5bfe\u5fdc\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u30b0\u30b0\u308b\u3068 NSLog\u3092\u6d88\u3059\u65b9\u6cd5\u3068\u3057\u3066\u3001\u30d7\u30ec\u30d5\u30a3\u30af\u30b9\u30d8\u30c3\u30c0\u30d5\u30a1\u30a4\u30eb(.pch\u30d5\u30a1\u30a4\u30eb)\u306b #define NSLog \u3092\u65b9\u6cd5\u304c\u51fa\u3066\u304d\u307e\u3059\u304c\u3001\u3053\u3061\u3089\u306fObjective C\u306b\u3057\u304b\u52b9\u679c\u304c\u306a\u3044\u3088\u3046\u306a\u306e\u3067\u6ce8\u610f\u3002<\/p>\n<h2>\u304a\u307e\u3051<\/h2>\n<p>\u4ee3\u66ff\u6848\u3068\u3057\u3066\u306f\u3001\u3088\u308a\u7d30\u304b\u3044\u30ed\u30b0\u30ec\u30d9\u30eb\u5236\u5fa1\u304c\u53ef\u80fd\u306a<a href=\"https:\/\/github.com\/DaveWoodCom\/XCGLogger\">XCGLogger<\/a>\u3092\u4f7f\u3046\u306e\u3082\u624b\u3067\u3059\u3002<\/p>\n<p>AppDelegate\u3067<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nimport XCGLogger\r\n\r\nlet log: XCGLogger = {\r\n  let log = XCGLogger.defaultInstance()\r\n  #if DEBUG\r\n    log.setup(.Debug, showThreadName: true, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: nil)\r\n    #else\r\n    log.setup(.Severe, showThreadName: true, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: nil)\r\n  #endif\r\n  let dateFormatter = NSDateFormatter()\r\n  dateFormatter.dateFormat = &quot;MM\/dd\/yyyy hh:mma&quot;\r\n  dateFormatter.locale = NSLocale.currentLocale()\r\n  log.dateFormatter = dateFormatter\r\n  \r\n  return log\r\n  }()\r\n<\/pre>\n<p>\u3068\u3057\u3066\u304a\u304f\u3068\u3001<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nlog.debug(&quot;Debug\u30ec\u30d9\u30eb\u306e\u30ed\u30b0\u3067\u3059&quot;)\r\nlog.info(&quot;info\u30ec\u30d9\u30eb\u306e\u30ed\u30b0\u3067\u3059&quot;)\r\n<\/pre>\n<p>\u306e\u3088\u3046\u306b\u30ed\u30b0\u30ec\u30d9\u30eb\u3054\u3068\u306e\u30ed\u30b0\u51fa\u529b\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Xcode7(Swift2) \u3067\u30c7\u30d0\u30c3\u30b0\u30d3\u30eb\u30c9\u306e\u6642\u3060\u3051\u30c7\u30d0\u30c3\u30b0\u51fa\u529b\u3057\u3066\u3001\u30d7\u30ed\u30c0\u30af\u30b7\u30e7\u30f3\u30d3\u30eb\u30c9\u306e\u6642\u306f\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306e\u305f\u3081\u30c7\u30d0\u30c3\u30b0\u30ed\u30b0\u3092\u524a\u308b\u65b9\u6cd5\u306e\u30e1\u30e2\u3002 \u3053\u306e\u30b3\u30fc\u30c9\u306b\u3088\u308a\u3001print, debugPrintln, NSLog\u306e &hellip; <a href=\"https:\/\/www.ecoop.net\/memo\/archives\/swift2_disable_debug_log_in_production.html\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Swift2\u3067\u30ea\u30ea\u30fc\u30b9\u30d3\u30eb\u30c9\u306e\u6642\u306b\u30ed\u30b0\u8868\u793a\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117,101],"tags":[],"class_list":["post-1183","post","type-post","status-publish","format-standard","hentry","category-ios-dev","category-mac-2"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/1183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/comments?post=1183"}],"version-history":[{"count":0,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/1183\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/media?parent=1183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/categories?post=1183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/tags?post=1183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}