diff --git a/Source/SpeedLog.swift b/Source/SpeedLog.swift index 47c0114..a991fe0 100644 --- a/Source/SpeedLog.swift +++ b/Source/SpeedLog.swift @@ -12,31 +12,37 @@ typealias SLog = SpeedLog ///LogMode type. Specify what details should be included to the log public struct LogMode : OptionSetType { - + private var value: UInt = 0 - - public init(_ value: UInt) { self.value = value } + public var rawValue: UInt { return value } + public init(rawValue value: UInt) { self.value = value } - public init(nilLiteral: ()) { self.value = 0 } - - public static var allZeros: LogMode { return self.init(0) } - public var rawValue: UInt { return self.value } - + public init(_ value: UInt) { self.value = value } + //MARK:- Options - public static var None: LogMode { return self.init(0) } - public static var FileName: LogMode { return self.init(1 << 0) } - public static var FuncName: LogMode { return self.init(1 << 1) } - public static var Line: LogMode { return self.init(1 << 2) } + 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) /// AllOptions - Enable all options, [FileName, FuncName, Line] - public static var AllOptions: LogMode { return [FileName, FuncName, Line] } + public static var AllOptions: LogMode = [FileName, FuncName, Line] } + ///SpeedLog Type public struct SpeedLog { /// Log Mode public static var mode: LogMode = .None + /** + print items to the console + + - parameter items: items to print + - parameter separator: separator between items. Default is space" " + - parameter terminator: a character inserted at the end of output. + */ + 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 = printStringForMode(file, function: function, line: line) @@ -48,6 +54,9 @@ public struct SpeedLog { extension SpeedLog { + /** + Creates an output string for the currect log Mode + */ static func printStringForMode(file: String, function: String, line: Int) -> String { var result: String = "" if mode.contains(.FileName) { diff --git a/Tests/SpeedLogTests.swift b/Tests/SpeedLogTests.swift index 3248980..9f8d58e 100644 --- a/Tests/SpeedLogTests.swift +++ b/Tests/SpeedLogTests.swift @@ -29,7 +29,12 @@ class SpeedLogTests: XCTestCase { func testLinePrefix() { let prefix = logForMode(.Line) - XCTAssertEqual(prefix, "[\(10)]: ") + XCTAssertEqual(prefix, "[10]: ") + } + + func testAllOptionsPrefix() { + let prefix = logForMode(.AllOptions) + XCTAssertEqual(prefix, "File.FuncA[10]: ") } }