Working stuff

This commit is contained in:
Hariharan Mudaliar 2026-01-14 15:11:57 +05:30
commit 94a612f327
No known key found for this signature in database
GPG key ID: 025583EB0BE5640E
13 changed files with 913 additions and 150 deletions

View file

@ -1,4 +1,5 @@
import Foundation
import OSLog
import SwiftUI
enum LogCategory: String {
@ -12,9 +13,41 @@ enum LogCategory: String {
case success = "✅"
case debug = "🔍"
case extensions = "🧩"
var osCategoryName: String {
switch self {
case .lifecycle: return "lifecycle"
case .memory: return "memory"
case .performance: return "performance"
case .ui: return "ui"
case .network: return "network"
case .error: return "error"
case .warning: return "warning"
case .success: return "success"
case .debug: return "debug"
case .extensions: return "extensions"
}
}
}
struct Logger {
private static let subsystem = "com.ebullioscopic.Atoll"
private static let dateFormatter: ISO8601DateFormatter = {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
return formatter
}()
private static var osLoggerCache: [LogCategory: OSLog] = [:]
private static func osLogger(for category: LogCategory) -> OSLog {
if let cached = osLoggerCache[category] {
return cached
}
let logger = OSLog(subsystem: subsystem, category: category.osCategoryName)
osLoggerCache[category] = logger
return logger
}
static func log(
_ message: String,
category: LogCategory,
@ -23,8 +56,14 @@ struct Logger {
line: Int = #line
) {
let fileName = (file as NSString).lastPathComponent
let timestamp = ISO8601DateFormatter().string(from: Date())
print("\(category.rawValue) [\(timestamp)] [\(fileName):\(line)] \(function) - \(message)")
let timestamp = dateFormatter.string(from: Date())
let entry = "\(category.rawValue) [\(timestamp)] [\(fileName):\(line)] \(function) - \(message)"
let logger = osLogger(for: category)
os_log("%{public}@", log: logger, type: .default, entry)
#if DEBUG
Swift.print(entry)
#endif
}
static func trackMemory(