Skip to content

Commit

Permalink
add more test and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kostiakoval committed Nov 21, 2015
1 parent 7bde2a1 commit fa11559
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
35 changes: 22 additions & 13 deletions Source/SpeedLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion Tests/SpeedLogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ")
}
}

Expand Down

0 comments on commit fa11559

Please sign in to comment.