Skip to content

Instantly share code, notes, and snippets.

@ajjames
Created August 2, 2021 20:05
Show Gist options
  • Save ajjames/ce4827b2cbe9b18d135eafade2ae3e29 to your computer and use it in GitHub Desktop.
Save ajjames/ce4827b2cbe9b18d135eafade2ae3e29 to your computer and use it in GitHub Desktop.
Common Logger
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