- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOption
//日志收集(日志会被拦截,开发的时候注掉)
[self redirectNSlogToDocumentFolder];

方法实现

#pragma mark - 日志收集
- (void)redirectNSlogToDocumentFolder
{
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSDateFormatter *dateformat = [[NSDateFormatter alloc]init];
[dateformat setDateFormat:@"yyyy-MM-dd-HH-mm-ss"];
NSString *fileName = [NSString stringWithFormat:@"LOG-%@.txt",[dateformat stringFromDate:[NSDate date]]];
NSString *logFilePath = [documentDirectory stringByAppendingPathComponent:fileName]; // 先删除已经存在的文件
NSFileManager *defaultManager = [NSFileManager defaultManager];
[defaultManager removeItemAtPath:logFilePath error:nil]; // 将log输入到文件
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout); freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);
}

在需要进行收集的时候将文件上传到服务器


作者:Kevin丶
链接:http://www.jianshu.com/p/f60a2c761c3e
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

iOS APP日志写入文件(日志收集)的更多相关文章

  1. Docker,就放弃了把日志写入文件

    日志配置 既然用 Docker,就放弃了把日志写入文件,直接写到标准输出. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ...

  2. logging日志管理-将日志写入文件

    # -*- coding: cp936 -*- # test.py #http://blog.chinaunix.net/uid-27571599-id-3492860.html #logging日志 ...

  3. Python + logging 输出到屏幕,将log日志写入文件

    日志 日志是跟踪软件运行时所发生的事件的一种方法.软件开发者在代码中调用日志函数,表明发生了特定的事件.事件由描述性消息描述,该描述性消息可以可选地包含可变数据(即,对于事件的每次出现都潜在地不同的数 ...

  4. 【php写日志】php将日志写入文件

    php 写内容到文件,把日志写到log文件 <?php header("Content-type: text/html; charset=utf-8"); /******** ...

  5. python中使用logging将日志写入文件或输出到控制台

    import logging import os class Logger: def __init__(self, name=__name__): # 创建一个loggger self.__name ...

  6. iOS App与iTunes文件传输的方法和对iOS App文件结构的说明

    转:http://www.xiaoyaoli.com/?p=368 就像很多iOS上面的播放器App一样,本文编写一个程序可以通过iTunes往里面放文件,比如编写一个音乐播放器程序,通过itune往 ...

  7. SQL SERVER 日志写入原理浅析

    昨天看到网上有一个关于SQL SERVER 课件,便随手下载了下来看看主要讲了些什么内容,于是看到了下面两个PPT页面 由于第一张PPT上的内容不太准确(日志文件中没有“日志页”的概念,只有VLF的概 ...

  8. PHP 输出日志到文件 DEMO

    首先需要确保输出文件有权限写入,一般设置权限为 chown -R nginx.nginx 输出的文件路径 如果以上方法还是无效,可以直接将文件设置有777,但是这种方式只能用于测试环境 chmod - ...

  9. 分享 NET 5.x 自定义文件日志实现 原汁原味

    下面直接贴出实现代码 FileLoggerProvider /// <summary> /// 文件记录器提供商 /// </summary> public class Fil ...

随机推荐

  1. FFmpeg新版本(2016年10月份以后) 支持硬件解码

    FFmpeg provides a subsystem for hardware acceleration. Hardware acceleration allows to use specific ...

  2. Dom对象与jQuery对象的转换

  3. Awake & Start

    [Awake & Start] MonoBehaviour.Awake() Awake is used to initialize any variables or game state be ...

  4. Unity调试设置

    [Unity调试设置] 1.Mac中,"Unity"->"Preferences...". Windows中,"Edit"->& ...

  5. 动画系统II

    [动画系统II] 1.动画混合(animation blending)是把某个时间点的两个或更多的输入姿势结合,产生骨骼的输出姿势.例如,通过混合负伤的及无负伤的步行动画,我们可以生成二者之间不同负伤 ...

  6. Solr查询过程源码分析

    原文出自:http://blog.csdn.net/flyingpig4/article/details/6305488 <pre name="code" class=&qu ...

  7. 616. Add Bold Tag in String加粗字符串

    [抄题]: Given a string s and a list of strings dict, you need to add a closed pair of bold tag <b&g ...

  8. 360 安全卫士 for Linux 使用结果

    测试了一把,结果显示360基本对Linux社区规范和安全常识不give a fuck. 胡乱打包 首先,这个deb包就是胡乱打包,依赖关系就没弄好: $ dpkg-deb -I 360safeforl ...

  9. HandleErrorAttribute只能处理httpStatusCode为500的异常(服务器异常)

    HandleErrorAttribute源代码: [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited ...

  10. LightOJ 1258 Making Huge Palindromes (Manacher)

    题意:给定上一个串,让你在后面添加一些字符,使得这个串成为一个回文串. 析:先用manacher算法进行处理如果发现有字符匹配超过最长的了,结束匹配,答案就是该字符前面那个长度加上该串原来的长度. 代 ...