From a0d55fcde0f403a59f504be7e8b024efefd4e923 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sun, 22 Nov 2015 15:41:35 +0100 Subject: [PATCH 01/13] enable logs by default. Disable them in Release mode --- Example/Example-iOS/ViewController.swift | 8 -------- Example/Example.xcodeproj/project.pbxproj | 3 ++- Source/SpeedLog.swift | 2 +- SpeedLog.xcodeproj/project.pbxproj | 3 ++- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Example/Example-iOS/ViewController.swift b/Example/Example-iOS/ViewController.swift index 3e0eb03..5502f69 100644 --- a/Example/Example-iOS/ViewController.swift +++ b/Example/Example-iOS/ViewController.swift @@ -12,14 +12,6 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. } - - override func didReceiveMemoryWarning() { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } - - } diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index ee40823..c6dee40 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -431,7 +431,7 @@ B5BA46DE1BFF668700EC5A0D /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - OTHER_SWIFT_FLAGS = "-D ENABLE_LOG"; + OTHER_SWIFT_FLAGS = ""; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -439,6 +439,7 @@ B5BA46DF1BFF668700EC5A0D /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + OTHER_SWIFT_FLAGS = "-D DISABLE_LOG"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/Source/SpeedLog.swift b/Source/SpeedLog.swift index 0eec570..3c01aaf 100644 --- a/Source/SpeedLog.swift +++ b/Source/SpeedLog.swift @@ -44,7 +44,7 @@ public struct SpeedLog { */ public static func print(items: Any..., separator: String = " ", terminator: String = "\n", _ file: String = __FILE__, _ function: String = __FUNCTION__, _ line: Int = __LINE__) { - #if ENABLE_LOG + #if !DISABLE_LOG let prefix = modePrefix(file, function: function, line: line) let stringItem = items.map {"\($0)"} .joinWithSeparator(separator) Swift.print("\(prefix)\(stringItem)", terminator: terminator) diff --git a/SpeedLog.xcodeproj/project.pbxproj b/SpeedLog.xcodeproj/project.pbxproj index e8c2d26..617dbbe 100644 --- a/SpeedLog.xcodeproj/project.pbxproj +++ b/SpeedLog.xcodeproj/project.pbxproj @@ -327,7 +327,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - OTHER_SWIFT_FLAGS = "-D ENABLE_LOG"; + OTHER_SWIFT_FLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = kk.SpeedLog; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -344,6 +344,7 @@ INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + OTHER_SWIFT_FLAGS = "-D DISABLE_LOG"; PRODUCT_BUNDLE_IDENTIFIER = kk.SpeedLog; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; From 1938bc661e52a871fd2ed4d1c2299cac2fedbf32 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sun, 22 Nov 2015 19:04:26 +0100 Subject: [PATCH 02/13] add date formatting --- Source/SpeedLog.swift | 24 ++++++++++++++++-------- Tests/SpeedLogTests.swift | 22 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Source/SpeedLog.swift b/Source/SpeedLog.swift index 3c01aaf..4efedcc 100644 --- a/Source/SpeedLog.swift +++ b/Source/SpeedLog.swift @@ -20,13 +20,14 @@ public struct LogMode : OptionSetType { public init(_ value: UInt) { self.value = value } //MARK:- Options - public static var None = LogMode(rawValue: 0) - public static var FileName = LogMode(rawValue: 1 << 0) - public static var FuncName = LogMode(rawValue: 1 << 1) - public static var Line = LogMode(rawValue: 1 << 2) + public static let None = LogMode(rawValue: 0) + public static let FileName = LogMode(rawValue: 1 << 0) + public static let FuncName = LogMode(rawValue: 1 << 1) + public static let Line = LogMode(rawValue: 1 << 2) + public static let Date = LogMode(rawValue: 1 << 3) /// AllOptions - Enable all options, [FileName, FuncName, Line] - public static var AllOptions: LogMode = [FileName, FuncName, Line] + public static var AllOptions: LogMode = [Date, FileName, FuncName, Line] } @@ -45,7 +46,7 @@ public struct SpeedLog { public static func print(items: Any..., separator: String = " ", terminator: String = "\n", _ file: String = __FILE__, _ function: String = __FUNCTION__, _ line: Int = __LINE__) { #if !DISABLE_LOG - let prefix = modePrefix(file, function: function, line: line) + let prefix = modePrefix(NSDate(), file: file, function: function, line: line) let stringItem = items.map {"\($0)"} .joinWithSeparator(separator) Swift.print("\(prefix)\(stringItem)", terminator: terminator) #endif @@ -57,11 +58,18 @@ extension SpeedLog { /** Creates an output string for the currect log Mode */ - static func modePrefix(file: String, function: String, line: Int) -> String { + static func modePrefix(date: NSDate, file: String, function: String, line: Int) -> String { var result: String = "" + if mode.contains(.Date) { + let formatter = NSDateFormatter() + formatter.dateFormat = "yyyy-MM-dd HH:mm:ss:SSS" + + let s = formatter.stringFromDate(date) + result += s + } if mode.contains(.FileName) { let filename = file.lastPathComponent.stringByDeletingPathExtension - result = "\(filename)." + result += "\(filename)." } if mode.contains(.FuncName) { result += "\(function)" diff --git a/Tests/SpeedLogTests.swift b/Tests/SpeedLogTests.swift index 083a4cd..f7d3acb 100644 --- a/Tests/SpeedLogTests.swift +++ b/Tests/SpeedLogTests.swift @@ -32,6 +32,12 @@ class SpeedLogTests: XCTestCase { XCTAssertEqual(prefix, "[10]: ") } + func testDatePrefix() { + let prefix = logForMode(.Date) + XCTAssertEqual(prefix, "2015-01-10 06:44:43:060: ") + } + + func testAllOptionsPrefix() { let prefix = logForMode(.AllOptions) XCTAssertEqual(prefix, "File.FuncA[10]: ") @@ -43,7 +49,21 @@ extension SpeedLogTests { func logForMode(mode: LogMode) -> String { SpeedLog.mode = mode - return SpeedLog.modePrefix("File", function: "FuncA", line: 10) + return SpeedLog.modePrefix(date, file:"File", function: "FuncA", line: 10) + } + + var date: NSDate { + let components = NSDateComponents() + components.year = 2015 + components.month = 1 + components.day = 10 + + components.hour = 6 + components.minute = 44 + components.second = 43 + components.nanosecond = 60000000 //100000 NSEC_PER_SEC + + return NSCalendar.currentCalendar().dateFromComponents(components)! } } From f9e3d972d4bdaec43a6307f0e65a21c340a1014c Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sun, 22 Nov 2015 19:28:35 +0100 Subject: [PATCH 03/13] add FullCode Style --- Source/SpeedLog.swift | 5 ++++- Tests/SpeedLogTests.swift | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Source/SpeedLog.swift b/Source/SpeedLog.swift index 4efedcc..692aac6 100644 --- a/Source/SpeedLog.swift +++ b/Source/SpeedLog.swift @@ -28,6 +28,8 @@ public struct LogMode : OptionSetType { /// AllOptions - Enable all options, [FileName, FuncName, Line] public static var AllOptions: LogMode = [Date, FileName, FuncName, Line] + public static var FullCodeLocation: LogMode = [FileName, FuncName, Line] + } @@ -62,7 +64,7 @@ extension SpeedLog { var result: String = "" if mode.contains(.Date) { let formatter = NSDateFormatter() - formatter.dateFormat = "yyyy-MM-dd HH:mm:ss:SSS" + formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS " let s = formatter.stringFromDate(date) result += s @@ -79,6 +81,7 @@ extension SpeedLog { } if !result.isEmpty { + result = result.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) result += ": " } diff --git a/Tests/SpeedLogTests.swift b/Tests/SpeedLogTests.swift index f7d3acb..7ea3c03 100644 --- a/Tests/SpeedLogTests.swift +++ b/Tests/SpeedLogTests.swift @@ -34,13 +34,18 @@ class SpeedLogTests: XCTestCase { func testDatePrefix() { let prefix = logForMode(.Date) - XCTAssertEqual(prefix, "2015-01-10 06:44:43:060: ") + XCTAssertEqual(prefix, "2015-01-10 06:44:43.060: ") } + func testFullCodeLocationPrefix() { + let prefix = logForMode(.FullCodeLocation) + XCTAssertEqual(prefix, "File.FuncA[10]: ") + } func testAllOptionsPrefix() { let prefix = logForMode(.AllOptions) - XCTAssertEqual(prefix, "File.FuncA[10]: ") + XCTAssertEqual(prefix, "2015-01-10 06:44:43.060 File.FuncA[10]: ") + //FIXME: add space between date and file } } From b719f096d194134d29dfb9d80020b385ced19b58 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Tue, 24 Nov 2015 21:54:32 +0100 Subject: [PATCH 04/13] add colours log --- Example/Example-iOS/AppDelegate.swift | 12 ++++ Source/Colors.swift | 91 +++++++++++++++++++++++++++ Source/Swizzling.swift | 24 +++++++ Source/UIColor+Log.swift | 43 +++++++++++++ SpeedLog.xcodeproj/project.pbxproj | 12 ++++ 5 files changed, 182 insertions(+) create mode 100644 Source/Colors.swift create mode 100644 Source/Swizzling.swift create mode 100644 Source/UIColor+Log.swift diff --git a/Example/Example-iOS/AppDelegate.swift b/Example/Example-iOS/AppDelegate.swift index b83e250..0f18efa 100644 --- a/Example/Example-iOS/AppDelegate.swift +++ b/Example/Example-iOS/AppDelegate.swift @@ -16,6 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { myFunc() + colorLog() return true } @@ -34,5 +35,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate { SpeedLog.mode = [.FuncName, .FileName, .Line] SpeedLog.print("Show all 3 options :)") } + + func colorLog() { + let c = UIColor.redColor() + print("Original:", c) + + UIColor.swizzleDesription() + print("Swizzleed:", c) + + UIColor.undoDesriptionSwizzling() + print("Original Restored:", c) + } } diff --git a/Source/Colors.swift b/Source/Colors.swift new file mode 100644 index 0000000..9a5eef3 --- /dev/null +++ b/Source/Colors.swift @@ -0,0 +1,91 @@ +// +// Colors.swift +// SpeedLog +// +// Created by Kostiantyn Koval on 23/11/15. +// Copyright © 2015 Kostiantyn Koval. All rights reserved. +// + +import Foundation + +protocol ColorType { + var colorCode: String { get } +} + +struct RGBColor { + let R: Int + let G: Int + let B: Int +} + +extension RGBColor: CustomStringConvertible { + var description: String { + return "RGB: \(R), \(G), \(B)" + } +} + +extension RGBColor: ColorType { + + var colorCode: String { + return "\(R),\(G),\(B)" + } +} + + +struct LogColors { + struct Key { + static let Escape = "\u{001b}[" + + static let Fg = "fg" + static let Bg = "bg" + + static let ResetFG = Escape + "fg;" // Clear any foreground color + static let ResetBG = Escape + "bg;" // Clear any background color + static let Reset = Escape + ";" // Clear any foreground or background color + } + + static func font(color: ColorType, object: T) -> String { + return "\(Key.Escape)fg\(color.colorCode);\(object)\(Key.Reset)" + } + + static func background(color: ColorType, object: T) -> String { + return "\(Key.Escape)bg\(color.colorCode);\(object)\(Key.Reset)" + } + + static func colored(font: ColorType, background: ColorType, object: T) -> String { + + let string = + "\(Key.Escape)bg\(font.colorCode);" + + "\(Key.Escape)bg\(background.colorCode);" + + "\(object)\(Key.Reset)" + + return string + } + + + +/* + static func red(object: T) { + print("\(ESCAPE)fg255,0,0;\(object)\(RESET)") + } + + static func green(object: T) { + print("\(ESCAPE)fg0,255,0;\(object)\(RESET)") + } + + static func blue(object: T) { + print("\(ESCAPE)fg0,0,255;\(object)\(RESET)") + } + + static func yellow(object: T) { + print("\(ESCAPE)fg255,255,0;\(object)\(RESET)") + } + + static func purple(object: T) { + print("\(ESCAPE)fg255,0,255;\(object)\(RESET)") + } + + static func cyan(object: T) { + print("\(ESCAPE)fg0,255,255;\(object)\(RESET)") + } */ +} diff --git a/Source/Swizzling.swift b/Source/Swizzling.swift new file mode 100644 index 0000000..ed20c68 --- /dev/null +++ b/Source/Swizzling.swift @@ -0,0 +1,24 @@ +// +// Swizzling.swift +// SpeedLog +// +// Created by Kostiantyn Koval on 24/11/15. +// Copyright © 2015 Kostiantyn Koval. All rights reserved. +// + +import Foundation + +extension NSObject { + + class func swizzleMethods(origSelector: Selector, withSelector: Selector, forClass: AnyClass) { + let originalMethod = class_getInstanceMethod(forClass, origSelector) + let swizzledMethod = class_getInstanceMethod(forClass, withSelector) + + method_exchangeImplementations(originalMethod, swizzledMethod) + } + + func swizzleMethods(origSelector: Selector, withSelector: Selector) { + let aClass: AnyClass! = object_getClass(self) + NSObject.swizzleMethods(origSelector, withSelector: withSelector, forClass: aClass) + } +} diff --git a/Source/UIColor+Log.swift b/Source/UIColor+Log.swift new file mode 100644 index 0000000..d1fd3e6 --- /dev/null +++ b/Source/UIColor+Log.swift @@ -0,0 +1,43 @@ +// +// UIColor+Log.swift +// SpeedLog +// +// Created by Kostiantyn Koval on 23/11/15. +// Copyright © 2015 Kostiantyn Koval. All rights reserved. +// + +import UIKit + +public extension UIColor { + public class func swizzleDesription() { + let instance: UIColor = UIColor.redColor() + instance.swizzleMethods("description", withSelector: "colorDescription") + } + + public class func undoDesriptionSwizzling() { + let instance: UIColor = UIColor.redColor() + instance.swizzleMethods("colorDescription", withSelector: "description") + } +} + +extension UIColor { + + var rgbColor: RGBColor { + var red: CGFloat = 0 + var green: CGFloat = 0 + var blue: CGFloat = 0 + var alpha: CGFloat = 0 + + getRed(&red, green: &green, blue: &blue, alpha: &alpha) + return RGBColor(R: Int(red) * 255, G: Int(green) * 255, B: Int(blue) * 255) + } + + func colorDescription() -> String { + let color = rgbColor + return "\(color) - " + LogColors.background(color, object: " ") + } +} + + + + diff --git a/SpeedLog.xcodeproj/project.pbxproj b/SpeedLog.xcodeproj/project.pbxproj index 617dbbe..f7f998a 100644 --- a/SpeedLog.xcodeproj/project.pbxproj +++ b/SpeedLog.xcodeproj/project.pbxproj @@ -11,6 +11,9 @@ B5BA46711BFF596C00EC5A0D /* SpeedLogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BA46701BFF596C00EC5A0D /* SpeedLogTests.swift */; }; B5BA46851BFF625500EC5A0D /* SpeedLog.h in Headers */ = {isa = PBXBuildFile; fileRef = B5BA46821BFF625500EC5A0D /* SpeedLog.h */; settings = {ATTRIBUTES = (Public, ); }; }; B5BA46861BFF625500EC5A0D /* SpeedLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BA46831BFF625500EC5A0D /* SpeedLog.swift */; }; + B5FB59961C039E2C00B12B4D /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FB59951C039E2C00B12B4D /* Colors.swift */; }; + B5FB59981C039F1E00B12B4D /* UIColor+Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FB59971C039F1E00B12B4D /* UIColor+Log.swift */; }; + B5FB599B1C04F07C00B12B4D /* Swizzling.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FB599A1C04F07C00B12B4D /* Swizzling.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -31,6 +34,9 @@ B5BA46811BFF625500EC5A0D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; B5BA46821BFF625500EC5A0D /* SpeedLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpeedLog.h; sourceTree = ""; }; B5BA46831BFF625500EC5A0D /* SpeedLog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpeedLog.swift; sourceTree = ""; }; + B5FB59951C039E2C00B12B4D /* Colors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = ""; }; + B5FB59971C039F1E00B12B4D /* UIColor+Log.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Log.swift"; sourceTree = ""; }; + B5FB599A1C04F07C00B12B4D /* Swizzling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Swizzling.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -83,6 +89,9 @@ isa = PBXGroup; children = ( B5BA46831BFF625500EC5A0D /* SpeedLog.swift */, + B5FB59951C039E2C00B12B4D /* Colors.swift */, + B5FB59971C039F1E00B12B4D /* UIColor+Log.swift */, + B5FB599A1C04F07C00B12B4D /* Swizzling.swift */, B5BA46871BFF627400EC5A0D /* Supporting Files */, ); path = Source; @@ -206,6 +215,9 @@ buildActionMask = 2147483647; files = ( B5BA46861BFF625500EC5A0D /* SpeedLog.swift in Sources */, + B5FB59981C039F1E00B12B4D /* UIColor+Log.swift in Sources */, + B5FB59961C039E2C00B12B4D /* Colors.swift in Sources */, + B5FB599B1C04F07C00B12B4D /* Swizzling.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From f1d411bcb4e424ef1ca13682b6693060ce2a8f31 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Thu, 26 Nov 2015 19:33:21 +0100 Subject: [PATCH 05/13] add Readme playground examples --- .../contents.xcworkspacedata | 3 +++ .../Readme.xcplaygroundpage/Contents.swift | 25 +++++++++++++++++++ .../timeline.xctimeline | 0 .../Contents.swift | 0 .../timeline.xctimeline | 6 +++++ .../contents.xcplayground | 7 ++++-- README.md | 9 +++++++ 7 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/Contents.swift rename Example/MyPlayground.playground/{ => Pages/Readme.xcplaygroundpage}/timeline.xctimeline (100%) rename Example/MyPlayground.playground/{ => Pages/Untitled Page.xcplaygroundpage}/Contents.swift (100%) create mode 100644 Example/MyPlayground.playground/Pages/Untitled Page.xcplaygroundpage/timeline.xctimeline diff --git a/Example/Example.xcworkspace/contents.xcworkspacedata b/Example/Example.xcworkspace/contents.xcworkspacedata index 9bba940..6d4fa50 100644 --- a/Example/Example.xcworkspace/contents.xcworkspacedata +++ b/Example/Example.xcworkspace/contents.xcworkspacedata @@ -4,6 +4,9 @@ + + diff --git a/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/Contents.swift b/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..ee2c1ba --- /dev/null +++ b/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/Contents.swift @@ -0,0 +1,25 @@ +//: [Previous](@previous) + +import SpeedLog +SpeedLog.print("Hello") +SpeedLog.print(["Super"], ["Speed"]) + +// ### Log output Styling + +SpeedLog.mode = .FuncName +SpeedLog.print("Show only FunctionName") +//myFunc(): Show only FunctionName + +SpeedLog.mode = [.FuncName, .FileName] +SpeedLog.print("Show FunctionName and File name") +//AppDelegate.myFunc(): Show FunctionName and File name + +SpeedLog.mode = [.FuncName, .FileName, .Line] +SpeedLog.print("Show all 3 options :)") +//AppDelegate.myFunc()[35]: Show all 3 options :) + +SpeedLog.mode = .AllOptions +SpeedLog.print("Enable All Features") +//AppDelegate.myFunc()[26]: Enable All Features + +//: [Next](@next) diff --git a/Example/MyPlayground.playground/timeline.xctimeline b/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/timeline.xctimeline similarity index 100% rename from Example/MyPlayground.playground/timeline.xctimeline rename to Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/timeline.xctimeline diff --git a/Example/MyPlayground.playground/Contents.swift b/Example/MyPlayground.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift similarity index 100% rename from Example/MyPlayground.playground/Contents.swift rename to Example/MyPlayground.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift diff --git a/Example/MyPlayground.playground/Pages/Untitled Page.xcplaygroundpage/timeline.xctimeline b/Example/MyPlayground.playground/Pages/Untitled Page.xcplaygroundpage/timeline.xctimeline new file mode 100644 index 0000000..bf468af --- /dev/null +++ b/Example/MyPlayground.playground/Pages/Untitled Page.xcplaygroundpage/timeline.xctimeline @@ -0,0 +1,6 @@ + + + + + diff --git a/Example/MyPlayground.playground/contents.xcplayground b/Example/MyPlayground.playground/contents.xcplayground index 5da2641..4467a73 100644 --- a/Example/MyPlayground.playground/contents.xcplayground +++ b/Example/MyPlayground.playground/contents.xcplayground @@ -1,4 +1,7 @@ - - + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 3d31c34..e6e175f 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ The SpeedLog allows you to remove `print` when the logs are disabled. This allow - [x] Improves Swift code optimization - [x] Easy to disable - [x] Reach formatting +- [x] Coloured console output +- [x] Custom `UIColor` representation ## Usage @@ -84,6 +86,13 @@ github "kostiakoval/SpeedLog" Copy the `SpeedLog.swift` file into your project +### Colors + +In order to use colorised console you need to install [XcodeColors](https://github.com/robbiehanson/XcodeColors) Xcode plugin. +Use [Alcatraz](http://alcatraz.io) to install it. Go to: +Xcode -> Window -> Package Manager -> Search for `XcodeColors` and install it + + ## Future Features There are many logging libs I like: From ce9b0137894b95b2a96fcbcee6342a885cea15e7 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Thu, 26 Nov 2015 19:37:21 +0100 Subject: [PATCH 06/13] update readme --- .../Readme.xcplaygroundpage/Contents.swift | 12 +++++++----- README.md | 18 +++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/Contents.swift b/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/Contents.swift index ee2c1ba..80ba828 100644 --- a/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/Contents.swift +++ b/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/Contents.swift @@ -15,11 +15,13 @@ SpeedLog.print("Show FunctionName and File name") //AppDelegate.myFunc(): Show FunctionName and File name SpeedLog.mode = [.FuncName, .FileName, .Line] -SpeedLog.print("Show all 3 options :)") -//AppDelegate.myFunc()[35]: Show all 3 options :) +SpeedLog.print("Show 3 options :)") +//AppDelegate.myFunc()[36]: Show 3 options :) + +SpeedLog.mode = .FullCodeLocation +SpeedLog.print("Show fullCode, same as above") +//AppDelegate.myFunc()[39]: Show fullCode, same as above SpeedLog.mode = .AllOptions SpeedLog.print("Enable All Features") -//AppDelegate.myFunc()[26]: Enable All Features - -//: [Next](@next) +//2015-11-26 19:32:33.687 AppDelegate.myFunc()[27]: Enable All Features diff --git a/README.md b/README.md index e6e175f..0728647 100644 --- a/README.md +++ b/README.md @@ -30,21 +30,25 @@ SpeedLog.print(["Super"], ["Speed"]) ### Log output Styling ```swift -SpeedLog.mode = LogMode.FuncName +SpeedLog.mode = .FuncName SpeedLog.print("Show only FunctionName") //myFunc(): Show only FunctionName -SpeedLog.mode = LogMode.FuncName | LogMode.FileName +SpeedLog.mode = [.FuncName, .FileName] SpeedLog.print("Show FunctionName and File name") //AppDelegate.myFunc(): Show FunctionName and File name -SpeedLog.mode = LogMode.FuncName | LogMode.FileName | LogMode.Line -SpeedLog.print("Show all 3 options :)") -//AppDelegate.myFunc()[35]: Show all 3 options :) +SpeedLog.mode = [.FuncName, .FileName, .Line] +SpeedLog.print("Show 3 options :)") +//AppDelegate.myFunc()[36]: Show 3 options :) -SpeedLog.mode = LogMode.AllOptions +SpeedLog.mode = .FullCodeLocation +SpeedLog.print("Show fullCode, same as above") +//AppDelegate.myFunc()[39]: Show fullCode, same as above + +SpeedLog.mode = .AllOptions SpeedLog.print("Enable All Features") -//AppDelegate.myFunc()[26]: Enable All Features +//2015-11-26 19:32:33.687 AppDelegate.myFunc()[27]: Enable All Features ``` ###Enables Log From 91f96ad8953c6a59ebf60ee9519a776f7ca93e66 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sat, 28 Nov 2015 14:32:11 +0100 Subject: [PATCH 07/13] add LogMode tests. Refactor color login --- Source/Colors.swift | 18 ----------------- Source/SpeedLog.swift | 11 ++++------ Source/UIColor+Log.swift | 32 +++++++++++++++++++++++++++--- SpeedLog.xcodeproj/project.pbxproj | 4 ++++ Tests/LogModeTests.swift | 29 +++++++++++++++++++++++++++ Tests/Tests.swift | 23 --------------------- 6 files changed, 66 insertions(+), 51 deletions(-) create mode 100644 Tests/LogModeTests.swift delete mode 100644 Tests/Tests.swift diff --git a/Source/Colors.swift b/Source/Colors.swift index 9a5eef3..0829da9 100644 --- a/Source/Colors.swift +++ b/Source/Colors.swift @@ -12,24 +12,6 @@ protocol ColorType { var colorCode: String { get } } -struct RGBColor { - let R: Int - let G: Int - let B: Int -} - -extension RGBColor: CustomStringConvertible { - var description: String { - return "RGB: \(R), \(G), \(B)" - } -} - -extension RGBColor: ColorType { - - var colorCode: String { - return "\(R),\(G),\(B)" - } -} struct LogColors { diff --git a/Source/SpeedLog.swift b/Source/SpeedLog.swift index 692aac6..dfa7d6a 100644 --- a/Source/SpeedLog.swift +++ b/Source/SpeedLog.swift @@ -13,11 +13,8 @@ typealias SLog = SpeedLog ///LogMode type. Specify what details should be included to the log public struct LogMode : OptionSetType { - private var value: UInt = 0 - public var rawValue: UInt { return value } - - public init(rawValue value: UInt) { self.value = value } - public init(_ value: UInt) { self.value = value } + public let rawValue: UInt + public init(rawValue: UInt) { self.rawValue = rawValue } //MARK:- Options public static let None = LogMode(rawValue: 0) @@ -27,8 +24,8 @@ public struct LogMode : OptionSetType { public static let Date = LogMode(rawValue: 1 << 3) /// AllOptions - Enable all options, [FileName, FuncName, Line] - public static var AllOptions: LogMode = [Date, FileName, FuncName, Line] - public static var FullCodeLocation: LogMode = [FileName, FuncName, Line] + public static let AllOptions: LogMode = [Date, FileName, FuncName, Line] + public static let FullCodeLocation: LogMode = [FileName, FuncName, Line] } diff --git a/Source/UIColor+Log.swift b/Source/UIColor+Log.swift index d1fd3e6..881b581 100644 --- a/Source/UIColor+Log.swift +++ b/Source/UIColor+Log.swift @@ -8,18 +8,44 @@ import UIKit +// MARK: - Decription Swizzling public extension UIColor { - public class func swizzleDesription() { - let instance: UIColor = UIColor.redColor() + + /// Swizzle description method with own colorDescription. + /// colorDescription will used instead of description + public class func swizzleDescription() { + let instance = UIColor.redColor() instance.swizzleMethods("description", withSelector: "colorDescription") } + /// Restore back original description method public class func undoDesriptionSwizzling() { - let instance: UIColor = UIColor.redColor() + let instance = UIColor.redColor() instance.swizzleMethods("colorDescription", withSelector: "description") } } +// MARK: - RGGColor +public struct RGBColor { + let R: Int + let G: Int + let B: Int +} + +extension RGBColor: CustomStringConvertible { + public var description: String { + return "RGB: \(R), \(G), \(B)" + } +} + +extension RGBColor: ColorType { + //Color representation for XcodeColors console log + var colorCode: String { + return "\(R),\(G),\(B)" + } +} + +// MARK: - UIColor extension UIColor { var rgbColor: RGBColor { diff --git a/SpeedLog.xcodeproj/project.pbxproj b/SpeedLog.xcodeproj/project.pbxproj index f7f998a..d622713 100644 --- a/SpeedLog.xcodeproj/project.pbxproj +++ b/SpeedLog.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + B518B4491C078F8900C6DA04 /* LogModeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B518B4481C078F8900C6DA04 /* LogModeTests.swift */; }; B5BA466C1BFF596C00EC5A0D /* SpeedLog.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5BA46611BFF596B00EC5A0D /* SpeedLog.framework */; }; B5BA46711BFF596C00EC5A0D /* SpeedLogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BA46701BFF596C00EC5A0D /* SpeedLogTests.swift */; }; B5BA46851BFF625500EC5A0D /* SpeedLog.h in Headers */ = {isa = PBXBuildFile; fileRef = B5BA46821BFF625500EC5A0D /* SpeedLog.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -27,6 +28,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + B518B4481C078F8900C6DA04 /* LogModeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogModeTests.swift; sourceTree = ""; }; B5BA46611BFF596B00EC5A0D /* SpeedLog.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SpeedLog.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B5BA466B1BFF596C00EC5A0D /* SpeedLogTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SpeedLogTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; B5BA46701BFF596C00EC5A0D /* SpeedLogTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeedLogTests.swift; sourceTree = ""; }; @@ -80,6 +82,7 @@ isa = PBXGroup; children = ( B5BA46701BFF596C00EC5A0D /* SpeedLogTests.swift */, + B518B4481C078F8900C6DA04 /* LogModeTests.swift */, B5BA46721BFF596C00EC5A0D /* Info.plist */, ); path = Tests; @@ -226,6 +229,7 @@ buildActionMask = 2147483647; files = ( B5BA46711BFF596C00EC5A0D /* SpeedLogTests.swift in Sources */, + B518B4491C078F8900C6DA04 /* LogModeTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/LogModeTests.swift b/Tests/LogModeTests.swift new file mode 100644 index 0000000..80c5596 --- /dev/null +++ b/Tests/LogModeTests.swift @@ -0,0 +1,29 @@ +// +// Test.swift +// SpeedLog +// +// Created by Kostiantyn Koval on 26/11/15. +// Copyright © 2015 Kostiantyn Koval. All rights reserved. +// + +import XCTest +@testable import SpeedLog + +class LogModeTests: XCTestCase { + let allCases: [LogMode] = [.None, .FileName, .FuncName, .Line, .Date] + + func testAllCasesAreEven() { + let allValues = allCases.map { $0.rawValue } + let oddValues = allValues.filter { $0 % 2 != 0 } + + XCTAssertEqual(oddValues.count, 1) + XCTAssertTrue(oddValues.first! == 1) + } + + func testAllCasesAreUnique() { + let rawValues = allCases.map {$0.rawValue } + let uniqueValues = Set(rawValues) + + XCTAssertEqual(uniqueValues.count, rawValues.count) + } +} diff --git a/Tests/Tests.swift b/Tests/Tests.swift deleted file mode 100644 index 211761f..0000000 --- a/Tests/Tests.swift +++ /dev/null @@ -1,23 +0,0 @@ -import UIKit -import XCTest -import SpeedLog - -class Tests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func testExample() { - // This is an example of a functional test case. - XCTAssert(true, "Pass") - } - - -} From 596df9b96364caad86e658a5be1cf99620653a34 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sat, 28 Nov 2015 14:41:11 +0100 Subject: [PATCH 08/13] add more test for LogMode --- Tests/LogModeTests.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tests/LogModeTests.swift b/Tests/LogModeTests.swift index 80c5596..f1fd77f 100644 --- a/Tests/LogModeTests.swift +++ b/Tests/LogModeTests.swift @@ -26,4 +26,9 @@ class LogModeTests: XCTestCase { XCTAssertEqual(uniqueValues.count, rawValues.count) } + + func testAggregationCase() { + XCTAssertEqual(LogMode.FullCodeLocation, [.FileName, .FuncName, .Line]) + XCTAssertEqual(LogMode.AllOptions, [.Date, .FileName, .FuncName, .Line]) + } } From dd41f099892d8ebfe5a84bb5ebff9cfa5f955569 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sat, 28 Nov 2015 15:08:41 +0100 Subject: [PATCH 09/13] add Color log tests --- Source/ColorLog.swift | 52 +++++++++++++++++++++ Source/Colors.swift | 73 ------------------------------ Source/SpeedLog.swift | 1 - Source/UIColor+Log.swift | 4 +- SpeedLog.xcodeproj/project.pbxproj | 12 +++-- Tests/ColorLogTest.swift | 36 +++++++++++++++ 6 files changed, 98 insertions(+), 80 deletions(-) create mode 100644 Source/ColorLog.swift delete mode 100644 Source/Colors.swift create mode 100644 Tests/ColorLogTest.swift diff --git a/Source/ColorLog.swift b/Source/ColorLog.swift new file mode 100644 index 0000000..16791de --- /dev/null +++ b/Source/ColorLog.swift @@ -0,0 +1,52 @@ +// +// Colors.swift +// SpeedLog +// +// Created by Kostiantyn Koval on 23/11/15. +// Copyright © 2015 Kostiantyn Koval. All rights reserved. +// + +import Foundation + +/// RGBColorType representation +protocol RGBColorType { + + /// Return RGB color represenation. + /// Example R: 200, G: 125, G: 255 + var colorCode: String { get } +} + +struct ColorLog { + struct Key { + private static let Escape = "\u{001b}[" + private static let Fg = "fg" + static let Bg = "bg" + + static let StartFg = "\(Escape)\(Fg)" + static let StartBg = "\(Escape)\(Bg)" + + static let ResetFG = Escape + "fg;" // Clear any foreground color + static let ResetBG = Escape + "bg;" // Clear any background color + static let Reset = Escape + ";" // Clear any foreground or background color + } + + /// String with a Font color + static func font(color: RGBColorType, object: T) -> String { + return "\(Key.StartFg)\(color.colorCode);\(object)\(Key.Reset)" + } + + /// String with a Background color + static func background(color: RGBColorType, object: T) -> String { + return "\(Key.StartBg)\(color.colorCode);\(object)\(Key.Reset)" + } + + /// String with both Background and Font color + static func colored(font: RGBColorType, background: RGBColorType, object: T) -> String { + let string = + "\(Key.Escape)fg\(font.colorCode);" + + "\(Key.Escape)bg\(background.colorCode);" + + "\(object)\(Key.Reset)" + + return string + } +} diff --git a/Source/Colors.swift b/Source/Colors.swift deleted file mode 100644 index 0829da9..0000000 --- a/Source/Colors.swift +++ /dev/null @@ -1,73 +0,0 @@ -// -// Colors.swift -// SpeedLog -// -// Created by Kostiantyn Koval on 23/11/15. -// Copyright © 2015 Kostiantyn Koval. All rights reserved. -// - -import Foundation - -protocol ColorType { - var colorCode: String { get } -} - - - -struct LogColors { - struct Key { - static let Escape = "\u{001b}[" - - static let Fg = "fg" - static let Bg = "bg" - - static let ResetFG = Escape + "fg;" // Clear any foreground color - static let ResetBG = Escape + "bg;" // Clear any background color - static let Reset = Escape + ";" // Clear any foreground or background color - } - - static func font(color: ColorType, object: T) -> String { - return "\(Key.Escape)fg\(color.colorCode);\(object)\(Key.Reset)" - } - - static func background(color: ColorType, object: T) -> String { - return "\(Key.Escape)bg\(color.colorCode);\(object)\(Key.Reset)" - } - - static func colored(font: ColorType, background: ColorType, object: T) -> String { - - let string = - "\(Key.Escape)bg\(font.colorCode);" + - "\(Key.Escape)bg\(background.colorCode);" + - "\(object)\(Key.Reset)" - - return string - } - - - -/* - static func red(object: T) { - print("\(ESCAPE)fg255,0,0;\(object)\(RESET)") - } - - static func green(object: T) { - print("\(ESCAPE)fg0,255,0;\(object)\(RESET)") - } - - static func blue(object: T) { - print("\(ESCAPE)fg0,0,255;\(object)\(RESET)") - } - - static func yellow(object: T) { - print("\(ESCAPE)fg255,255,0;\(object)\(RESET)") - } - - static func purple(object: T) { - print("\(ESCAPE)fg255,0,255;\(object)\(RESET)") - } - - static func cyan(object: T) { - print("\(ESCAPE)fg0,255,255;\(object)\(RESET)") - } */ -} diff --git a/Source/SpeedLog.swift b/Source/SpeedLog.swift index dfa7d6a..9b1d23f 100644 --- a/Source/SpeedLog.swift +++ b/Source/SpeedLog.swift @@ -26,7 +26,6 @@ public struct LogMode : OptionSetType { /// AllOptions - Enable all options, [FileName, FuncName, Line] public static let AllOptions: LogMode = [Date, FileName, FuncName, Line] public static let FullCodeLocation: LogMode = [FileName, FuncName, Line] - } diff --git a/Source/UIColor+Log.swift b/Source/UIColor+Log.swift index 881b581..eb1d677 100644 --- a/Source/UIColor+Log.swift +++ b/Source/UIColor+Log.swift @@ -38,7 +38,7 @@ extension RGBColor: CustomStringConvertible { } } -extension RGBColor: ColorType { +extension RGBColor: RGBColorType { //Color representation for XcodeColors console log var colorCode: String { return "\(R),\(G),\(B)" @@ -60,7 +60,7 @@ extension UIColor { func colorDescription() -> String { let color = rgbColor - return "\(color) - " + LogColors.background(color, object: " ") + return "\(color) - " + ColorLog.background(color, object: " ") } } diff --git a/SpeedLog.xcodeproj/project.pbxproj b/SpeedLog.xcodeproj/project.pbxproj index d622713..e4bf6cf 100644 --- a/SpeedLog.xcodeproj/project.pbxproj +++ b/SpeedLog.xcodeproj/project.pbxproj @@ -12,7 +12,8 @@ B5BA46711BFF596C00EC5A0D /* SpeedLogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BA46701BFF596C00EC5A0D /* SpeedLogTests.swift */; }; B5BA46851BFF625500EC5A0D /* SpeedLog.h in Headers */ = {isa = PBXBuildFile; fileRef = B5BA46821BFF625500EC5A0D /* SpeedLog.h */; settings = {ATTRIBUTES = (Public, ); }; }; B5BA46861BFF625500EC5A0D /* SpeedLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BA46831BFF625500EC5A0D /* SpeedLog.swift */; }; - B5FB59961C039E2C00B12B4D /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FB59951C039E2C00B12B4D /* Colors.swift */; }; + B5CD588C1C09E71D00E4238C /* ColorLogTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CD588B1C09E71D00E4238C /* ColorLogTest.swift */; }; + B5FB59961C039E2C00B12B4D /* ColorLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FB59951C039E2C00B12B4D /* ColorLog.swift */; }; B5FB59981C039F1E00B12B4D /* UIColor+Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FB59971C039F1E00B12B4D /* UIColor+Log.swift */; }; B5FB599B1C04F07C00B12B4D /* Swizzling.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FB599A1C04F07C00B12B4D /* Swizzling.swift */; }; /* End PBXBuildFile section */ @@ -36,7 +37,8 @@ B5BA46811BFF625500EC5A0D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; B5BA46821BFF625500EC5A0D /* SpeedLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpeedLog.h; sourceTree = ""; }; B5BA46831BFF625500EC5A0D /* SpeedLog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpeedLog.swift; sourceTree = ""; }; - B5FB59951C039E2C00B12B4D /* Colors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = ""; }; + B5CD588B1C09E71D00E4238C /* ColorLogTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorLogTest.swift; sourceTree = ""; }; + B5FB59951C039E2C00B12B4D /* ColorLog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorLog.swift; sourceTree = ""; }; B5FB59971C039F1E00B12B4D /* UIColor+Log.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Log.swift"; sourceTree = ""; }; B5FB599A1C04F07C00B12B4D /* Swizzling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Swizzling.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -82,6 +84,7 @@ isa = PBXGroup; children = ( B5BA46701BFF596C00EC5A0D /* SpeedLogTests.swift */, + B5CD588B1C09E71D00E4238C /* ColorLogTest.swift */, B518B4481C078F8900C6DA04 /* LogModeTests.swift */, B5BA46721BFF596C00EC5A0D /* Info.plist */, ); @@ -92,7 +95,7 @@ isa = PBXGroup; children = ( B5BA46831BFF625500EC5A0D /* SpeedLog.swift */, - B5FB59951C039E2C00B12B4D /* Colors.swift */, + B5FB59951C039E2C00B12B4D /* ColorLog.swift */, B5FB59971C039F1E00B12B4D /* UIColor+Log.swift */, B5FB599A1C04F07C00B12B4D /* Swizzling.swift */, B5BA46871BFF627400EC5A0D /* Supporting Files */, @@ -219,7 +222,7 @@ files = ( B5BA46861BFF625500EC5A0D /* SpeedLog.swift in Sources */, B5FB59981C039F1E00B12B4D /* UIColor+Log.swift in Sources */, - B5FB59961C039E2C00B12B4D /* Colors.swift in Sources */, + B5FB59961C039E2C00B12B4D /* ColorLog.swift in Sources */, B5FB599B1C04F07C00B12B4D /* Swizzling.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -228,6 +231,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + B5CD588C1C09E71D00E4238C /* ColorLogTest.swift in Sources */, B5BA46711BFF596C00EC5A0D /* SpeedLogTests.swift in Sources */, B518B4491C078F8900C6DA04 /* LogModeTests.swift in Sources */, ); diff --git a/Tests/ColorLogTest.swift b/Tests/ColorLogTest.swift new file mode 100644 index 0000000..af25bd8 --- /dev/null +++ b/Tests/ColorLogTest.swift @@ -0,0 +1,36 @@ +// +// ColorLogTest.swift +// SpeedLog +// +// Created by Kostiantyn Koval on 28/11/15. +// Copyright © 2015 Kostiantyn Koval. All rights reserved. +// + +import XCTest +@testable import SpeedLog + +class ColorLogTest: XCTestCase { + let redRGB = UIColor.redColor().rgbColor + + func testFont() { + let redString = ColorLog.font(redRGB, object: "Hi") + XCTAssertEqual(redString, "\(ColorLog.Key.StartFg)\(redRGB.colorCode);Hi\(ColorLog.Key.Reset)") + } + + func testBackground() { + let redBgString = ColorLog.background(redRGB, object: "Hi") + XCTAssertEqual(redBgString, "\(ColorLog.Key.StartBg)\(redRGB.colorCode);Hi\(ColorLog.Key.Reset)") + } + + func testColored() { + let redBgString = ColorLog.colored(redRGB, background: redRGB, object: "Hi") + + let expecred = + "\(ColorLog.Key.StartFg)\(redRGB.colorCode);" + + "\(ColorLog.Key.StartBg)\(redRGB.colorCode);" + + "Hi\(ColorLog.Key.Reset)" + + XCTAssertEqual(redBgString, expecred) + } + +} From c5997768788125c31aa4577b7f2dcfcd24739214 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sat, 28 Nov 2015 15:30:04 +0100 Subject: [PATCH 10/13] Visual representation of UIColor in log --- Example/Example-iOS/AppDelegate.swift | 14 +++++++++++--- Example/Example.xcodeproj/project.pbxproj | 8 -------- .../contents.xcworkspacedata | 3 --- .../Contents.swift | 0 .../timeline.xctimeline | 0 .../contents.xcplayground | 2 +- Source/SpeedLog.swift | 19 ++++++++++++++++--- Source/UIColor+Log.swift | 6 +++--- 8 files changed, 31 insertions(+), 21 deletions(-) rename Example/MyPlayground.playground/Pages/{Untitled Page.xcplaygroundpage => Playground.xcplaygroundpage}/Contents.swift (100%) rename Example/MyPlayground.playground/Pages/{Untitled Page.xcplaygroundpage => Playground.xcplaygroundpage}/timeline.xctimeline (100%) diff --git a/Example/Example-iOS/AppDelegate.swift b/Example/Example-iOS/AppDelegate.swift index 0f18efa..c5f38c9 100644 --- a/Example/Example-iOS/AppDelegate.swift +++ b/Example/Example-iOS/AppDelegate.swift @@ -33,17 +33,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate { SpeedLog.print("Show FunctionName and File name") SpeedLog.mode = [.FuncName, .FileName, .Line] + SpeedLog.print("Show 3 options :)") + + SpeedLog.mode = .FullCodeLocation + SpeedLog.print("Show fullCode, same as above") + + SpeedLog.mode = [.Date, .FuncName, .FileName, .Line] SpeedLog.print("Show all 3 options :)") } func colorLog() { + SpeedLog.mode = .None + SpeedLog.print("\nNice UIColor :) \n") let c = UIColor.redColor() print("Original:", c) - UIColor.swizzleDesription() - print("Swizzleed:", c) + SpeedLog.enableVisualColorLog() + print("Visual:", c) - UIColor.undoDesriptionSwizzling() + SpeedLog.disableVisualColorLog() print("Original Restored:", c) } } diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index c6dee40..199605c 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -395,10 +395,6 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/DerivedData/Example/Build/Products/Debug-iphoneos", - ); INFOPLIST_FILE = "Example-iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -414,10 +410,6 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/DerivedData/Example/Build/Products/Debug-iphoneos", - ); INFOPLIST_FILE = "Example-iOS/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/Example/Example.xcworkspace/contents.xcworkspacedata b/Example/Example.xcworkspace/contents.xcworkspacedata index 6d4fa50..9bba940 100644 --- a/Example/Example.xcworkspace/contents.xcworkspacedata +++ b/Example/Example.xcworkspace/contents.xcworkspacedata @@ -4,9 +4,6 @@ - - diff --git a/Example/MyPlayground.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift b/Example/MyPlayground.playground/Pages/Playground.xcplaygroundpage/Contents.swift similarity index 100% rename from Example/MyPlayground.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift rename to Example/MyPlayground.playground/Pages/Playground.xcplaygroundpage/Contents.swift diff --git a/Example/MyPlayground.playground/Pages/Untitled Page.xcplaygroundpage/timeline.xctimeline b/Example/MyPlayground.playground/Pages/Playground.xcplaygroundpage/timeline.xctimeline similarity index 100% rename from Example/MyPlayground.playground/Pages/Untitled Page.xcplaygroundpage/timeline.xctimeline rename to Example/MyPlayground.playground/Pages/Playground.xcplaygroundpage/timeline.xctimeline diff --git a/Example/MyPlayground.playground/contents.xcplayground b/Example/MyPlayground.playground/contents.xcplayground index 4467a73..1bf63f9 100644 --- a/Example/MyPlayground.playground/contents.xcplayground +++ b/Example/MyPlayground.playground/contents.xcplayground @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/Source/SpeedLog.swift b/Source/SpeedLog.swift index 9b1d23f..ec02b30 100644 --- a/Source/SpeedLog.swift +++ b/Source/SpeedLog.swift @@ -53,9 +53,7 @@ public struct SpeedLog { extension SpeedLog { - /** - Creates an output string for the currect log Mode - */ + /// Create an output string for the currect log Mode static func modePrefix(date: NSDate, file: String, function: String, line: Int) -> String { var result: String = "" if mode.contains(.Date) { @@ -85,6 +83,21 @@ extension SpeedLog { } } +// MARK: - ColorLog + +public extension SpeedLog { + + /// Use custom UIColor desription + static func enableVisualColorLog() { + UIColor.swizzleDescription() + } + + /// Restore default UIColor desription + static func disableVisualColorLog() { + UIColor.undoDesriptionSwizzling() + } +} + /// String syntax sugar extension extension String { var ns: NSString { diff --git a/Source/UIColor+Log.swift b/Source/UIColor+Log.swift index eb1d677..bbd22f5 100644 --- a/Source/UIColor+Log.swift +++ b/Source/UIColor+Log.swift @@ -9,17 +9,17 @@ import UIKit // MARK: - Decription Swizzling -public extension UIColor { +extension UIColor { /// Swizzle description method with own colorDescription. /// colorDescription will used instead of description - public class func swizzleDescription() { + class func swizzleDescription() { let instance = UIColor.redColor() instance.swizzleMethods("description", withSelector: "colorDescription") } /// Restore back original description method - public class func undoDesriptionSwizzling() { + class func undoDesriptionSwizzling() { let instance = UIColor.redColor() instance.swizzleMethods("colorDescription", withSelector: "description") } From 350e5d94a32502a75504e927ada3aa4ec206a771 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sat, 28 Nov 2015 15:41:16 +0100 Subject: [PATCH 11/13] add UIColor log to readme --- Example/Example-iOS/AppDelegate.swift | 4 ++-- Images/RGB-colors-log.png | Bin 0 -> 6501 bytes README.md | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 Images/RGB-colors-log.png diff --git a/Example/Example-iOS/AppDelegate.swift b/Example/Example-iOS/AppDelegate.swift index c5f38c9..e1af7c7 100644 --- a/Example/Example-iOS/AppDelegate.swift +++ b/Example/Example-iOS/AppDelegate.swift @@ -49,10 +49,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { print("Original:", c) SpeedLog.enableVisualColorLog() - print("Visual:", c) + SpeedLog.print("Visual:", c) SpeedLog.disableVisualColorLog() - print("Original Restored:", c) + SpeedLog.print("Original Restored:", c) } } diff --git a/Images/RGB-colors-log.png b/Images/RGB-colors-log.png new file mode 100644 index 0000000000000000000000000000000000000000..ef72795cfdd1974aad3844a7bde144e21b1e51af GIT binary patch literal 6501 zcmZ`+1yCI8vR+&l3lJay77NbevPiHX!7XU;#ogUC5Zv7Z1PBCo7MCC)xVyUsf8?C| z?mboay{YStFEkeu zQI6kYOhnu& ziZ%2yI!el%ihjy>uv)-(!tQ|JcO3!VflLg8O&T}^iLU;VZpXv(?&l*v2CmaNwjUjj zk~31@0usog6jR`b;9?l0ULxH!a8TvvrT$)qLt6phj=^=V7NKd1h`_DbuCEIM+;;SyyRJtN6#_sVt%>;*B1kUYImE ze=;&{uxz5`oI!x10T9tcson$p1Olc~i5C!6Lq$bqMLX6p6m`SCWAMawiSfOH#!pPB zspv#}7ddF(p}tQyDN~K_l8!n1(JYGsi_d-|yIS_}_S?Fzq{Sz0X0_sm*fj?D{ zTdU_b)E<=yyIHU@phC7yzG*Ld+6=0H$eo8}LCN}l`6l%Y7?f#lg>7YReyJ8S)vRIA zC?!wcBA}d%HbRjymC|I|bZg`BOsd8cqcY(OByV#|`V}X3zwIGV;2g`V0dZ{U*S?J^ zF?X!C=X2yJpbfbl878F9^nba%OH+=~S@6*5dBe4YK*myk;h8Xd+pTIwPW&7Hb#wpsX!RJ31%o#V)U zC5!1d=F7|3OY~tPDPN%sfE58WfDXHQ#0Y%ODFp!2xT0ts1t3T6S0|`bMQ2nLl6u>b zr_CI3RKu=_GS>k}$>W%Vr(HpA@gqk?%mtyB0d!(emHko6;AZtX`Vo-yX=e}yVIp=! z69Gmmh-Pr6uy=L@3y6X%EN+O@`lv0)`72Z@ejrqAB?^)POmpF;7&c?1SuvKFm-qlA zF(pOJ1OOU{EdgllkDg;#{2GEdDbg-%niDbRT>R1l02J;T-?!A z*7xPb*Ttg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94@)``t zMMe6KT9lpcYcB14pm@48M9?`iR)2wMT+oNyD&LMR;Mds4s|}YMBF1*eouI3x$Gxra ziIc#qwUApz^~g!ZwCwPz*`DD+N5n`%ZSQXR#^JQa`@%33%G6BEA{WGd<20_FSrx#Q z%H`^{z1sqEcX#0mPVB3_QIL^Lm6}-Lji&P$5W`r6_!?8T7S6c0{71n<5PwvKUeLk! zs8RHYGksx8G`RAu=RRz;kTxcH;vGt5E6;!O1o7(}5vN!n^j{Qi@6{4y%dnGi7g)gi z_xOD%yqQ(ft1nI3^lwT;)^TH9oI+@<9BEE8JA^Ab1YUfxy-7!wNh8a@5mOyD`nbq3QVb*{GKTXMTn>gKJkgtdt%YY+zq<5FB%H3o)@ zt_jzZT%|y$dkQ-ZQeXgCQ5*?>Yy~pswB9>XgD%<~tdZD)ixtJ)GF00c51@JMXB{OLr6;r!2UZgpSJSr~oak50XP}lSnu|b(uFyuDj;sH?^IfVVry~2^%_yb!+Y$QQ&KyLc92x&r?>0e zp_tkSx#}$AYC9z|(C;~s73f8CX~fUbbe(?l>f;Ey^{$--Z_4WDITd_mp4~`T9*Q@M zm8GC(1nk5rEvg zrqxg4Ihfi77LBEFme1q2arui{@qp*aJ1&PQaY75B6i#zroH;fJZqkpMPKKs-%FjZ0 z3Zf)KZ6?eGLK{?;F6YW2iK&&Jz(ac;<)s3?t14Rp@5!ULM-XEw$}0c-Y)ZeA7q1Z2 G5BMJ&eKw&0 literal 0 HcmV?d00001 diff --git a/README.md b/README.md index 0728647..cfe3109 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,19 @@ SpeedLog.mode = .AllOptions SpeedLog.print("Enable All Features") //2015-11-26 19:32:33.687 AppDelegate.myFunc()[27]: Enable All Features ``` +### UIColor log +SpeedLog has nice UIColor representation in Console + +![](/Images/RGB-colors-log.png) + +```swift +SpeedLog.enableVisualColorLog() +SpeedLog.print("Visual:", c) + +SpeedLog.disableVisualColorLog() +SpeedLog.print("Original Restored:", c) +``` + ###Enables Log From e0de25f083dd72cd5068b100caf2a2d9647c4dcd Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sat, 28 Nov 2015 15:44:27 +0100 Subject: [PATCH 12/13] readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cfe3109..c512fd8 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,8 @@ SpeedLog.print("Enable All Features") //2015-11-26 19:32:33.687 AppDelegate.myFunc()[27]: Enable All Features ``` ### UIColor log -SpeedLog has nice UIColor representation in Console - +`SpeedLog` has nice `UIColor` log style. +All you need to do is enable it once by calling `SpeedLog.enableVisualColorLog()` ![](/Images/RGB-colors-log.png) ```swift From 60159a3b4affd73224fd56f3b6f9d0ce31b9cf32 Mon Sep 17 00:00:00 2001 From: Kostiantyn Koval Date: Sat, 28 Nov 2015 15:49:28 +0100 Subject: [PATCH 13/13] add alcatraz and XcodeColoers to readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c512fd8..6ff6365 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ SpeedLog.print("Enable All Features") ### UIColor log `SpeedLog` has nice `UIColor` log style. All you need to do is enable it once by calling `SpeedLog.enableVisualColorLog()` + ![](/Images/RGB-colors-log.png) ```swift @@ -62,7 +63,7 @@ SpeedLog.print("Visual:", c) SpeedLog.disableVisualColorLog() SpeedLog.print("Original Restored:", c) ``` - +P.S - You also need to install [XcodeColors](https://github.com/robbiehanson/XcodeColors) Xcode Plugin. Use [Alcatraz](http://alcatraz.io) to install it. ###Enables Log