//
//  LNLoggerFormater.swift
//  Lanu
//
//  Created by OneeChan on 2025/11/7.
//

import Foundation
import CocoaLumberjack

class LNLoggerFormater: NSObject, DDLogFormatter {
    private let formatter = DateFormatter()
    
    override init() {
        super.init()
        
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
    }
    
    func format(message logMessage: DDLogMessage) -> String? {
        let timeStr = formatter.string(from: logMessage.timestamp)
        
        let levelStr = switch logMessage.level {
        case .verbose: "V"
        case .debug: "D"
        case .info: "I"
        case .warning: "W"
        case .error: "E"
        default: "?"
        }
        
        let function = logMessage.function ?? ""
        let line = logMessage.line
        
        return String(format: "[%@] [%@] %@:%ld %@", timeStr, levelStr, function, line, logMessage.message)
    }
}
