// // LogManager.swift // AIGrammar // // Created by oscar on 2024/7/3. // import Foundation import SwiftyBeaver let logger = SwiftyBeaver.self func setupLogging() { let console = ConsoleDestination() let file = FileDestination() //file.logFileURL = URL(fileURLWithPath: "/path/to/your/log/file.log") // use custom format and set console output to short time, log level & message // console.format = "$DHH:mm:ss$d $L $M" // or use this for JSON output: // console.format = "$J" // In Xcode 15, specifying the logging method as .logger to display color, subsystem, and category information in the console.(Relies on the OSLog API) //console.logPrintWay = .logger(subsystem: "Main", category: "UI") // If you prefer not to use the OSLog API, you can use print instead. // console.logPrintWay = .print console.format = "$DHH:mm:ss$d $C$L$c $N.$F:$l - $M" file.format = "$Dyyyy-MM-dd HH:mm:ss.SSS$d $C$L$c $N.$F:$l - $M" // 自定义颜色 console.levelColor.verbose = "⚪️ " // White console.levelColor.debug = "🔵 " // Blue console.levelColor.info = "🟢 " // Green console.levelColor.warning = "🟡 " // Yellow console.levelColor.error = "🔴 " // Red logger.addDestination(console) logger.addDestination(file) } // 获取日志文件路径 func getLogFileURL() -> URL? { return logger.destinations .compactMap { $0 as? FileDestination } .first?.logFileURL // 获取第一个FileDestination的日志文件URL }