Skip to content

Instantly share code, notes, and snippets.

@MaisaMilena
Created October 6, 2023 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaisaMilena/b8a7b053a7097448f09bd42381d4b8a9 to your computer and use it in GitHub Desktop.
Save MaisaMilena/b8a7b053a7097448f09bd42381d4b8a9 to your computer and use it in GitHub Desktop.
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