diff --git a/SlimLogger/SlimLogger.swift b/SlimLogger/SlimLogger.swift index 83eca39..290602b 100644 --- a/SlimLogger/SlimLogger.swift +++ b/SlimLogger/SlimLogger.swift @@ -59,34 +59,34 @@ open class Slim { } open class func trace( _ message: @autoclosure () -> T, filename: String = #file, line: Int = #line) { - slim.logInternal(message, level: LogLevel.trace, filename: filename, line: line) + slim.logInternal(message(), level: LogLevel.trace, filename: filename, line: line) } open class func debug( _ message: @autoclosure () -> T, filename: String = #file, line: Int = #line) { - slim.logInternal(message, level: LogLevel.debug, filename: filename, line: line) + slim.logInternal(message(), level: LogLevel.debug, filename: filename, line: line) } open class func info( _ message: @autoclosure () -> T, filename: String = #file, line: Int = #line) { - slim.logInternal(message, level: LogLevel.info, filename: filename, line: line) + slim.logInternal(message(), level: LogLevel.info, filename: filename, line: line) } open class func warn( _ message: @autoclosure () -> T, filename: String = #file, line: Int = #line) { - slim.logInternal(message, level: LogLevel.warn, filename: filename, line: line) + slim.logInternal(message(), level: LogLevel.warn, filename: filename, line: line) } open class func error( _ message: @autoclosure () -> T, filename: String = #file, line: Int = #line) { - slim.logInternal(message, level: LogLevel.error, filename: filename, line: line) + slim.logInternal(message(), level: LogLevel.error, filename: filename, line: line) } open class func fatal( _ message: @autoclosure () -> T, filename: String = #file, line: Int = #line) { - slim.logInternal(message, level: LogLevel.fatal, filename: filename, line: line) + slim.logInternal(message(), level: LogLevel.fatal, filename: filename, line: line) } fileprivate func logInternal( _ message: @autoclosure () -> T, level: LogLevel, filename: String, line: Int) { let cleanedfile = cleanedFilename(filename) if isSourceFileEnabled(cleanedfile) { for dest in logDestinations { - dest.log(message, level: level, filename: cleanedfile, line: line) + dest.log(message(), level: level, filename: cleanedfile, line: line) } } } diff --git a/SlimLogger/SlimLogglyDestination.swift b/SlimLogger/SlimLogglyDestination.swift index b22d293..e0bc54e 100644 --- a/SlimLogger/SlimLogglyDestination.swift +++ b/SlimLogger/SlimLogglyDestination.swift @@ -13,7 +13,7 @@ class SlimLogglyDestination: LogDestination { var userid: String? fileprivate let dateFormatter = DateFormatter() fileprivate var buffer: [String] = [] - fileprivate var backgroundTaskIdentifier: UIBackgroundTaskIdentifier = UIBackgroundTaskInvalid + fileprivate var backgroundTaskIdentifier: UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier.invalid fileprivate lazy var standardFields: [String: String] = { var dict: [String: String] = [:] dict["lang"] = Locale.preferredLanguages[0] @@ -138,7 +138,7 @@ class SlimLogglyDestination: LogDestination { } else { self.traceMessage(msg: "Neither error nor responsedata, something's wrong") } - if self.backgroundTaskIdentifier != UIBackgroundTaskInvalid { + if self.backgroundTaskIdentifier != UIBackgroundTaskIdentifier.invalid { self.endBackgroundTask() } }) @@ -147,9 +147,9 @@ class SlimLogglyDestination: LogDestination { } private func endBackgroundTask() { - if self.backgroundTaskIdentifier != UIBackgroundTaskInvalid { - UIApplication.shared.endBackgroundTask(self.backgroundTaskIdentifier) - self.backgroundTaskIdentifier = UIBackgroundTaskInvalid + if self.backgroundTaskIdentifier != UIBackgroundTaskIdentifier.invalid { + UIApplication.shared.endBackgroundTask(convertToUIBackgroundTaskIdentifier(self.backgroundTaskIdentifier.rawValue)) + self.backgroundTaskIdentifier = UIBackgroundTaskIdentifier.invalid print("Ending background task") } } @@ -160,3 +160,8 @@ class SlimLogglyDestination: LogDestination { } } } + +// Helper function inserted by Swift 4.2 migrator. +fileprivate func convertToUIBackgroundTaskIdentifier(_ input: Int) -> UIBackgroundTaskIdentifier { + return UIBackgroundTaskIdentifier(rawValue: input) +} diff --git a/SlimLoggerExampleProject/SlimLoggerExampleProject.xcodeproj/project.pbxproj b/SlimLoggerExampleProject/SlimLoggerExampleProject.xcodeproj/project.pbxproj index 367be41..eeadd6d 100644 --- a/SlimLoggerExampleProject/SlimLoggerExampleProject.xcodeproj/project.pbxproj +++ b/SlimLoggerExampleProject/SlimLoggerExampleProject.xcodeproj/project.pbxproj @@ -194,11 +194,11 @@ TargetAttributes = { E51237901B2239DB002EABDC = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0810; + LastSwiftMigration = 1020; }; E51237A51B2239DB002EABDC = { CreatedOnToolsVersion = 6.3.1; - LastSwiftMigration = 0810; + LastSwiftMigration = 1020; TestTargetID = E51237901B2239DB002EABDC; }; }; @@ -208,6 +208,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -406,7 +407,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "se.baresi.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -419,7 +420,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "se.baresi.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -439,7 +440,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "se.baresi.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SlimLoggerExampleProject.app/SlimLoggerExampleProject"; }; name = Debug; @@ -456,7 +457,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "se.baresi.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SlimLoggerExampleProject.app/SlimLoggerExampleProject"; }; name = Release; diff --git a/SlimLoggerExampleProject/SlimLoggerExampleProject/AppDelegate.swift b/SlimLoggerExampleProject/SlimLoggerExampleProject/AppDelegate.swift index 60f323f..d1d0e67 100644 --- a/SlimLoggerExampleProject/SlimLoggerExampleProject/AppDelegate.swift +++ b/SlimLoggerExampleProject/SlimLoggerExampleProject/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let logglyDestination = SlimLogglyDestination() logglyDestination.userid = "johndoe"