//
//  LNLogger.swift
//  Lanu
//
//  Created by OneeChan on 2025/11/11.
//

import Foundation
import CocoaLumberjackSwift

/// 日志工具类，基于 CocoaLumberjack 实现，支持类似 print 的参数格式
enum Log {
    private static func buildLogMessage(items: Any..., separator: String) -> String {
        let logs = items.map { String(describing: $0) }
        return logs.joined(separator: separator)
    }
    
    static func v(
        _ items: Any...,
        separator: String = " ",
        terminator: String = "\n",
        file: StaticString = #file,
        function: StaticString = #function,
        line: UInt = #line
    ) {
        DDLogVerbose("\(buildLogMessage(items: items, separator: separator))", level: .verbose, file: file, function: function, line: line)
    }
    
    static func d(
        _ items: Any...,
        separator: String = " ",
        terminator: String = "\n",
        file: StaticString = #file,
        function: StaticString = #function,
        line: UInt = #line
    ) {
        DDLogDebug("\(buildLogMessage(items: items, separator: separator))", level: .debug, file: file, function: function, line: line)
    }
    
    static func i(
        _ items: Any...,
        separator: String = " ",
        terminator: String = "\n",
        file: StaticString = #file,
        function: StaticString = #function,
        line: UInt = #line
    ) {
        DDLogInfo("\(buildLogMessage(items: items, separator: separator))", level: .info, file: file, function: function, line: line)
    }
    
    static func w(
        _ items: Any...,
        separator: String = " ",
        terminator: String = "\n",
        file: StaticString = #file,
        function: StaticString = #function,
        line: UInt = #line
    ) {
        DDLogWarn("\(buildLogMessage(items: items, separator: separator))", level: .warning, file: file, function: function, line: line)
    }
    
    static func e(
        _ items: Any...,
        separator: String = " ",
        terminator: String = "\n",
        file: StaticString = #file,
        function: StaticString = #function,
        line: UInt = #line
    ) {
        DDLogError("\(buildLogMessage(items: items, separator: separator))", level: .error, file: file, function: function, line: line)
    }
}
