swift压缩--Zip

最近项目需要做个日志系统,并且压缩上传。虽然使用的都是第三方库,但是还是在这里写下吧。
使用的第三方
日志使用: https://github.com/DaveWoodCom/XCGLogger
导入项目
使用的pod 导入

pod "XCGLogger" #log日志

日志XCGLogger 配置

import XCGLogger
let log = XCGLogger.default    使用全局常量声明为默认的XCGLogger实例

在AppDelegate中进行一些初始化操作

func application(_application:UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey:Any]?) ->Bool

高级使用
控制台输出:

let systemDestination = AppleSystemLogDestination(identifier:"advancedLogger.systemDestination")

//设置控制台输出的各个配置项

systemDestination.outputLevel= .debug
systemDestination.showLogIdentifier=false
systemDestination.showFunctionName=true
systemDestination.showThreadName=true
systemDestination.showLevel=true
systemDestination.showFileName=true
systemDestination.showLineNumber=true
systemDestination.showDate=true
//logger对象中添加控制台输出
log.add(destination: systemDestination)

日志文件地址:

letlogURL =self.createLogFile()
letfileDestination =FileDestination(writeToFile: logURL,
identifier:"advancedLogger.fileDestination",
shouldAppend:true, appendMarker:"-- Relauched App --")

//设置文件输出的各个配置项

fileDestination.outputLevel= .debug
fileDestination.showLogIdentifier=false
fileDestination.showFunctionName=true
fileDestination.showThreadName=true
fileDestination.showLevel=true
fileDestination.showFileName=true
fileDestination.showLineNumber=true
fileDestination.showDate=true
//文件输出在后台处理
fileDestination.logQueue=XCGLogger.logQueue
//logger对象中添加控制台输出
log.add(destination: fileDestination)
//开始启用
log.logAppDetails()

自定义时间格式:

letdateFormatter =DateFormatter()
dateFormatter.dateFormat="yyyy-MM-dd HH:mm:ss"
dateFormatter.locale=Locale.current
log.dateFormatter= dateFormatter

最后:

log.setup(level: .debug, showThreadName:true, showLevel:true, showFileNames:true, showLineNumbers:true)

调试与发布 配置

#if DEBUG
log.setup(level: .debug, showThreadName:true, showLevel:true, showFileNames:true, showLineNumbers:true)
#else
log.setup(level: .severe, showThreadName:true, showLevel:true, showFileNames:true, showLineNumbers:true)
#end if

基本使用

log.verbose(“一个详细的消息,通常在处理特定问题时很有用”)
log.debug(“ A debug message ”)
log.info(“一个信息消息,可能有用的为用户在console.app中查找”)
log.warning(“警告信息,可能表示可能的错误”)
log.error(“发生错误,但它可以恢复,只是关于发生了什么的信息”)
log.severe(“发生严重错误,我们现在可能会崩溃”)

之前也没加过日志,所以就在项目 登录(超时、重连)、数据库操作catch、 文件操作catch、所有接口返回失败。这些地方加了log.error(".......") 。 希望有人可以留言注意要打日志地方,谢谢。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,050评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,014评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,126评论 6 342
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,536评论 4 61
  • 所有赞美的话,都献给你 ——在我年轻的时候。 所有悲伤的眼泪,都留给自己 ...
    左右中阅读 2,915评论 0 0

友情链接更多精彩内容