0001    //
0002    //  BaseDestination.swift
0003    //  SwiftyBeaver
0004    //
0005    //  Created by Sebastian Kreutzberger (Twitter @skreutzb) on 05.12.15.
0006    //  Copyright © 2015 Sebastian Kreutzberger
0007    //  Some rights reserved: http://opensource.org/licenses/MIT
0008    //
0009    
0010    import Foundation
0011    
0012    struct MinLevelFilter
BaseDestination.swift:34
    var minLevelFilters = [MinLevelFilter]()
BaseDestination.swift:66
        let filter = MinLevelFilter(minLevel: minLevel, path: path, function: function)
{ 0013 var minLevel
BaseDestination.swift:158
            if filter.minLevel.rawValue <= level.rawValue {
= SwiftyBeaver.Level.Verbose 0014 var path
BaseDestination.swift:159
                if filter.path == "" || path == filter.path || path.rangeOfString(filter.path) != nil {
BaseDestination.swift:159
                if filter.path == "" || path == filter.path || path.rangeOfString(filter.path) != nil {
BaseDestination.swift:159
                if filter.path == "" || path == filter.path || path.rangeOfString(filter.path) != nil {
= "" 0015 var function
BaseDestination.swift:160
                    if filter.function == "" || function == filter.function || function.rangeOfString(filter.function) != nil {
BaseDestination.swift:160
                    if filter.function == "" || function == filter.function || function.rangeOfString(filter.function) != nil {
BaseDestination.swift:160
                    if filter.function == "" || function == filter.function || function.rangeOfString(filter.function) != nil {
= "" 0016 } 0017 0018 public class BaseDestination
BaseDestination.swift:170
public func == (lhs: BaseDestination, rhs: BaseDestination) -> Bool {
BaseDestination.swift:170
public func == (lhs: BaseDestination, rhs: BaseDestination) -> Bool {
ConsoleDestination.swift:12
public class ConsoleDestination: BaseDestination {
FileDestination.swift:12
public class FileDestination: BaseDestination {
SwiftyBeaver.swift:23
    static var destinations = Set<BaseDestination>() //[BaseDestination]()
SwiftyBeaver.swift:30
		guard let dest = destination as? BaseDestination else {
SwiftyBeaver.swift:43
		guard let dest = destination as? BaseDestination else {
: Hashable, Equatable { 0019 0020 public var detailOutput
BaseDestination.swift:80
            function: function, line: line, detailOutput: detailOutput)
= true 0021 public var colored
BaseDestination.swift:121
        if colored {
= true 0022 public var minLevel
BaseDestination.swift:152
        if minLevel.rawValue <= level.rawValue {
= SwiftyBeaver.Level.Verbose 0023 public var dateFormat
BaseDestination.swift:78
        dateStr = formattedDate(dateFormat)
= "yyyy-MM-dd HH:mm:ss.SSS" 0024 public var levelString
BaseDestination.swift:101
            levelStr = levelString.Debug
BaseDestination.swift:105
            levelStr = levelString.Info
BaseDestination.swift:109
            levelStr = levelString.Warning
BaseDestination.swift:113
            levelStr = levelString.Error
BaseDestination.swift:118
            levelStr = levelString.Verbose
= LevelString() 0025 0026 public struct LevelString
BaseDestination.swift:24
    public var levelString = LevelString()
{ 0027 public var Verbose
BaseDestination.swift:118
            levelStr = levelString.Verbose
= "VERBOSE" 0028 public var Debug
BaseDestination.swift:101
            levelStr = levelString.Debug
= "DEBUG" 0029 public var Info
BaseDestination.swift:105
            levelStr = levelString.Info
= "INFO" 0030 public var Warning
BaseDestination.swift:109
            levelStr = levelString.Warning
= "WARNING" 0031 public var Error
BaseDestination.swift:113
            levelStr = levelString.Error
= "ERROR" 0032 } 0033 0034 var minLevelFilters
BaseDestination.swift:67
        minLevelFilters.append(filter)
BaseDestination.swift:156
        for filter in minLevelFilters {
= [MinLevelFilter]() 0035 let formatter
BaseDestination.swift:87
        formatter.dateFormat = dateFormat
BaseDestination.swift:88
        let dateStr = formatter.stringFromDate(NSDate())
= NSDateFormatter() 0036 0037 // For a colored log level word in a logged line 0038 // XCode RGB colors 0039 var blue
BaseDestination.swift:100
            color = blue
FileDestination.swift:30
        blue = "0;34m"  // replace first 0 with 1 to make it bold
= "fg0,0,255;" 0040 var green
BaseDestination.swift:104
            color = green
FileDestination.swift:31
        green = "0;32m"
= "fg0,255,0;" 0041 var yellow
BaseDestination.swift:108
            color = yellow
FileDestination.swift:32
        yellow = "0;33m"
= "fg255,255,0;" 0042 var red
BaseDestination.swift:112
            color = red
FileDestination.swift:33
        red = "0;31m"
= "fg255,0,0;" 0043 var magenta
FileDestination.swift:34
        magenta = "0;35m"
= "fg255,0,255;" 0044 var cyan
FileDestination.swift:35
        cyan = "0;36m"
= "fg0,255,255;" 0045 var silver
BaseDestination.swift:117
            color = silver
FileDestination.swift:36
        silver = "0;37m"
= "fg200,200,200;" 0046 var reset
BaseDestination.swift:122
            levelStr = escape + color + levelStr + reset
FileDestination.swift:37
        reset = "\u{001b}[0m"
= "\u{001b}[;" 0047 var escape
BaseDestination.swift:122
            levelStr = escape + color + levelStr + reset
= "\u{001b}[" 0048 0049 0050 // each destination class must have an own hashValue Int 0051 lazy public var hashValue: Int = self.defaultHashValue 0052 public var defaultHashValue
BaseDestination.swift:51
    lazy public var hashValue: Int = self.defaultHashValue
: Int {return 0} 0053 0054 // each destination instance must have an own serial queue to ensure serial output 0055 // GCD gives it a prioritization between User Initiated and Utility 0056 var queue
BaseDestination.swift:61
        queue = dispatch_queue_create(queueLabel, nil)
SwiftyBeaver.swift:102
            if let queue = dest.queue {
SwiftyBeaver.swift:103
                if dest.shouldLevelBeLogged(level, path: path, function: function) && dest.queue != nil {
SwiftyBeaver.swift:125
      if let queue = dest.queue {
: dispatch_queue_t? 0057 0058 public init
ConsoleDestination.swift:17
        super.init()
FileDestination.swift:26
        super.init()
() { 0059 let uuid = NSUUID().UUIDString 0060 let queueLabel = "swiftybeaver-queue-" + uuid 0061 queue = dispatch_queue_create(queueLabel, nil) 0062 } 0063 0064 /// overrule the destination’s minLevel for a given path and optional function 0065 public func addMinLevelFilter(minLevel: SwiftyBeaver.Level, path: String, function:String = "") { 0066 let filter = MinLevelFilter(minLevel: minLevel, path: path, function: function) 0067 minLevelFilters.append(filter) 0068 } 0069 0070 /// send / store the formatted log message to the destination 0071 /// returns the formatted log message for processing by inheriting method 0072 /// and for unit tests (nil if error) 0073 public func send
ConsoleDestination.swift:22
        let formattedString = super.send(level, msg: msg, thread: thread, path: path, function: function, line: line)
FileDestination.swift:42
        let formattedString = super.send(level, msg: msg, thread: thread, path: path, function: function, line: line)
SwiftyBeaver.swift:108
                            dest.send(level, msg: msgStr, thread: thread, path: path, function: function, line: line)
(level: SwiftyBeaver.Level, msg: String, thread: String, path: String, function: String, line: Int) -> String? { 0074 var dateStr = "" 0075 var str = "" 0076 let levelStr = formattedLevel(level) 0077 0078 dateStr = formattedDate(dateFormat) 0079 str = formattedMessage(dateStr, levelString: levelStr, msg: msg, thread: thread, path: path, 0080 function: function, line: line, detailOutput: detailOutput) 0081 return str 0082 } 0083 0084 /// returns a formatted date string 0085 func formattedDate
BaseDestination.swift:78
        dateStr = formattedDate(dateFormat)
(dateFormat: String) -> String { 0086 //formatter.timeZone = NSTimeZone(abbreviation: "UTC") 0087 formatter.dateFormat = dateFormat 0088 let dateStr = formatter.stringFromDate(NSDate()) 0089 return dateStr 0090 } 0091 0092 /// returns an optionally colored level noun (like INFO, etc.) 0093 func formattedLevel
BaseDestination.swift:76
        let levelStr = formattedLevel(level)
(level: SwiftyBeaver.Level) -> String { 0094 // optionally wrap the level string in color 0095 var color = "" 0096 var levelStr = "" 0097 0098 switch level { 0099 case SwiftyBeaver.Level.Debug: 0100 color = blue 0101 levelStr = levelString.Debug 0102 0103 case SwiftyBeaver.Level.Info: 0104 color = green 0105 levelStr = levelString.Info 0106 0107 case SwiftyBeaver.Level.Warning: 0108 color = yellow 0109 levelStr = levelString.Warning 0110 0111 case SwiftyBeaver.Level.Error: 0112 color = red 0113 levelStr = levelString.Error 0114 0115 default: 0116 // Verbose is default 0117 color = silver 0118 levelStr = levelString.Verbose 0119 } 0120 0121 if colored { 0122 levelStr = escape + color + levelStr + reset 0123 } 0124 return levelStr 0125 } 0126 0127 /// returns the formatted log message 0128 func formattedMessage
BaseDestination.swift:79
        str = formattedMessage(dateStr, levelString: levelStr, msg: msg, thread: thread, path: path,
(dateString: String, levelString: String, msg: String, 0129 thread: String, path: String, function: String, line: Int, detailOutput: Bool) -> String { 0130 // just use the file name of the path and remove suffix 0131 let file = path.componentsSeparatedByString("/").last!.componentsSeparatedByString(".").first! 0132 var str = "" 0133 if dateString != "" { 0134 str += "[\(dateString)] " 0135 } 0136 if detailOutput { 0137 if thread != "main" && thread != "" { 0138 str += "|\(thread)| " 0139 } 0140 0141 str += "\(file).\(function):\(line) \(levelString): \(msg)" 0142 } else { 0143 str += "\(levelString): \(msg)" 0144 } 0145 return str 0146 } 0147 0148 /// checks if level is at least minLevel or if a minLevel filter for that path does exist 0149 /// returns boolean and can be used to decide if a message should be logged or not 0150 func shouldLevelBeLogged
SwiftyBeaver.swift:103
                if dest.shouldLevelBeLogged(level, path: path, function: function) && dest.queue != nil {
(level: SwiftyBeaver.Level, path: String, function: String) -> Bool { 0151 // at first check the instance’s global minLevel property 0152 if minLevel.rawValue <= level.rawValue { 0153 return true 0154 } 0155 // now go through all minLevelFilters and see if there is a match 0156 for filter in minLevelFilters { 0157 // rangeOfString returns nil if both values are the same! 0158 if filter.minLevel.rawValue <= level.rawValue { 0159 if filter.path == "" || path == filter.path || path.rangeOfString(filter.path) != nil { 0160 if filter.function == "" || function == filter.function || function.rangeOfString(filter.function) != nil { 0161 return true 0162 } 0163 } 0164 } 0165 } 0166 return false 0167 } 0168 } 0169 0170 public func == (lhs: BaseDestination, rhs: BaseDestination) -> Bool { 0171 return ObjectIdentifier(lhs) == ObjectIdentifier(rhs) 0172 } 0173 0174