Files
SwiftChain/SwiftChainCore/Models/LogManager.swift
2025-05-05 16:58:52 +02:00

39 lines
1.1 KiB
Swift

//
// LogManager.swift
// SwiftChain
//
// Created by Victor on 05/05/2025.
//
import os.log
public struct LogManager {
public enum LogLevel: String {
case info = "INFO"
case success = "SUCCÈS"
case warning = "ATTENTION"
case error = "ERREUR"
case network = "RÉSEAU"
case blockchain = "BLOCKCHAIN"
var logType: OSLogType {
switch self {
case .info, .success: return .info
case .warning: return .debug
case .error: return .error
case .network, .blockchain: return .default
}
}
}
static let log = OSLog(subsystem: "com.votreapp.swiftchain", category: "blockchain")
public static func log(_ message: String, level: LogLevel) {
os_log("%{public}@: %{public}@", log: log, type: level.logType, level.rawValue, message)
// Également afficher dans la console pour le CLI
let timestamp = DateFormatter.localizedString(from: Date(), dateStyle: .none, timeStyle: .medium)
print("[\(timestamp)] [\(level.rawValue)] \(message)")
}
}