//
//  LKFLog.swift
//  LKF
//
//  Created by Alexander Holzer on 07.07.25.
//  Copyright © 2025 Alexander Holzer. All rights reserved.
//

import Foundation

open class LKFLog {
    
    let logFunction: ((String,String?,String?,String)->Void)?
    static public private(set) var current: LKFLog?
    
    
    public init (logFunction: ((String,String?,String?, String)->Void)? = nil) {
        self.logFunction = logFunction
        LKFLog.current = self
    }

    open func log (_ message: String, details: String? = nil, severity: String = "info", facility: String = "lkf") {
        self.logFunction?(message, details, facility, severity)
    }
    
    public func error (_ message: String, details: String? = nil, facility: String = "lkf") {
        self.logFunction?(message, details, "error", facility)
    }
    
    public func warning (_ message: String, details: String? = nil, facility: String = "lkf") {
        self.logFunction?(message, details, "warning", facility)
    }
    
    public func debug (_ message: String, facility: String = "lkf") {
        log (message, severity: "debug", facility: facility)
    }
    
    public func log (error: LKFError) {
        self.log(error.localizedDescription, details: error.errorDescription, severity: "error")
    }
    
    public func log (_ message: String, error: LKFError, severity: String = "error") {
        self.log(message, details: error.localizedDescription, severity: severity)
    }
}
