2019-09-29 16:35:12 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Cocoa
|
2024-03-30 19:22:53 +00:00
|
|
|
import os
|
2019-09-29 16:35:12 +00:00
|
|
|
|
2024-03-26 20:50:35 +00:00
|
|
|
class LogHelper {
|
2019-09-29 16:35:12 +00:00
|
|
|
var log: OpaquePointer?
|
2024-03-30 19:22:53 +00:00
|
|
|
let logger = Logger(subsystem: "io.mpv", category: "mpv")
|
2019-09-29 16:35:12 +00:00
|
|
|
|
2024-03-30 19:22:53 +00:00
|
|
|
let loggerMapping: [Int:OSLogType] = [
|
|
|
|
MSGL_V: .debug,
|
|
|
|
MSGL_INFO: .info,
|
|
|
|
MSGL_WARN: .error,
|
|
|
|
MSGL_ERR: .fault,
|
|
|
|
]
|
|
|
|
|
|
|
|
init(_ log: OpaquePointer? = nil) {
|
2019-09-29 16:35:12 +00:00
|
|
|
self.log = log
|
|
|
|
}
|
|
|
|
|
2024-03-26 22:45:18 +00:00
|
|
|
func verbose(_ message: String) {
|
|
|
|
send(message: message, type: MSGL_V)
|
2019-09-29 16:35:12 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 22:45:18 +00:00
|
|
|
func info(_ message: String) {
|
|
|
|
send(message: message, type: MSGL_INFO)
|
2019-09-29 16:35:12 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 22:45:18 +00:00
|
|
|
func warning(_ message: String) {
|
|
|
|
send(message: message, type: MSGL_WARN)
|
2019-09-29 16:35:12 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 22:45:18 +00:00
|
|
|
func error(_ message: String) {
|
|
|
|
send(message: message, type: MSGL_ERR)
|
2019-09-29 16:35:12 +00:00
|
|
|
}
|
|
|
|
|
2024-03-26 22:45:18 +00:00
|
|
|
func send(message: String, type: Int) {
|
2024-03-30 19:22:53 +00:00
|
|
|
guard let log = log, UnsafeRawPointer(log).load(as: UInt8.self) != 0 else {
|
|
|
|
logger.log(level: loggerMapping[type] ?? .default, "\(message, privacy: .public)")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-03-26 22:45:18 +00:00
|
|
|
let args: [CVarArg] = [(message as NSString).utf8String ?? "NO MESSAGE"]
|
|
|
|
mp_msg_va(log, Int32(type), "%s\n", getVaList(args))
|
2019-09-29 16:35:12 +00:00
|
|
|
}
|
|
|
|
}
|