mac/log: properly guard logger usage behind platform version check

This commit is contained in:
der richter 2024-06-09 14:41:10 +02:00
parent 1acb49f9c6
commit b390ade709
1 changed files with 11 additions and 2 deletions

View File

@ -20,7 +20,12 @@ import os
class LogHelper {
var log: OpaquePointer?
let logger = Logger(subsystem: "io.mpv", category: "mpv")
#if HAVE_MACOS_11_FEATURES
@available(macOS 11.0, *)
var logger: Logger? {
return Logger(subsystem: "io.mpv", category: "mpv")
}
#endif
let loggerMapping: [Int: OSLogType] = [
MSGL_V: .debug,
@ -51,7 +56,11 @@ class LogHelper {
func send(message: String, type: Int) {
guard let log = log else {
logger.log(level: loggerMapping[type] ?? .default, "\(message, privacy: .public)")
#if HAVE_MACOS_11_FEATURES
if #available(macOS 11.0, *) {
logger?.log(level: loggerMapping[type] ?? .default, "\(message, privacy: .public)")
}
#endif
return
}