0001    //
0002    //  SwiftyBeaver.swift
0003    //  SwiftyBeaver
0004    //
0005    //  Created by Sebastian Kreutzberger (Twitter @skreutzb) on 28.11.15.
0006    //  Copyright © 2015 Sebastian Kreutzberger
0007    //  Some rights reserved: http://opensource.org/licenses/MIT
0008    //
0009    
0010    import Foundation
0011    
0012    public class SwiftyBeaver
BaseDestination.swift:13
    var minLevel = SwiftyBeaver.Level.Verbose
BaseDestination.swift:22
    public var minLevel = SwiftyBeaver.Level.Verbose
BaseDestination.swift:65
    public func addMinLevelFilter(minLevel: SwiftyBeaver.Level, path: String, function:String = "") {
BaseDestination.swift:73
    public func send(level: SwiftyBeaver.Level, msg: String, thread: String, path: String, function: String, line: Int) -> String? {
BaseDestination.swift:93
    func formattedLevel(level: SwiftyBeaver.Level) -> String {
BaseDestination.swift:150
    func shouldLevelBeLogged(level: SwiftyBeaver.Level, path: String, function: String) -> Bool {
ConsoleDestination.swift:21
    override public func send(level: SwiftyBeaver.Level, msg: String, thread: String, path: String, function: String, line: Int) -> String? {
FileDestination.swift:41
    override public func send(level: SwiftyBeaver.Level, msg: String, thread: String, path: String, function: String, line: Int) -> String? {
SwiftyBeaver.swift:100
    class func dispatch_send(level: SwiftyBeaver.Level, msg: Any, thread: String, path: String, function: String, line: Int) {
{ 0013 0014 public enum Level
BaseDestination.swift:13
    var minLevel = SwiftyBeaver.Level.Verbose
BaseDestination.swift:22
    public var minLevel = SwiftyBeaver.Level.Verbose
BaseDestination.swift:65
    public func addMinLevelFilter(minLevel: SwiftyBeaver.Level, path: String, function:String = "") {
BaseDestination.swift:73
    public func send(level: SwiftyBeaver.Level, msg: String, thread: String, path: String, function: String, line: Int) -> String? {
BaseDestination.swift:93
    func formattedLevel(level: SwiftyBeaver.Level) -> String {
BaseDestination.swift:150
    func shouldLevelBeLogged(level: SwiftyBeaver.Level, path: String, function: String) -> Bool {
ConsoleDestination.swift:21
    override public func send(level: SwiftyBeaver.Level, msg: String, thread: String, path: String, function: String, line: Int) -> String? {
FileDestination.swift:41
    override public func send(level: SwiftyBeaver.Level, msg: String, thread: String, path: String, function: String, line: Int) -> String? {
SwiftyBeaver.swift:80
        dispatch_send(Level.Verbose, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:84
        dispatch_send(Level.Debug, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:88
        dispatch_send(Level.Info, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:92
        dispatch_send(Level.Warning, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:96
        dispatch_send(Level.Error, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:100
    class func dispatch_send(level: SwiftyBeaver.Level, msg: Any, thread: String, path: String, function: String, line: Int) {
: Int { 0015 case Verbose
BaseDestination.swift:13
    var minLevel = SwiftyBeaver.Level.Verbose
BaseDestination.swift:22
    public var minLevel = SwiftyBeaver.Level.Verbose
SwiftyBeaver.swift:80
        dispatch_send(Level.Verbose, msg: msg, thread: threadName(), path: path, function: function, line: line)
= 0 0016 case Debug
BaseDestination.swift:99
        case SwiftyBeaver.Level.Debug:
SwiftyBeaver.swift:84
        dispatch_send(Level.Debug, msg: msg, thread: threadName(), path: path, function: function, line: line)
= 1 0017 case Info
BaseDestination.swift:103
        case SwiftyBeaver.Level.Info:
SwiftyBeaver.swift:88
        dispatch_send(Level.Info, msg: msg, thread: threadName(), path: path, function: function, line: line)
= 2 0018 case Warning
BaseDestination.swift:107
        case SwiftyBeaver.Level.Warning:
SwiftyBeaver.swift:92
        dispatch_send(Level.Warning, msg: msg, thread: threadName(), path: path, function: function, line: line)
= 3 0019 case Error
BaseDestination.swift:111
        case SwiftyBeaver.Level.Error:
SwiftyBeaver.swift:96
        dispatch_send(Level.Error, msg: msg, thread: threadName(), path: path, function: function, line: line)
= 4 0020 } 0021 0022 // a set of active destinations 0023 static var destinations
SwiftyBeaver.swift:36
		destinations.insert(dest)  // if not already in (it’s a set)
SwiftyBeaver.swift:48
		destinations.remove(dest)
SwiftyBeaver.swift:55
        destinations.removeAll()
SwiftyBeaver.swift:60
        return destinations.count
SwiftyBeaver.swift:101
        for dest in destinations {
SwiftyBeaver.swift:124
    for dest in destinations {
= Set<BaseDestination>() //[BaseDestination]() 0024 0025 0026 // MARK: Destination Handling 0027 0028 /// returns boolean about success 0029 public class func addDestination(destination: AnyObject) -> Bool { 0030 guard let dest = destination as? BaseDestination else { 0031 print("SwiftyBeaver: adding of destination failed") 0032 return false 0033 } 0034 0035 //print("insert hashValue \(dest.hashValue)") 0036 destinations.insert(dest) // if not already in (it’s a set) 0037 return true 0038 0039 } 0040 0041 /// returns boolean about success 0042 public class func removeDestination(destination: AnyObject) -> Bool { 0043 guard let dest = destination as? BaseDestination else { 0044 print("SwiftyBeaver: removing of destination failed") 0045 return false 0046 } 0047 0048 destinations.remove(dest) 0049 return true 0050 0051 } 0052 0053 /// if you need to start fresh 0054 public class func removeAllDestinations() { 0055 destinations.removeAll() 0056 } 0057 0058 /// returns the amount of destinations 0059 public class func countDestinations() -> Int { 0060 return destinations.count 0061 } 0062 0063 class func threadName
SwiftyBeaver.swift:80
        dispatch_send(Level.Verbose, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:84
        dispatch_send(Level.Debug, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:88
        dispatch_send(Level.Info, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:92
        dispatch_send(Level.Warning, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:96
        dispatch_send(Level.Error, msg: msg, thread: threadName(), path: path, function: function, line: line)
() -> String { 0064 if NSThread.isMainThread() { 0065 return "main" 0066 } else { 0067 if let threadName = NSThread.currentThread().name where !threadName.isEmpty { 0068 return threadName 0069 } else if let queueName = String(UTF8String: dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)) where !queueName.isEmpty { 0070 return queueName 0071 } else { 0072 return String(format: "%p", NSThread.currentThread()) 0073 } 0074 } 0075 } 0076 0077 // MARK: Levels 0078 0079 public class func verbose(msg: Any, _ path: String = __FILE__, _ function: String = __FUNCTION__, line: Int = __LINE__) { 0080 dispatch_send(Level.Verbose, msg: msg, thread: threadName(), path: path, function: function, line: line) 0081 } 0082 0083 public class func debug(msg: Any, _ path: String = __FILE__, _ function: String = __FUNCTION__, line: Int = __LINE__) { 0084 dispatch_send(Level.Debug, msg: msg, thread: threadName(), path: path, function: function, line: line) 0085 } 0086 0087 public class func info(msg: Any, _ path: String = __FILE__, _ function: String = __FUNCTION__, line: Int = __LINE__) { 0088 dispatch_send(Level.Info, msg: msg, thread: threadName(), path: path, function: function, line: line) 0089 } 0090 0091 public class func warning(msg: Any, _ path: String = __FILE__, _ function: String = __FUNCTION__, line: Int = __LINE__) { 0092 dispatch_send(Level.Warning, msg: msg, thread: threadName(), path: path, function: function, line: line) 0093 } 0094 0095 public class func error(msg: Any, _ path: String = __FILE__, _ function: String = __FUNCTION__, line: Int = __LINE__) { 0096 dispatch_send(Level.Error, msg: msg, thread: threadName(), path: path, function: function, line: line) 0097 } 0098 0099 /// internal helper which dispatches send to dedicated queue if minLevel is ok 0100 class func dispatch_send
SwiftyBeaver.swift:80
        dispatch_send(Level.Verbose, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:84
        dispatch_send(Level.Debug, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:88
        dispatch_send(Level.Info, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:92
        dispatch_send(Level.Warning, msg: msg, thread: threadName(), path: path, function: function, line: line)
SwiftyBeaver.swift:96
        dispatch_send(Level.Error, msg: msg, thread: threadName(), path: path, function: function, line: line)
(level: SwiftyBeaver.Level, msg: Any, thread: String, path: String, function: String, line: Int) { 0101 for dest in destinations { 0102 if let queue = dest.queue { 0103 if dest.shouldLevelBeLogged(level, path: path, function: function) && dest.queue != nil { 0104 // try to convert msg object to String and put it on queue 0105 let msgStr = "\(msg)" 0106 if msgStr.characters.count > 0 { 0107 dispatch_async(queue, { 0108 dest.send(level, msg: msgStr, thread: thread, path: path, function: function, line: line) 0109 }) 0110 } 0111 } 0112 } 0113 } 0114 } 0115 0116 /** 0117 Flush all destinations to make sure all logging messages have been written out 0118 Returns after all messages flushed or timeout seconds 0119 0120 - returns: true if all messages flushed, false if timeout occurred 0121 */ 0122 public class func flush(secondTimeout: Int64) -> Bool { 0123 let grp = dispatch_group_create(); 0124 for dest in destinations { 0125 if let queue = dest.queue { 0126 dispatch_group_enter(grp) 0127 dispatch_async(queue, { 0128 dispatch_group_leave(grp) 0129 }) 0130 } 0131 } 0132 let waitUntil = dispatch_time(DISPATCH_TIME_NOW, secondTimeout * 1000000000) 0133 return dispatch_group_wait(grp, waitUntil) == 0 0134 } 0135 } 0136