使用XcodeColors 来显示XCGLogger,进行swift 的logger定制
2016-03-17 00:11
525 查看
XcodeColors项目地址
XcodeColors installation instructions for Xcode 4, 5, 6 & 7:
Download or clone the repository.
Open the XcodeColors project with Xcode
If compiling for Xcode 4, then change the schemes to use the Xcode4 build configuration (instead of the Xcode5 build configuration which is the default)
Compile the XcodeColors target.
When you do this, the Xcode plugin is automatically copied to the proper location.
This is done via the build settings. You can validate the plugin was copied to “~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/XcodeColors.xcplugin”
Now completely Quit Xcode
Re-Launch Xcode, and re-open the XcodeColors project
Now run the TestXcodeColors target.
This will test your installation, and you should see colors in your Xcode console.
Did you upgrade Xcode and now XcodeColors is “broken”? Get the fix here: XcodeUpdates.
$ ./update_compat.sh
在其他的类中引用这个log进行输出
XcodeColors installation instructions for Xcode 4, 5, 6 & 7:
Download or clone the repository.
Open the XcodeColors project with Xcode
If compiling for Xcode 4, then change the schemes to use the Xcode4 build configuration (instead of the Xcode5 build configuration which is the default)
Compile the XcodeColors target.
When you do this, the Xcode plugin is automatically copied to the proper location.
This is done via the build settings. You can validate the plugin was copied to “~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/XcodeColors.xcplugin”
Now completely Quit Xcode
Re-Launch Xcode, and re-open the XcodeColors project
Now run the TestXcodeColors target.
This will test your installation, and you should see colors in your Xcode console.
Did you upgrade Xcode and now XcodeColors is “broken”? Get the fix here: XcodeUpdates.
$ ./update_compat.sh
XCGLogger中定义log显示内容的颜色
在AppDelegate.swift中定义一个全局变量log// // AppDelegate.swift // Meerkat // // Created by 徐泽宇 on 16/3/5. // Copyright © 2016年 九象网络科技(上海). All rights reserved. // import UIKit import XCGLogger @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? let log: XCGLogger = { let log = XCGLogger.defaultInstance() log.setup(.Debug, showThreadName: true, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: nil, fileLogLevel: .Debug) let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy/MM/dd hh:mma" dateFormatter.locale = NSLocale.currentLocale() log.dateFormatter = dateFormatter return log }() func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. //使用XCGLogger记录日志 begin log.xcodeColorsEnabled = true // Or set the XcodeColors environment variable in your scheme to YES log.xcodeColors = [ .Verbose: .lightGrey, .Debug: .darkGrey, .Info: .darkGreen, .Warning: .orange, .Error: XCGLogger.XcodeColor(fg: UIColor.redColor(), bg: UIColor.whiteColor()), // Optionally use a UIColor .Severe: XCGLogger.XcodeColor(fg: (255, 255, 255), bg: (255, 0, 0)) // Optionally use RGB values directly ] //使用XCGLogger记录日志 end // 启动友盟的 分析功能 begin MobClick.startWithAppkey("1111111111", reportPolicy: SEND_INTERVAL, channelId: nil) MobClick.setLogEnabled(true) //友盟SDK为了兼容Xcode3的工程,默认取的是Xcode的Build号。如果需要取Xcode4及以上版本的Version,可以使用下面 的方法。 let version = NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"] as! String MobClick.setAppVersion(version) // 启动友盟的 分析功能 end log.debug("友盟统计sdk载入完成!") return true } func applicationWillResignActive(application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } func applicationDidEnterBackground(application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } func applicationWillEnterForeground(application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } func applicationDidBecomeActive(application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } func applicationWillTerminate(application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } }
在其他的类中引用这个log进行输出
var appDelegate=AppDelegate() appDelegate.log.debug("摄像头界面初始化完成!")
相关文章推荐
- Swift开发第六篇——操作运算符也可以重载& func 的参数修饰
- swift内存泄露,与OC的混合
- Swift2.x 中类的计算属性set方法不能访问自身值
- swift2.x不能使用函数重载的问题
- Swift 2.0 自定义cell和不同风格的cell
- Swift - 让程序挂起后,能在后台继续运行任务
- Swift - 委托(delegate)的介绍,及使用样例
- Swift - 闭包的介绍及用法
- IOS开发系列之Swift_UI_TextFIeld
- Swift - 产生不重复数字的随机数生成器
- Swift - 给图片添加文字水印(图片上写文字,并可设置位置和样式)
- Swift - 使用CGBlendMode改变UIImage颜色
- Swift - final关键字的介绍,以及使用场景
- Swift 学习之二十一:?和 !(详解)
- Swift - 实现单例模式
- Swift - 正则表达式的几种使用方式
- Swift - UISearchController初步学习
- Swift - 设置应用程序图标的提醒个数(右上角小红圈)
- Swift - iOS应用的国际化与本地化
- Swift - 实现发送邮件功能