44 lines
923 B
Swift
44 lines
923 B
Swift
//
|
|
// SDLLogger.swift
|
|
// Tun
|
|
//
|
|
// Created by 安礼成 on 2024/3/13.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public class SDLLogger: @unchecked Sendable {
|
|
public enum Level: Int8, CustomStringConvertible {
|
|
case debug = 0
|
|
case info = 1
|
|
case warning = 2
|
|
case error = 3
|
|
|
|
public var description: String {
|
|
switch self {
|
|
case .debug:
|
|
return "Debug"
|
|
case .info:
|
|
return "Info"
|
|
case .warning:
|
|
return "Warning"
|
|
case .error:
|
|
return "Error"
|
|
}
|
|
}
|
|
}
|
|
|
|
private let level: Level
|
|
|
|
public init(level: Level) {
|
|
self.level = level
|
|
}
|
|
|
|
public func log(_ message: String, level: Level = .debug) {
|
|
if self.level.rawValue <= level.rawValue {
|
|
NSLog("\(level.description): \(message)")
|
|
}
|
|
}
|
|
|
|
}
|