美文网首页
日志重定向

日志重定向

作者: iOS白水 | 来源:发表于2020-09-10 14:13 被阅读0次

背景: 第三方调试日志,需要真实路测场景 或者 提供完整的日志 给与排查。
就是这么简单。通过pp助手之类查看doucment文档目录

- (void)redirectNSLogToDucumentFile{
    //创建文件路径
    NSString *documentpath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSDate *currentDate = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *currentDateString = [dateFormatter stringFromDate:currentDate];
    NSString *fileName = [NSString stringWithFormat:@"log_%@.txt",currentDateString];
    NSString *logFilePath = [documentpath stringByAppendingPathComponent:fileName];
    //删除已经存在文件
    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager removeItemAtPath:logFilePath error:nil];
      // 将log输入到文件
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [self redirectNSLogToDucumentFile];
}

相关文章

  • iOS开发小技巧

    将Log日志重定向输出到文件中保存

  • 2018-08-22linux命令操作

    查看日志流程 查看文件常用命令 > 重定向覆盖>> 重定向追加配合 cat grep tail 如cat c...

  • docker日志轮转

    总结 1、可以实现日志输出重定向; 2、可以通过配置日志轮转规则实现docker日志轮转压缩。 操作如下: 1、修...

  • 日志重定向

    背景: 第三方调试日志,需要真实路测场景 或者 提供完整的日志 给与排查。就是这么简单。通过pp助手之类查看dou...

  • Rsyslog服务无法生成目录文件

    问题: rsyslog接收syslog数据后重定向日志保存路径(特定路径下/opt)无法按照路径产生目录及日志文件...

  • python使用日志系统--Apple的学习笔记

    一,前言 之前QT工程已经学习了日志系统35.QT重定向日志系统--Apple的学习笔记[https://www....

  • Python 命令输出重定向有缓存的问题

    将 Python 命令的输出重定向到日志文件的时候,发现输出并不会写到日志文件里 原因是 Python 做了缓存,...

  • postgresql.conf参数说明

    1.logging_collector = on/off ---- 是否将日志重定向至文件中(该配置修改后,需...

  • 重定向adb logcat输出到文件

    重定向adb logcat输出到文件 在使用Android Studio开发时,经常会遇到logcat的日志无法显...

  • docker文档合集

    docker alpine中安装telnet如何将docker日志重定向到单个文件里docker CE与EE区别/...

网友评论

      本文标题:日志重定向

      本文链接:https://www.haomeiwen.com/subject/aulpektx.html