|
// Updated to Swift 1.2 and CocoaLumberjack 2.0.0-rc by Stan Serebryakov on 2015-02-16 |
|
|
|
import Foundation |
|
|
|
extension DDLog { |
|
|
|
private struct State { |
|
static var logLevel: DDLogLevel = .Error |
|
static var logAsync: Bool = true |
|
} |
|
|
|
class var logLevel: DDLogLevel { |
|
get { return State.logLevel } |
|
set { State.logLevel = newValue } |
|
} |
|
|
|
class var logAsync: Bool { |
|
get { return (self.logLevel != .Error) && State.logAsync } |
|
set { State.logAsync = newValue } |
|
} |
|
|
|
class func log(flag: DDLogFlag, @autoclosure message: () -> String, |
|
function: String = __FUNCTION__, file: String = __FILE__, line: UInt = __LINE__) { |
|
if flag.rawValue & logLevel.rawValue != 0 { |
|
var logMsg = DDLogMessage(message: message(), level: logLevel, flag: flag, context: 0, |
|
file: file, function: function, line: line, |
|
tag: nil, options: DDLogMessageOptions(0), timestamp: nil) |
|
DDLog.log(logAsync, message: logMsg) |
|
} |
|
} |
|
} |
|
|
|
func logError(@autoclosure message: () -> String, function: String = __FUNCTION__, |
|
file: String = __FILE__, line: UInt = __LINE__) { |
|
DDLog.log(.Error, message: message, function: function, file: file, line: line) |
|
} |
|
|
|
func logWarn(@autoclosure message: () -> String, function: String = __FUNCTION__, |
|
file: String = __FILE__, line: UInt = __LINE__) { |
|
DDLog.log(.Warning, message: message, function: function, file: file, line: line) |
|
} |
|
|
|
func logInfo(@autoclosure message: () -> String, function: String = __FUNCTION__, |
|
file: String = __FILE__, line: UInt = __LINE__) { |
|
DDLog.log(.Info, message: message, function: function, file: file, line: line) |
|
} |
|
|
|
func logDebug(@autoclosure message: () -> String, function: String = __FUNCTION__, |
|
file: String = __FILE__, line: UInt = __LINE__) { |
|
DDLog.log(.Debug, message: message, function: function, file: file, line: line) |
|
} |
|
|
|
func logVerbose(@autoclosure message: () -> String, function: String = __FUNCTION__, |
|
file: String = __FILE__, line: UInt = __LINE__) { |
|
DDLog.log(.Verbose, message: message, function: function, file: file, line: line) |
|
} |
Cool stuff! Unfortunately, for some reason, I'm getting the following error on line 23 after I remove the timestamp parameter (for some reason it doesn't recognize that method signature). I'm using beta3. Any ideas?
Cannot invoke 'init' with an argument list of type '(logMsg: @autoclosure () -> String, level: @lvalue DDLogLevel, flag: DDLogFlag, context: IntegerLiteralConvertible, file: String, function: String, line: UInt, tag: NilLiteralConvertible, options: $T10)'