From 7f2f31480e8ebbe6bd6c92173be3d918fe157026 Mon Sep 17 00:00:00 2001 From: Guilherme Rambo Date: Mon, 2 Jan 2017 12:02:44 -0200 Subject: [PATCH 1/6] Refactor: removed unnecessary Emoji enum and related method --- Lighty-iOSTests/LightyLoggerTests.swift | 8 ----- Lighty-macOSTests/LightyLoggerTests.swift | 8 ----- Sources/LightyLogger.swift | 44 ++++++----------------- 3 files changed, 10 insertions(+), 50 deletions(-) diff --git a/Lighty-iOSTests/LightyLoggerTests.swift b/Lighty-iOSTests/LightyLoggerTests.swift index 72dee5c..f74a532 100644 --- a/Lighty-iOSTests/LightyLoggerTests.swift +++ b/Lighty-iOSTests/LightyLoggerTests.swift @@ -32,14 +32,6 @@ class LightyLoggerTests: XCTestCase { XCTAssertEqual(dateFormatter.timeStyle, DateFormatter.Style.medium) } - func testGetAccessoryWithType() { - XCTAssertEqual(logger.getAccessoryWithType(messageType: .verbose), "💜") - XCTAssertEqual(logger.getAccessoryWithType(messageType: .debug), "💙") - XCTAssertEqual(logger.getAccessoryWithType(messageType: .info), "💚") - XCTAssertEqual(logger.getAccessoryWithType(messageType: .warn), "💛") - XCTAssertEqual(logger.getAccessoryWithType(messageType: .error), "❤️") - } - func testLog() { let mocklogger = MockLightyLogger() mocklogger.log(type: .error, message: "test") diff --git a/Lighty-macOSTests/LightyLoggerTests.swift b/Lighty-macOSTests/LightyLoggerTests.swift index d0a5b7f..7428c31 100644 --- a/Lighty-macOSTests/LightyLoggerTests.swift +++ b/Lighty-macOSTests/LightyLoggerTests.swift @@ -31,14 +31,6 @@ class LightyLoggerTests: XCTestCase { XCTAssertEqual(dateFormatter.dateStyle, DateFormatter.Style.short) XCTAssertEqual(dateFormatter.timeStyle, DateFormatter.Style.medium) } - - func testGetAccessoryWithType() { - XCTAssertEqual(logger.getAccessoryWithType(messageType: .verbose), "💜") - XCTAssertEqual(logger.getAccessoryWithType(messageType: .debug), "💙") - XCTAssertEqual(logger.getAccessoryWithType(messageType: .info), "💚") - XCTAssertEqual(logger.getAccessoryWithType(messageType: .warn), "💛") - XCTAssertEqual(logger.getAccessoryWithType(messageType: .error), "❤️") - } func testLog() { let mocklogger = MockLightyLogger() diff --git a/Sources/LightyLogger.swift b/Sources/LightyLogger.swift index 3402e93..c6f3363 100644 --- a/Sources/LightyLogger.swift +++ b/Sources/LightyLogger.swift @@ -37,21 +37,12 @@ import Foundation /** Message type for logging */ -public enum LightyMessageType { - case verbose - case debug - case info - case warn - case error -} - -private struct Emoji { - static let Empty = "" - static let Verbose = "💜" - static let Debug = "💙" - static let Info = "💚" - static let Warn = "💛" - static let Error = "❤️" +public enum LightyMessageType: String { + case verbose = "💜" + case debug = "💙" + case info = "💚" + case warn = "💛" + case error = "❤️" } /** @@ -85,21 +76,6 @@ public class LightyLogger { return dateFormatter } - internal func getAccessoryWithType(messageType: LightyMessageType) -> String { - switch messageType { - case .verbose: - return Emoji.Verbose - case .debug: - return Emoji.Debug - case .info: - return Emoji.Info - case .warn: - return Emoji.Warn - case .error: - return Emoji.Error - } - } - /** Main function print logs - parameter type: LightyMessageType @@ -117,8 +93,8 @@ public class LightyLogger { let fileName = file.nsstring.lastPathComponent.nsstring.deletingPathExtension let trackedString = "\(fileName).\(fileExtension):\(line) \(function)" - let emoji = getAccessoryWithType(messageType: type) - print(emoji + " " + dateFormatter.string(from: Date()) + separator + trackedString + separator + message + " " + emoji) + + print(type.rawValue + " " + dateFormatter.string(from: Date()) + separator + trackedString + separator + message + " " + type.rawValue) } /** @@ -139,8 +115,8 @@ public class LightyLogger { let fileName = file.nsstring.lastPathComponent.nsstring.deletingPathExtension let trackedString = "\(fileName).\(fileExtension):\(line) \(function)" - let emoji = getAccessoryWithType(messageType: type) - print(emoji + " " + dateFormatter.string(from: Date()) + separator + trackedString + separator + message + " " + emoji) + + print(type.rawValue + " " + dateFormatter.string(from: Date()) + separator + trackedString + separator + message + " " + type.rawValue) #endif } From eb3dee14854a37c8bebcfc124f18c1fd86815ecd Mon Sep 17 00:00:00 2001 From: Guilherme Rambo Date: Mon, 2 Jan 2017 12:03:48 -0200 Subject: [PATCH 2/6] Refactor: calling log from dlog to avoid duplicate implementation --- Sources/LightyLogger.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Sources/LightyLogger.swift b/Sources/LightyLogger.swift index c6f3363..7d3631f 100644 --- a/Sources/LightyLogger.swift +++ b/Sources/LightyLogger.swift @@ -111,12 +111,7 @@ public class LightyLogger { function: String = #function, line: Int = #line) { #if DEBUG - let fileExtension = file.nsstring.lastPathComponent.nsstring.pathExtension - let fileName = file.nsstring.lastPathComponent.nsstring.deletingPathExtension - - let trackedString = "\(fileName).\(fileExtension):\(line) \(function)" - - print(type.rawValue + " " + dateFormatter.string(from: Date()) + separator + trackedString + separator + message + " " + type.rawValue) + log(type: type, message: message) #endif } From d12c2f27ec8c8066f818ad1954daee4d224e7c30 Mon Sep 17 00:00:00 2001 From: Guilherme Rambo Date: Mon, 2 Jan 2017 12:05:25 -0200 Subject: [PATCH 3/6] Refactor: using URL instead of NSString to parse the filename and extension --- Sources/LightyLogger.swift | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Sources/LightyLogger.swift b/Sources/LightyLogger.swift index 7d3631f..d2765a7 100644 --- a/Sources/LightyLogger.swift +++ b/Sources/LightyLogger.swift @@ -89,8 +89,9 @@ public class LightyLogger { file: String = #file, function: String = #function, line: Int = #line) { - let fileExtension = file.nsstring.lastPathComponent.nsstring.pathExtension - let fileName = file.nsstring.lastPathComponent.nsstring.deletingPathExtension + let fileUrl = URL(fileURLWithPath: file) + let fileExtension = fileUrl.pathExtension + let fileName = fileUrl.deletingPathExtension().lastPathComponent let trackedString = "\(fileName).\(fileExtension):\(line) \(function)" @@ -116,9 +117,3 @@ public class LightyLogger { } } - -private extension String { - - var nsstring: NSString { return self as NSString } - -} From d3262af38c7fd25e91fd25601feea1ec2f03f2dd Mon Sep 17 00:00:00 2001 From: Guilherme Rambo Date: Mon, 2 Jan 2017 12:06:01 -0200 Subject: [PATCH 4/6] Refactor: removed unnecessary Cocoa and UIKit imports --- Sources/LightyLogger.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Sources/LightyLogger.swift b/Sources/LightyLogger.swift index d2765a7..ac2816b 100644 --- a/Sources/LightyLogger.swift +++ b/Sources/LightyLogger.swift @@ -28,11 +28,6 @@ // SOFTWARE. import Foundation -#if os(OSX) - import Cocoa -#elseif os(iOS) || os(tvOS) - import UIKit -#endif /** Message type for logging From 5b8f6b3ee8b27b8d729ea1b1c8fc035697377b0d Mon Sep 17 00:00:00 2001 From: Guilherme Rambo Date: Mon, 2 Jan 2017 18:43:19 -0200 Subject: [PATCH 5/6] Revert "Refactor: calling log from dlog to avoid duplicate implementation" This reverts commit eb3dee14854a37c8bebcfc124f18c1fd86815ecd. --- Sources/LightyLogger.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/LightyLogger.swift b/Sources/LightyLogger.swift index ac2816b..0e5d7f1 100644 --- a/Sources/LightyLogger.swift +++ b/Sources/LightyLogger.swift @@ -107,7 +107,12 @@ public class LightyLogger { function: String = #function, line: Int = #line) { #if DEBUG - log(type: type, message: message) + let fileExtension = file.nsstring.lastPathComponent.nsstring.pathExtension + let fileName = file.nsstring.lastPathComponent.nsstring.deletingPathExtension + + let trackedString = "\(fileName).\(fileExtension):\(line) \(function)" + + print(type.rawValue + " " + dateFormatter.string(from: Date()) + separator + trackedString + separator + message + " " + type.rawValue) #endif } From 7e439318971771390c89d9b9d2508264586eede0 Mon Sep 17 00:00:00 2001 From: Guilherme Rambo Date: Mon, 2 Jan 2017 18:44:33 -0200 Subject: [PATCH 6/6] Refactor: using URL to parse filename on dlog --- Sources/LightyLogger.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/LightyLogger.swift b/Sources/LightyLogger.swift index 0e5d7f1..1d9982f 100644 --- a/Sources/LightyLogger.swift +++ b/Sources/LightyLogger.swift @@ -107,8 +107,9 @@ public class LightyLogger { function: String = #function, line: Int = #line) { #if DEBUG - let fileExtension = file.nsstring.lastPathComponent.nsstring.pathExtension - let fileName = file.nsstring.lastPathComponent.nsstring.deletingPathExtension + let fileUrl = URL(fileURLWithPath: file) + let fileExtension = fileUrl.pathExtension + let fileName = fileUrl.deletingPathExtension().lastPathComponent let trackedString = "\(fileName).\(fileExtension):\(line) \(function)"