使用XcodeColors 来显示XCGLogger,进行swift 的logger定制

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

XCGLogger中定义log显示内容的颜色

  1. 在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:.
    }


}
  1. 在其他的类中引用这个log进行输出
var appDelegate=AppDelegate()
appDelegate.log.debug("摄像头界面初始化完成!")

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...