matsuda
2/13/2016 - 3:16 PM

log functions for application in Swift

log functions for application in Swift

//
//  Log.swift
//  Log
//
//  Created by Kosuke Matsuda on 2016/02/13.
//  Copyright © 2016年 Kosuke Matsuda. All rights reserved.
//

import Foundation

public func Log(body: Any? = nil, function: String = #function, file: String = #file, line: Int = #line) {
    Log(body == nil ? "" : body, function: function, file: file, line: line)
}

public func Log(@autoclosure body: () -> Any, function: String = #function, file: String = #file, line: Int = #line) {
#if DEBUG
    print("[\((file as NSString).lastPathComponent):\(line)] <\(function)> \(body())")
#endif
}
import UIKit

#if DEBUG
func exceptionHandler(exception : NSException) {
    NSLog("CRASH: %@", exception);
    NSLog("Stack Trace: %@", exception.callStackSymbols);
    // Internal error reporting
}
#endif

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Build Settings > Swift Compiler - Custom Flags > Other Swift Flags : -DDEBUG
#if DEBUG
        NSSetUncaughtExceptionHandler(exceptionHandler)
#if (arch(i386) || arch(x86_64)) && os(iOS)
        {
            if let docDir = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first {
                print("Documents directory : \n[ \(docDir) ]")
            }
        }()
#endif
#endif
        return true
    }
}