//
//  SDLLogger.swift
//  Tun
//
//  Created by 安礼成 on 2024/3/13.
//
import Foundation
import os

public class SDLLogger: @unchecked Sendable {
    
    public enum Subsystem: String, CaseIterable {
        case debug = "com.jihe.punchnet.debug"
        case trace = "com.jihe.punchnet.trace"
    }
    
    private static var loggers: [String: SDLLogger] {
        var loggers: [String: SDLLogger] = [:]
        for sub in Subsystem.allCases {
            loggers[sub.rawValue] = .init(subsystem: sub)
        }
        return loggers
    }
    
    private let log: Logger
    
    private init(subsystem: Subsystem) {
        self.log = Logger(subsystem: subsystem.rawValue, category: "punchnet")
    }
    
    public func _log(_ message: String) {
        self.log.info("\(message, privacy: .public)")
    }
    
    public static func log(_ message: String, for system: Subsystem = .debug) {
        if let logger = loggers[system.rawValue] {
            logger._log(message)
        }
    }
}
