From 3031fb158df7834beb6cf9c4e6741300cb75bb14 Mon Sep 17 00:00:00 2001 From: David Jones Date: Fri, 25 Nov 2016 11:16:48 +0000 Subject: [PATCH 1/3] Use autoclosures to prevent String construction ...until we know a log message will be emitted --- Sources/LoggerAPI/Logger.swift | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Sources/LoggerAPI/Logger.swift b/Sources/LoggerAPI/Logger.swift index d96eb4c..548089c 100644 --- a/Sources/LoggerAPI/Logger.swift +++ b/Sources/LoggerAPI/Logger.swift @@ -103,10 +103,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public static func verbose(_ msg: String, functionName: String = #function, + public static func verbose(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file ) { if let logger = logger, logger.isLogging(.verbose) { - logger.log( .verbose, msg: msg, + logger.log( .verbose, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -123,10 +123,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func info(_ msg: String, functionName: String = #function, + public class func info(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.info) { - logger.log( .info, msg: msg, + logger.log( .info, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -143,10 +143,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func warning(_ msg: String, functionName: String = #function, + public class func warning(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.warning) { - logger.log( .warning, msg: msg, + logger.log( .warning, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -163,10 +163,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func error(_ msg: String, functionName: String = #function, + public class func error(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.error) { - logger.log( .error, msg: msg, + logger.log( .error, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -183,10 +183,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func debug(_ msg: String, functionName: String = #function, + public class func debug(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.debug) { - logger.log( .debug, msg: msg, + logger.log( .debug, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -203,10 +203,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func entry(_ msg: String, functionName: String = #function, + public class func entry(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.entry) { - logger.log(.entry, msg: msg, + logger.log(.entry, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -223,10 +223,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func exit(_ msg: String, functionName: String = #function, + public class func exit(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.exit) { - logger.log(.exit, msg: msg, + logger.log(.exit, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } From 7a2cb4fdd7df7eb9c2f8a967c07f2d6c2fb4c9c4 Mon Sep 17 00:00:00 2001 From: Shmuel Kallner Date: Fri, 16 Dec 2016 09:26:41 +0200 Subject: [PATCH 2/3] Support Swift 3.0.2 --- .swift-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.swift-version b/.swift-version index cb2b00e..b502146 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0.1 +3.0.2 From 953fd0cc46c58a01181ff0e3e4eeb0a7ab61c2a2 Mon Sep 17 00:00:00 2001 From: David Jones Date: Fri, 25 Nov 2016 11:16:48 +0000 Subject: [PATCH 3/3] Use autoclosures to prevent String construction ...until we know a log message will be emitted --- Sources/LoggerAPI/Logger.swift | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Sources/LoggerAPI/Logger.swift b/Sources/LoggerAPI/Logger.swift index d96eb4c..548089c 100644 --- a/Sources/LoggerAPI/Logger.swift +++ b/Sources/LoggerAPI/Logger.swift @@ -103,10 +103,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public static func verbose(_ msg: String, functionName: String = #function, + public static func verbose(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file ) { if let logger = logger, logger.isLogging(.verbose) { - logger.log( .verbose, msg: msg, + logger.log( .verbose, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -123,10 +123,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func info(_ msg: String, functionName: String = #function, + public class func info(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.info) { - logger.log( .info, msg: msg, + logger.log( .info, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -143,10 +143,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func warning(_ msg: String, functionName: String = #function, + public class func warning(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.warning) { - logger.log( .warning, msg: msg, + logger.log( .warning, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -163,10 +163,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func error(_ msg: String, functionName: String = #function, + public class func error(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.error) { - logger.log( .error, msg: msg, + logger.log( .error, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -183,10 +183,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func debug(_ msg: String, functionName: String = #function, + public class func debug(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.debug) { - logger.log( .debug, msg: msg, + logger.log( .debug, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -203,10 +203,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func entry(_ msg: String, functionName: String = #function, + public class func entry(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.entry) { - logger.log(.entry, msg: msg, + logger.log(.entry, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } } @@ -223,10 +223,10 @@ public class Log { /// - Parameter fileName: The file of the source code of the function invoking the /// logger API. Defaults to the file of the actual function /// invoking this function. - public class func exit(_ msg: String, functionName: String = #function, + public class func exit(_ msg: @autoclosure () -> String, functionName: String = #function, lineNum: Int = #line, fileName: String = #file) { if let logger = logger, logger.isLogging(.exit) { - logger.log(.exit, msg: msg, + logger.log(.exit, msg: msg(), functionName: functionName, lineNum: lineNum, fileName: fileName) } }