diff --git a/Sources/BlackBox/BlackBox.swift b/Sources/BlackBox/BlackBox.swift index c04563b..80388b4 100644 --- a/Sources/BlackBox/BlackBox.swift +++ b/Sources/BlackBox/BlackBox.swift @@ -173,6 +173,142 @@ extension BlackBox { ) { BlackBox.instance.logEnd(event) } + + // MARK: - Level in function name + + /// Logs debug message + /// - Parameters: + /// - message: Message to log + /// - userInfo: Additional info you'd like to see alongside log + /// - serviceInfo: to be deleted + /// - category: Category of log. E.g. View Lifecycle. + /// - parentEvent: Parent log of current log. May be useful for traces. + /// - fileID: The fileID where the logs occurs. Containts module name and filename. The default is the fileID of the function where you call log. + /// - function: The function where the logs occurs. The default is the function name from where you call log. + /// - line: The line where the logs occurs. The default is the line in function from where you call log. + public static func debug( + _ message: StaticString, + userInfo: BBUserInfo? = nil, + serviceInfo: BBServiceInfo? = nil, + category: String? = nil, + parentEvent: GenericEvent? = nil, + fileID: StaticString = #fileID, + function: StaticString = #function, + line: UInt = #line + ) { + BlackBox.instance.log( + message, + userInfo: userInfo, + serviceInfo: serviceInfo, + level: .debug, + category: category, + parentEvent: parentEvent, + fileID: fileID, + function: function, + line: line + ) + } + + /// Logs info message + /// - Parameters: + /// - message: Message to log + /// - userInfo: Additional info you'd like to see alongside log + /// - serviceInfo: to be deleted + /// - category: Category of log. E.g. View Lifecycle. + /// - parentEvent: Parent log of current log. May be useful for traces. + /// - fileID: The fileID where the logs occurs. Containts module name and filename. The default is the fileID of the function where you call log. + /// - function: The function where the logs occurs. The default is the function name from where you call log. + /// - line: The line where the logs occurs. The default is the line in function from where you call log. + public static func info( + _ message: StaticString, + userInfo: BBUserInfo? = nil, + serviceInfo: BBServiceInfo? = nil, + category: String? = nil, + parentEvent: GenericEvent? = nil, + fileID: StaticString = #fileID, + function: StaticString = #function, + line: UInt = #line + ) { + BlackBox.instance.log( + message, + userInfo: userInfo, + serviceInfo: serviceInfo, + level: .info, + category: category, + parentEvent: parentEvent, + fileID: fileID, + function: function, + line: line + ) + } + + /// Logs measurement start with debug level + /// - Parameters: + /// - message: Measurement name + /// - userInfo: Additional info you'd like to see alongside log + /// - serviceInfo: to be deleted + /// - category: Category of log. E.g. View Lifecycle. + /// - parentEvent: Parent log of current log. May be useful for traces. + /// - fileID: The fileID where the logs occurs. Containts module name and filename. The default is the fileID of the function where you call log. + /// - function: The function where the logs occurs. The default is the function name from where you call log. + /// - line: The line where the logs occurs. The default is the line in function from where you call log. + /// - Returns: Started measurement + public static func debugStart( + _ message: StaticString, + userInfo: BBUserInfo? = nil, + serviceInfo: BBServiceInfo? = nil, + category: String? = nil, + parentEvent: GenericEvent? = nil, + fileID: StaticString = #fileID, + function: StaticString = #function, + line: UInt = #line + ) -> StartEvent { + BlackBox.instance.logStart( + message, + userInfo: userInfo, + serviceInfo: serviceInfo, + level: .debug, + category: category, + parentEvent: parentEvent, + fileID: fileID, + function: function, + line: line + ) + } + + /// Logs measurement start with info level + /// - Parameters: + /// - message: Measurement name + /// - userInfo: Additional info you'd like to see alongside log + /// - serviceInfo: to be deleted + /// - category: Category of log. E.g. View Lifecycle. + /// - parentEvent: Parent log of current log. May be useful for traces. + /// - fileID: The fileID where the logs occurs. Containts module name and filename. The default is the fileID of the function where you call log. + /// - function: The function where the logs occurs. The default is the function name from where you call log. + /// - line: The line where the logs occurs. The default is the line in function from where you call log. + /// - Returns: Started measurement + public static func infoStart( + _ message: StaticString, + userInfo: BBUserInfo? = nil, + serviceInfo: BBServiceInfo? = nil, + category: String? = nil, + parentEvent: GenericEvent? = nil, + fileID: StaticString = #fileID, + function: StaticString = #function, + line: UInt = #line + ) -> StartEvent { + BlackBox.instance.logStart( + message, + userInfo: userInfo, + serviceInfo: serviceInfo, + level: .info, + category: category, + parentEvent: parentEvent, + fileID: fileID, + function: function, + line: line + ) + } } // MARK: - Instance diff --git a/Tests/BlackBoxTests/BackwardsCompatibilityTests.swift b/Tests/BlackBoxTests/BackwardsCompatibilityTests.swift index ba21f42..ef55b02 100644 --- a/Tests/BlackBoxTests/BackwardsCompatibilityTests.swift +++ b/Tests/BlackBoxTests/BackwardsCompatibilityTests.swift @@ -86,6 +86,15 @@ class PublicApiTests: XCTestCase { function: #function, line: #line ) + + BlackBox.debug("Message") + BlackBox.info("Message") + + let startEventDebug = BlackBox.debugStart("Message") + BlackBox.logEnd(startEventDebug) + + let startEventInfo = BlackBox.infoStart("Message") + BlackBox.logEnd(startEventInfo) } func test_events() { diff --git a/Tests/BlackBoxTests/BlackBoxGenericEventTests.swift b/Tests/BlackBoxTests/BlackBoxGenericEventTests.swift index e2d9d98..42007c1 100644 --- a/Tests/BlackBoxTests/BlackBoxGenericEventTests.swift +++ b/Tests/BlackBoxTests/BlackBoxGenericEventTests.swift @@ -30,6 +30,16 @@ class BlackBoxGenericEventTests: BlackBoxTestCase { XCTAssertEqual(testableLogger.genericEvent?.level, .warning) } + func test_levelInFuncNameDebug() { + BlackBox.debug("Test") + XCTAssertEqual(testableLogger.genericEvent?.level, .debug) + } + + func test_levelInFuncNameInfo() { + BlackBox.info("Test") + XCTAssertEqual(testableLogger.genericEvent?.level, .info) + } + func test_defaultLevel() { BlackBox.log("Test") XCTAssertEqual(testableLogger.genericEvent?.level, .debug) @@ -73,7 +83,7 @@ class BlackBoxGenericEventTests: BlackBoxTestCase { func test_line() { BlackBox.log("Test") - XCTAssertEqual(testableLogger.genericEvent?.source.line, 75) + XCTAssertEqual(testableLogger.genericEvent?.source.line, 85) } func test_durationFormattedIsNil() { diff --git a/Tests/BlackBoxTests/BlackBoxStartEventTests.swift b/Tests/BlackBoxTests/BlackBoxStartEventTests.swift index add5a86..e129a45 100644 --- a/Tests/BlackBoxTests/BlackBoxStartEventTests.swift +++ b/Tests/BlackBoxTests/BlackBoxStartEventTests.swift @@ -39,6 +39,16 @@ class BlackBoxStartEventTests: BlackBoxTestCase { XCTAssertEqual(testableLogger.startEvent?.level, .warning) } + func test_levelInFuncNameDebug() { + let _ = BlackBox.debugStart("Test") + XCTAssertEqual(testableLogger.startEvent?.level, .debug) + } + + func test_levelInFuncNameInfo() { + let _ = BlackBox.infoStart("Test") + XCTAssertEqual(testableLogger.startEvent?.level, .info) + } + func test_defaultLevel() { let _ = BlackBox.logStart("Test") XCTAssertEqual(testableLogger.startEvent?.level, .debug) @@ -77,7 +87,7 @@ class BlackBoxStartEventTests: BlackBoxTestCase { func test_line() { let _ = BlackBox.logStart("Test") - XCTAssertEqual(testableLogger.startEvent?.source.line, 79) + XCTAssertEqual(testableLogger.startEvent?.source.line, 89) } func test_durationFormattedIsNil() {