Created
October 6, 2023 23:25
-
-
Save MaisaMilena/b8a7b053a7097448f09bd42381d4b8a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public protocol Logger: AnyObject { | |
static func info(_ message: String, file: StaticString, function: StaticString) | |
static func event(_ message: String, file: StaticString, function: StaticString) | |
static func error(_ message: String, file: StaticString, function: StaticString) | |
} | |
final class Sentinel: Logger { | |
static func info( | |
_ message: String, | |
file: StaticString = #file, | |
function: StaticString = #function | |
) { | |
log(level: "ℹ️", message: message, file: file, function: function) | |
} | |
static func event( | |
_ message: String, | |
file: StaticString = #file, | |
function: StaticString = #function | |
) { | |
log(level: "📝", message: message, file: file, function: function) | |
} | |
static func error( | |
_ message: String, | |
file: StaticString = #file, | |
function: StaticString = #function | |
) { | |
log(level: "😱", message: message, file: file, function: function) | |
} | |
// swiftlint:disable print_function_usage | |
private static func log( | |
level: String, | |
message: String = "", | |
file: StaticString = #file, | |
function: StaticString = #function | |
) { | |
let fileName = (String(describing: file) as NSString).lastPathComponent | |
print("[\(level)] \(fileName) - \(function) -> \(message)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment