希望找个swift的log的库
除了实现print的效果还有可以输出到文件,便于调试设备,发现问题
swift log library
NSLog alternatives for better logging with shipping apps ⋅ ObjDev
Swift Log – Devil or Why print is dangerous — iOS App Development — Medium
The First Essential Swift 3rd Party Library To Include In Your Project – Cerebral Gardens – Blog
Logging library for Swift – Stack Overflow
goktugyil/QorumLogs: Swift Logging Utility for Xcode & Google Docs
hubertr/Swell: Logging utility for Swift and Objective C
Wolg/awesome-swift: A curated list of awesome Swift frameworks, libraries and software.
“
- QorumLogs — Swift Logging Utility for Xcode & Google Docs.
- CleanroomLogger – A configurable and extensible pure Swift logging API that is simple, lightweight and performant.
- XCGLogger – A debug log framework for use in Swift projects.
- Swell – A logging utility for Swift and Objective C.
- Log – A logging tool with built-in themes, formatters, and a nice API to define your owns.
”
swift 日志 库
XCGLogger
代码:
var gLog:XCGLogger! let DocumentDirectory = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first! /*************************************************************************** let LoggingFile = LoggingRootDir.URLByAppendingPathComponent("jiandao.log") func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { gLog = XCGLogger.defaultInstance() gLog.setup( XCGLogger.LogLevel.Debug, showThreadName: true, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: LoggingFile, fileLogLevel: XCGLogger.LogLevel.Debug) gLog.verbose("A verbose message, usually useful when working on a specific problem") gLog.debug("A debug message") gLog.info("An info message, probably useful to power users looking in console.app") gLog.warning("A warning message, may indicate a possible error") gLog.error("An error occurred, but it’s recoverable, just info about what happened") gLog.severe("A severe error occurred, we are likely about to crash now") |
效果:
模拟器输出:
2016-03-30 17:45:38.064 简道[16024:901687] Unknown class _TtC6简道14ViewController in Interface Builder file. 2016-03-30 17:49:02.377 [Info] > 简道 Version: 1.0 Build: 1 PID: 16024 2016-03-30 17:49:02.377 [Info] > XCGLogger Version: 3.3 – LogLevel: Debug 2016-03-30 17:49:02.392 [Info] > XCGLogger writing to log to: file:///Users/crifan/Library/Developer/CoreSimulator/Devices/63F89987-3382-42A5-BC13-AE102BEF98DB/data/Containers/Data/Application/9410709F-01B6-4208-886F-CDB7F6587D76/Documents/jiandao.log 2016-03-30 17:49:03.822 [Debug] [main] [AppDelegate.swift:33] application(_:willFinishLaunchingWithOptions:) > A debug message 2016-03-30 17:49:04.479 [Info] [main] [AppDelegate.swift:34] application(_:willFinishLaunchingWithOptions:) > An info message, probably useful to power users looking in console.app 2016-03-30 17:49:05.683 [Warning] [main] [AppDelegate.swift:35] application(_:willFinishLaunchingWithOptions:) > A warning message, may indicate a possible error 2016-03-30 17:49:06.281 [Error] [main] [AppDelegate.swift:36] application(_:willFinishLaunchingWithOptions:) > An error occurred, but it’s recoverable, just info about what happened 2016-03-30 17:49:06.999 [Severe] [main] [AppDelegate.swift:37] application(_:willFinishLaunchingWithOptions:) > A severe error occurred, we are likely about to crash now (lldb) |
真机输出效果:
2016-03-30 17:51:53.899 简道[327:30380] Unknown class _TtC6简道14ViewController in Interface Builder file. 2016-03-30 17:52:00.085 [Info] > 简道 Version: 1.0 Build: 1 PID: 327 2016-03-30 17:52:00.085 [Info] > XCGLogger Version: 3.3 – LogLevel: Debug 2016-03-30 17:52:00.108 [Info] > XCGLogger writing to log to: file:///var/mobile/Containers/Data/Application/0D469B28-6209-4047-98D6-4D0CBCB85B4E/Documents/jiandao.log 2016-03-30 17:52:00.109 [Debug] [main] [AppDelegate.swift:33] application(_:willFinishLaunchingWithOptions:) > A debug message 2016-03-30 17:52:00.110 [Info] [main] [AppDelegate.swift:34] application(_:willFinishLaunchingWithOptions:) > An info message, probably useful to power users looking in console.app 2016-03-30 17:52:00.111 [Warning] [main] [AppDelegate.swift:35] application(_:willFinishLaunchingWithOptions:) > A warning message, may indicate a possible error 2016-03-30 17:52:00.111 [Error] [main] [AppDelegate.swift:36] application(_:willFinishLaunchingWithOptions:) > An error occurred, but it’s recoverable, just info about what happened 2016-03-30 17:52:00.112 [Severe] [main] [AppDelegate.swift:37] application(_:willFinishLaunchingWithOptions:) > A severe error occurred, we are likely about to crash now (lldb) |
效果不错。
[后记 2016-04-06]
后来看到:
Technical Q&A QA1669: Improved logging in Objective-C
看到了,关于想要log中记录文件名,函数名,用的是:
NSLog(@"%s:%d someObject=%@", __func__, __LINE__, someObject); |
即:
__func__, __LINE__
和C语言,是一致的
-》也就能猜出来,估计XCGLogger内存,也是根据是否显示文件名,函数名这些参数,决定是否添加对应的__func__, __LINE__的
结果去看源码,竟然没有找到__func__, __LINE__
抽空再继续研究吧。
转载请注明:在路上 » [已解决]swift日志方面的好用的库