使用XcodeColors 来显示XCGLogger,进行swift 的logger定制
XcodeColors项目地址 XcodeColors installation instructions for Xcode 4,5,6 & 7: Download or clone the repository. $ ./update_compat.sh XCGLogger中定义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("2222222222",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:.
}
}
var appDelegate=AppDelegate()
appDelegate.log.debug("摄像头界面初始化完成!")
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |