mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-04-27 15:07:41 +00:00
- Run SwiftFormat on all Swift files for consistent formatting - Fix all critical SwiftLint violations: * Replace count > 0 with \!isEmpty * Use descriptive variable names instead of i, x, y * Replace % operator with isMultiple(of:) * Fix force try violations * Use trailing closure syntax * Replace for-if patterns with for-where * Fix line length violations * Use Data(_:) instead of .data(using:)\! - Ensure zero SwiftLint errors for clean code quality 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
69 lines
1.8 KiB
Swift
69 lines
1.8 KiB
Swift
import Foundation
|
|
|
|
class Logger {
|
|
static let shared = Logger()
|
|
private var debugLogs: [String] = []
|
|
private var isJsonOutputMode = false
|
|
private let queue = DispatchQueue(label: "logger.queue", attributes: .concurrent)
|
|
|
|
private init() {}
|
|
|
|
func setJsonOutputMode(_ enabled: Bool) {
|
|
queue.async(flags: .barrier) {
|
|
self.isJsonOutputMode = enabled
|
|
// Don't clear logs automatically - let tests manage this explicitly
|
|
}
|
|
}
|
|
|
|
func debug(_ message: String) {
|
|
queue.async(flags: .barrier) {
|
|
if self.isJsonOutputMode {
|
|
self.debugLogs.append(message)
|
|
} else {
|
|
fputs("DEBUG: \(message)\n", stderr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func info(_ message: String) {
|
|
queue.async(flags: .barrier) {
|
|
if self.isJsonOutputMode {
|
|
self.debugLogs.append("INFO: \(message)")
|
|
} else {
|
|
fputs("INFO: \(message)\n", stderr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func warn(_ message: String) {
|
|
queue.async(flags: .barrier) {
|
|
if self.isJsonOutputMode {
|
|
self.debugLogs.append("WARN: \(message)")
|
|
} else {
|
|
fputs("WARN: \(message)\n", stderr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func error(_ message: String) {
|
|
queue.async(flags: .barrier) {
|
|
if self.isJsonOutputMode {
|
|
self.debugLogs.append("ERROR: \(message)")
|
|
} else {
|
|
fputs("ERROR: \(message)\n", stderr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func getDebugLogs() -> [String] {
|
|
queue.sync {
|
|
self.debugLogs
|
|
}
|
|
}
|
|
|
|
func clearDebugLogs() {
|
|
queue.async(flags: .barrier) {
|
|
self.debugLogs.removeAll()
|
|
}
|
|
}
|
|
}
|