diff --git a/Example/Example-iOS/AppDelegate.swift b/Example/Example-iOS/AppDelegate.swift
index b83e250..e1af7c7 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
}
@@ -32,7 +33,26 @@ 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)
+
+ SpeedLog.enableVisualColorLog()
+ SpeedLog.print("Visual:", c)
+
+ SpeedLog.disableVisualColorLog()
+ SpeedLog.print("Original Restored:", c)
+ }
}
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..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";
@@ -431,7 +423,7 @@
B5BA46DE1BFF668700EC5A0D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
- OTHER_SWIFT_FLAGS = "-D ENABLE_LOG";
+ OTHER_SWIFT_FLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
@@ -439,6 +431,7 @@
B5BA46DF1BFF668700EC5A0D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ OTHER_SWIFT_FLAGS = "-D DISABLE_LOG";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
diff --git a/Example/MyPlayground.playground/Contents.swift b/Example/MyPlayground.playground/Pages/Playground.xcplaygroundpage/Contents.swift
similarity index 100%
rename from Example/MyPlayground.playground/Contents.swift
rename to Example/MyPlayground.playground/Pages/Playground.xcplaygroundpage/Contents.swift
diff --git a/Example/MyPlayground.playground/timeline.xctimeline b/Example/MyPlayground.playground/Pages/Playground.xcplaygroundpage/timeline.xctimeline
similarity index 100%
rename from Example/MyPlayground.playground/timeline.xctimeline
rename to Example/MyPlayground.playground/Pages/Playground.xcplaygroundpage/timeline.xctimeline
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..80ba828
--- /dev/null
+++ b/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/Contents.swift
@@ -0,0 +1,27 @@
+//: [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 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")
+//2015-11-26 19:32:33.687 AppDelegate.myFunc()[27]: Enable All Features
diff --git a/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/timeline.xctimeline b/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/timeline.xctimeline
new file mode 100644
index 0000000..bf468af
--- /dev/null
+++ b/Example/MyPlayground.playground/Pages/Readme.xcplaygroundpage/timeline.xctimeline
@@ -0,0 +1,6 @@
+
+
+
+
+
diff --git a/Example/MyPlayground.playground/contents.xcplayground b/Example/MyPlayground.playground/contents.xcplayground
index 5da2641..1bf63f9 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/Images/RGB-colors-log.png b/Images/RGB-colors-log.png
new file mode 100644
index 0000000..ef72795
Binary files /dev/null and b/Images/RGB-colors-log.png differ
diff --git a/README.md b/README.md
index 3d31c34..6ff6365 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
@@ -28,22 +30,40 @@ 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
```
+### 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
+SpeedLog.enableVisualColorLog()
+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
@@ -84,6 +104,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:
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/SpeedLog.swift b/Source/SpeedLog.swift
index 0eec570..ec02b30 100644
--- a/Source/SpeedLog.swift
+++ b/Source/SpeedLog.swift
@@ -13,20 +13,19 @@ 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 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 let AllOptions: LogMode = [Date, FileName, FuncName, Line]
+ public static let FullCodeLocation: LogMode = [FileName, FuncName, Line]
}
@@ -44,8 +43,8 @@ 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
- let prefix = modePrefix(file, function: function, line: line)
+ #if !DISABLE_LOG
+ let prefix = modePrefix(NSDate(), file: file, function: function, line: line)
let stringItem = items.map {"\($0)"} .joinWithSeparator(separator)
Swift.print("\(prefix)\(stringItem)", terminator: terminator)
#endif
@@ -54,14 +53,19 @@ public struct SpeedLog {
extension SpeedLog {
- /**
- Creates an output string for the currect log Mode
- */
- static func modePrefix(file: String, function: String, line: Int) -> String {
+ /// 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) {
+ 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)"
@@ -71,6 +75,7 @@ extension SpeedLog {
}
if !result.isEmpty {
+ result = result.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
result += ": "
}
@@ -78,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/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..bbd22f5
--- /dev/null
+++ b/Source/UIColor+Log.swift
@@ -0,0 +1,69 @@
+//
+// UIColor+Log.swift
+// SpeedLog
+//
+// Created by Kostiantyn Koval on 23/11/15.
+// Copyright © 2015 Kostiantyn Koval. All rights reserved.
+//
+
+import UIKit
+
+// MARK: - Decription Swizzling
+extension UIColor {
+
+ /// Swizzle description method with own colorDescription.
+ /// colorDescription will used instead of description
+ class func swizzleDescription() {
+ let instance = UIColor.redColor()
+ instance.swizzleMethods("description", withSelector: "colorDescription")
+ }
+
+ /// Restore back original description method
+ class func undoDesriptionSwizzling() {
+ 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: RGBColorType {
+ //Color representation for XcodeColors console log
+ var colorCode: String {
+ return "\(R),\(G),\(B)"
+ }
+}
+
+// MARK: - UIColor
+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) - " + ColorLog.background(color, object: " ")
+ }
+}
+
+
+
+
diff --git a/SpeedLog.xcodeproj/project.pbxproj b/SpeedLog.xcodeproj/project.pbxproj
index e8c2d26..e4bf6cf 100644
--- a/SpeedLog.xcodeproj/project.pbxproj
+++ b/SpeedLog.xcodeproj/project.pbxproj
@@ -7,10 +7,15 @@
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, ); }; };
B5BA46861BFF625500EC5A0D /* SpeedLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BA46831BFF625500EC5A0D /* SpeedLog.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 */
/* Begin PBXContainerItemProxy section */
@@ -24,6 +29,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 = ""; };
@@ -31,6 +37,10 @@
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 = ""; };
+ 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 */
/* Begin PBXFrameworksBuildPhase section */
@@ -74,6 +84,8 @@
isa = PBXGroup;
children = (
B5BA46701BFF596C00EC5A0D /* SpeedLogTests.swift */,
+ B5CD588B1C09E71D00E4238C /* ColorLogTest.swift */,
+ B518B4481C078F8900C6DA04 /* LogModeTests.swift */,
B5BA46721BFF596C00EC5A0D /* Info.plist */,
);
path = Tests;
@@ -83,6 +95,9 @@
isa = PBXGroup;
children = (
B5BA46831BFF625500EC5A0D /* SpeedLog.swift */,
+ B5FB59951C039E2C00B12B4D /* ColorLog.swift */,
+ B5FB59971C039F1E00B12B4D /* UIColor+Log.swift */,
+ B5FB599A1C04F07C00B12B4D /* Swizzling.swift */,
B5BA46871BFF627400EC5A0D /* Supporting Files */,
);
path = Source;
@@ -206,6 +221,9 @@
buildActionMask = 2147483647;
files = (
B5BA46861BFF625500EC5A0D /* SpeedLog.swift in Sources */,
+ B5FB59981C039F1E00B12B4D /* UIColor+Log.swift in Sources */,
+ B5FB59961C039E2C00B12B4D /* ColorLog.swift in Sources */,
+ B5FB599B1C04F07C00B12B4D /* Swizzling.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -213,7 +231,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ B5CD588C1C09E71D00E4238C /* ColorLogTest.swift in Sources */,
B5BA46711BFF596C00EC5A0D /* SpeedLogTests.swift in Sources */,
+ B518B4491C078F8900C6DA04 /* LogModeTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -327,7 +347,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 +364,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;
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)
+ }
+
+}
diff --git a/Tests/LogModeTests.swift b/Tests/LogModeTests.swift
new file mode 100644
index 0000000..f1fd77f
--- /dev/null
+++ b/Tests/LogModeTests.swift
@@ -0,0 +1,34 @@
+//
+// 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)
+ }
+
+ func testAggregationCase() {
+ XCTAssertEqual(LogMode.FullCodeLocation, [.FileName, .FuncName, .Line])
+ XCTAssertEqual(LogMode.AllOptions, [.Date, .FileName, .FuncName, .Line])
+ }
+}
diff --git a/Tests/SpeedLogTests.swift b/Tests/SpeedLogTests.swift
index 083a4cd..7ea3c03 100644
--- a/Tests/SpeedLogTests.swift
+++ b/Tests/SpeedLogTests.swift
@@ -32,9 +32,20 @@ class SpeedLogTests: XCTestCase {
XCTAssertEqual(prefix, "[10]: ")
}
+ func testDatePrefix() {
+ let prefix = logForMode(.Date)
+ 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
}
}
@@ -43,7 +54,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)!
}
}
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")
- }
-
-
-}