---
title: "把 iOS app logs 写入 documents 文件夹"
author: "简单的茶"
date: "2013-12-06T17:15:03Z"
tags: []
categories: ["移动开发"]
slug: "ios-app-logs-documents"
draft: false
lastmod: "2013-12-06T17:24:06Z"
id: 1986409
url: "https://lisai.iteye.com/blog/1986409"
---

Now, in order to tell your app to redirect the NSLog() outputs to a file, you should do something like this:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

NSString *documentsDirectory = ;

NSString *fileName =];

NSString *logFilePath = ;

freopen(,"a+",stderr);
The last sentence is the one that actually redirects the output.

So once you have done that, your app logs will be stored in the application's documents folder.

 :D  :D  :D 


BTW: Organizer shows the console also, which has the NSLog output. The device has to be provisioned and have settings->developer settings->Logging turned on.