mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Restored files from old Mac, force pushing
This commit is contained in:
parent
5dd95228b8
commit
5040381840
126 changed files with 10431 additions and 67 deletions
77
DynamicIsland/utils/Logger.swift
Normal file
77
DynamicIsland/utils/Logger.swift
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
enum LogCategory: String {
|
||||
case lifecycle = "🔄"
|
||||
case memory = "💾"
|
||||
case performance = "⚡️"
|
||||
case ui = "🎨"
|
||||
case network = "🌐"
|
||||
case error = "❌"
|
||||
case warning = "⚠️"
|
||||
case success = "✅"
|
||||
case debug = "🔍"
|
||||
}
|
||||
|
||||
struct Logger {
|
||||
static func log(
|
||||
_ message: String,
|
||||
category: LogCategory,
|
||||
file: String = #file,
|
||||
function: String = #function,
|
||||
line: Int = #line
|
||||
) {
|
||||
let fileName = (file as NSString).lastPathComponent
|
||||
let timestamp = ISO8601DateFormatter().string(from: Date())
|
||||
print("\(category.rawValue) [\(timestamp)] [\(fileName):\(line)] \(function) - \(message)")
|
||||
}
|
||||
|
||||
static func trackMemory(
|
||||
file: String = #file,
|
||||
function: String = #function,
|
||||
line: Int = #line
|
||||
) {
|
||||
var info = mach_task_basic_info()
|
||||
var count = mach_msg_type_number_t(MemoryLayout<mach_task_basic_info>.size)/4
|
||||
|
||||
let kerr: kern_return_t = withUnsafeMutablePointer(to: &info) {
|
||||
$0.withMemoryRebound(to: integer_t.self, capacity: 1) {
|
||||
task_info(mach_task_self_,
|
||||
task_flavor_t(MACH_TASK_BASIC_INFO),
|
||||
$0,
|
||||
&count)
|
||||
}
|
||||
}
|
||||
|
||||
if kerr == KERN_SUCCESS {
|
||||
let usedMB = Double(info.resident_size) / 1024.0 / 1024.0
|
||||
log(String(format: "Memory used: %.2f MB", usedMB),
|
||||
category: .memory,
|
||||
file: file,
|
||||
function: function,
|
||||
line: line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func trackLifecycle(_ identifier: String) -> some View {
|
||||
self.modifier(ViewLifecycleTracker(identifier: identifier))
|
||||
}
|
||||
}
|
||||
|
||||
struct ViewLifecycleTracker: ViewModifier {
|
||||
let identifier: String
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.onAppear {
|
||||
Logger.log("\(identifier) appeared", category: .lifecycle)
|
||||
Logger.trackMemory()
|
||||
}
|
||||
.onDisappear {
|
||||
Logger.log("\(identifier) disappeared", category: .lifecycle)
|
||||
Logger.trackMemory()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue