Created
August 2, 2021 20:05
-
-
Save ajjames/ce4827b2cbe9b18d135eafade2ae3e29 to your computer and use it in GitHub Desktop.
Common Logger
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 | |
import os.log | |
protocol Logger { | |
func error(_ error: String) | |
func warning(_ warning: String) | |
func event(_ event: String) | |
func message(_ message: String) | |
} | |
enum Log { | |
static var shared = { UnifiedLogger() }() | |
} | |
struct UnifiedLogger: Logger { | |
func error(_ error: String) { | |
let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "", category: "error") | |
os_log("%{public}@", log: log, type: .error, "❌ \(error)") | |
} | |
func warning(_ warning: String) { | |
let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "", category: "warning") | |
os_log("%{public}@", log: log, type: .default, "⚠️ \(warning)") | |
} | |
func event(_ event: String) { | |
let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "", category: "event") | |
os_log("%{public}@", log: log, type: .info, "ℹ️ \(event)") | |
} | |
func message(_ message: String) { | |
let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "", category: "message") | |
os_log("%{public}@", log: log, type: .info, "💬 \(message)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment