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{ 0013 var minLevel
BaseDestination.swift:34 var minLevelFilters = [MinLevelFilter]()BaseDestination.swift:66 let filter = MinLevelFilter(minLevel: minLevel, path: path, function: function)= SwiftyBeaver.Level.Verbose 0014 var path
BaseDestination.swift:158 if filter.minLevel.rawValue <= level.rawValue {= "" 0015 var function
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 {= "" 0016 } 0017 0018 public class BaseDestination
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 {: Hashable, Equatable { 0019 0020 public var detailOutput
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 {= true 0021 public var colored
BaseDestination.swift:80 function: function, line: line, detailOutput: detailOutput)= true 0022 public var minLevel
BaseDestination.swift:121 if colored {= SwiftyBeaver.Level.Verbose 0023 public var dateFormat
BaseDestination.swift:152 if minLevel.rawValue <= level.rawValue {= "yyyy-MM-dd HH:mm:ss.SSS" 0024 public var levelString
BaseDestination.swift:78 dateStr = formattedDate(dateFormat)= LevelString() 0025 0026 public struct LevelString
BaseDestination.swift:101 levelStr = levelString.DebugBaseDestination.swift:105 levelStr = levelString.InfoBaseDestination.swift:109 levelStr = levelString.WarningBaseDestination.swift:113 levelStr = levelString.ErrorBaseDestination.swift:118 levelStr = levelString.Verbose{ 0027 public var Verbose
BaseDestination.swift:24 public var levelString = LevelString()= "VERBOSE" 0028 public var Debug
BaseDestination.swift:118 levelStr = levelString.Verbose= "DEBUG" 0029 public var Info
BaseDestination.swift:101 levelStr = levelString.Debug= "INFO" 0030 public var Warning
BaseDestination.swift:105 levelStr = levelString.Info= "WARNING" 0031 public var Error
BaseDestination.swift:109 levelStr = levelString.Warning= "ERROR" 0032 } 0033 0034 var minLevelFilters
BaseDestination.swift:113 levelStr = levelString.Error= [MinLevelFilter]() 0035 let formatter
BaseDestination.swift:67 minLevelFilters.append(filter)BaseDestination.swift:156 for filter in minLevelFilters {= NSDateFormatter() 0036 0037 // For a colored log level word in a logged line 0038 // XCode RGB colors 0039 var blue
BaseDestination.swift:87 formatter.dateFormat = dateFormatBaseDestination.swift:88 let dateStr = formatter.stringFromDate(NSDate())= "fg0,0,255;" 0040 var green
BaseDestination.swift:100 color = blueFileDestination.swift:30 blue = "0;34m" // replace first 0 with 1 to make it bold= "fg0,255,0;" 0041 var yellow
BaseDestination.swift:104 color = greenFileDestination.swift:31 green = "0;32m"= "fg255,255,0;" 0042 var red
BaseDestination.swift:108 color = yellowFileDestination.swift:32 yellow = "0;33m"= "fg255,0,0;" 0043 var magenta
BaseDestination.swift:112 color = redFileDestination.swift:33 red = "0;31m"= "fg255,0,255;" 0044 var cyan
FileDestination.swift:34 magenta = "0;35m"= "fg0,255,255;" 0045 var silver
FileDestination.swift:35 cyan = "0;36m"= "fg200,200,200;" 0046 var reset
BaseDestination.swift:117 color = silverFileDestination.swift:36 silver = "0;37m"= "\u{001b}[;" 0047 var escape
BaseDestination.swift:122 levelStr = escape + color + levelStr + resetFileDestination.swift:37 reset = "\u{001b}[0m"= "\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:122 levelStr = escape + color + levelStr + reset: 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:51 lazy public var hashValue: Int = self.defaultHashValue: dispatch_queue_t? 0057 0058 public init
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 {() { 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:17 super.init()FileDestination.swift:26 super.init()(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
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)(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:78 dateStr = formattedDate(dateFormat)(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:76 let levelStr = formattedLevel(level)(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
BaseDestination.swift:79 str = formattedMessage(dateStr, levelString: levelStr, msg: msg, thread: thread, path: path,(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
SwiftyBeaver.swift:103 if dest.shouldLevelBeLogged(level, path: path, function: function) && dest.queue != nil {