{"id":15037935,"url":"https://github.com/zjinhu/swiftlog","last_synced_at":"2025-04-09T23:32:57.212Z","repository":{"id":62456813,"uuid":"252404282","full_name":"zjinhu/SwiftLog","owner":"zjinhu","description":"swift砖块系列：Swift Log输出工具，可分级别打印log，方便排查日志，添加unicode转码，持续输出中文，支持swift4以上，支持log到本地文件中，添加淘汰算法默认七天淘汰一次log日志文件","archived":false,"fork":false,"pushed_at":"2024-01-16T01:36:50.000Z","size":145,"stargazers_count":25,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T01:22:54.887Z","etag":null,"topics":["log","print","swift","swift4","swift5"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zjinhu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-04-02T08:56:59.000Z","updated_at":"2025-03-06T08:38:07.000Z","dependencies_parsed_at":"2024-02-03T08:11:47.022Z","dependency_job_id":null,"html_url":"https://github.com/zjinhu/SwiftLog","commit_stats":null,"previous_names":["zjinhu/swiftlog","jackiehu/swiftlog"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjinhu%2FSwiftLog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjinhu%2FSwiftLog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjinhu%2FSwiftLog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjinhu%2FSwiftLog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zjinhu","download_url":"https://codeload.github.com/zjinhu/SwiftLog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248129970,"owners_count":21052670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["log","print","swift","swift4","swift5"],"created_at":"2024-09-24T20:36:21.884Z","updated_at":"2025-04-09T23:32:57.146Z","avatar_url":"https://github.com/zjinhu.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](Image/logo.png)\n\n\n\n[![Version](https://img.shields.io/cocoapods/v/Swift_Log.svg?style=flat)](http://cocoapods.org/pods/Swift_Log)\n[![SPM](https://img.shields.io/badge/SPM-supported-DE5C43.svg?style=flat)](https://swift.org/package-manager/)\n![Xcode 9.0+](https://img.shields.io/badge/Xcode-9.0%2B-blue.svg)\n![iOS 9.0+](https://img.shields.io/badge/iOS-9.0%2B-blue.svg)\n![Swift 4.0+](https://img.shields.io/badge/Swift-4.0%2B-orange.svg)\n[![Swift 5.0](https://img.shields.io/badge/Swift-5.0-green.svg?style=flat)](https://developer.apple.com/swift/)\n\nSwift 日志分级打印工具。\n\n支持分不同等级打印log，添加不同emoji方便查阅对应等级，可以设置输出级别，低于该级别的日志不进行打印。\n\n添加专门用于打印网络请求报文的类型unicode转码，方便查看中文日志输出。\n\n支持打印日志到文件，提供文件路径方便上传日志文件，支持文件LRU淘汰，默认七天淘汰一次。用法详见Demo。\n\n尝试了xs max下异步并发的方式写入100条4000字的日志大概需要170毫秒，不写文件仅仅Xcode的日志输出需要150毫秒。FileManager是线程安全的可以放心使用。\n\n## 安装\n\n### cocoapods\n\n1.在 Podfile 中添加 `pod ‘Swift_Log’`\n\n2.执行 `pod install 或 pod update`\n\n3.导入 `import Swift_Log`\n\n### Swift Package Manager\n\n从 Xcode 11 开始，集成了 Swift Package Manager，使用起来非常方便。SwiftLog 也支持通过 Swift Package Manager 集成。\n\n在 Xcode 的菜单栏中选择 `File \u003e Swift Packages \u003e Add Pacakage Dependency`，然后在搜索栏输入\n\n`https://github.com/jackiehu/SwiftLog`，即可完成集成\n\n### 手动集成\n\nSwiftLog 也支持手动集成，只需把Sources文件夹中的SwiftLog文件夹拖进需要集成的项目即可\n\n\n\n## 使用 \n\n```swift\n/// log等级\npublic enum LogDegree : Int{\n    case verbose = 0//最低级log\n    case debug = 1//debug级别\n    case netWork = 2//用于打印网络报文，可单独关闭\n    case info = 3//重要信息级别\n    case warning = 4//警告级别\n    case error = 5//错误级别\n}\n```\n\n```swift\n// 设置默认打印Log的等级。低于此等级不做输出\n    SLog.defaultLogDegree = .debug\n// 用于网络日志的开关\n    SLog.showNetLog = false\n//缓存日志保存最长时间///如果需要自定义时间一定要在addFileLog之前  默认七天\n    SLog.maxLogAge = 60 * 60 * 24 * 7\n// 打印日志到文件中\n    SLog.addFileLog = true\n//获取文件地址URL\n    SLog.getLogFileURL\n```\n输出日志\n```swift\n        SLogVerbose(\"打印最低级信息可忽视不理会\")\n        \n        SLogDebug(\"打印Debug级信息\")\n       \n        //支持打印时unicode转中文\n        SLogNet(\"可单独关闭----\\\\u6253\\\\u5370\\\\u6d88\\\\u606f print message，可以用于打印类似网络请求报文\")\n\n        SLogInfo(\"打印Info级信息\")\n        \n        SLogWarn(\"打印警告级信息\")\n        \n        SLogError(\"打印Error信息\")\n```\n也可以使用这种方法打印\n```swift\n       SLog.verbose(\"ignore\")\n        \n       SLog.debug(\"debug\")\n        \n       SLog.net(\"netWork\")\n       \n       SLog.info(\"info\")\n        \n       SLog.warn(\"warning\")\n        \n       SLog.error(\"error\")\n```\n\n打印输出样式，防止其他输出干扰\n\n```\n🌐 Network 🌐 | 2021-03-05 15:27:33:609 \n 所在类:ViewController.swift \n 方法名:viewDidLoad() \n 所在行:31 \n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c信息\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n\n netWork \n\n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003cEND\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n```\n\n```\n🔔 Info 🔔 | 2021-03-05 15:27:33:614 \n 所在类:ViewController.swift \n 方法名:viewDidLoad() \n 所在行:35 \n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c信息\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n\n info \n\n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003cEND\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n```\n\n```\n⚠️ Warning ⚠️ | 2021-03-05 15:27:33:615 \n 所在类:ViewController.swift \n 方法名:viewDidLoad() \n 所在行:38 \n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c信息\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n\n warning \n\n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003cEND\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n```\n\n```\n❌ Error ❌ | 2021-03-05 15:27:33:616 \n 所在类:ViewController.swift \n 方法名:viewDidLoad() \n 所在行:41 \n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c信息\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n\n error \n\n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003cEND\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n```\n\n```\n✅ Debug ✅ | 2021-03-05 15:36:57:508 \n 所在类:ViewController.swift \n 方法名:viewDidLoad() \n 所在行:28 \n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c信息\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n\n debug \n\n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003cEND\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n\n```\n\n```\n⚪ Verbose ⚪ | 2021-03-05 15:36:57:505 \n 所在类:ViewController.swift \n 方法名:viewDidLoad() \n 所在行:25 \n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c信息\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n\n ignore \n\n\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003c\u003cEND\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\u003e\n```\n\n详细用法参见Demo **ViewController**\n\n## 更多砖块工具加速APP开发\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftBrick\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftBrick)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftMediator\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftMediator)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftShow\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftShow)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftyForm\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftyForm)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftEmptyData\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftEmptyData)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftPageView\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftPageView)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=JHTabBarController\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/JHTabBarController)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftMesh\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftMesh)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftNotification\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftNotification)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftNetSwitch\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftNetSwitch)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftButton\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftButton)\n\n[![ReadMe Card](https://github-readme-stats.vercel.app/api/pin/?username=jackiehu\u0026repo=SwiftDatePicker\u0026theme=radical\u0026locale=cn)](https://github.com/jackiehu/SwiftDatePicker)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzjinhu%2Fswiftlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzjinhu%2Fswiftlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzjinhu%2Fswiftlog/lists"}