diff options
author | der richter <der.richter@gmx.de> | 2024-03-30 20:22:53 +0100 |
---|---|---|
committer | der richter <der.richter@gmx.de> | 2024-04-01 22:13:39 +0200 |
commit | fc978eb9f20b61d10718d82e4690de26ef2f9303 (patch) | |
tree | 7775ab241f7bec97a924eb6b393e85105e707145 /osdep/mac/log_helper.swift | |
parent | 7619cceb875da939f26b02ae3e1b2f5b3d0f103c (diff) | |
download | mpv-fc978eb9f20b61d10718d82e4690de26ef2f9303.tar.bz2 mpv-fc978eb9f20b61d10718d82e4690de26ef2f9303.tar.xz |
mac/log: fallback to system logger if no mp_log is yet available
since cocoa is initialising mpv and does several things before the mpv
core does anything and the mpv_handle was passed to the App, this can be
used to log such things before the mpv logging is available. helpful for
debugging especially bundle related things.
the logger mapping looks a bit unintuitive but error is basically yellow
what our warning is and fatal is red what our error is.
Diffstat (limited to 'osdep/mac/log_helper.swift')
-rw-r--r-- | osdep/mac/log_helper.swift | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/osdep/mac/log_helper.swift b/osdep/mac/log_helper.swift index 98bc19c221..0f65975da1 100644 --- a/osdep/mac/log_helper.swift +++ b/osdep/mac/log_helper.swift @@ -16,11 +16,20 @@ */ import Cocoa +import os class LogHelper { var log: OpaquePointer? + let logger = Logger(subsystem: "io.mpv", category: "mpv") - init(_ log: OpaquePointer?) { + let loggerMapping: [Int:OSLogType] = [ + MSGL_V: .debug, + MSGL_INFO: .info, + MSGL_WARN: .error, + MSGL_ERR: .fault, + ] + + init(_ log: OpaquePointer? = nil) { self.log = log } @@ -41,6 +50,11 @@ class LogHelper { } func send(message: String, type: Int) { + guard let log = log, UnsafeRawPointer(log).load(as: UInt8.self) != 0 else { + logger.log(level: loggerMapping[type] ?? .default, "\(message, privacy: .public)") + return + } + let args: [CVarArg] = [(message as NSString).utf8String ?? "NO MESSAGE"] mp_msg_va(log, Int32(type), "%s\n", getVaList(args)) } |