Peekaboo/peekaboo-cli/Sources/peekaboo/Logger.swift
Peter Steinberger 7895e1765f Add Swift 6.0 version to SwiftFormat config and apply formatting
- Specify Swift 6.0 in .swiftformat to enable all formatting features
- Apply Swift 6 formatting improvements:
  - Use shorthand optional unwrapping syntax
  - Use implicit returns in computed properties
  - Use modern Swift 6 syntax throughout

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-25 18:45:20 +02:00

54 lines
1.2 KiB
Swift

import Foundation
class Logger {
static let shared = Logger()
private var debugLogs: [String] = []
private var isJsonOutputMode = false
private init() {}
func setJsonOutputMode(_ enabled: Bool) {
isJsonOutputMode = enabled
debugLogs.removeAll()
}
func debug(_ message: String) {
if isJsonOutputMode {
debugLogs.append(message)
} else {
fputs("DEBUG: \(message)\n", stderr)
}
}
func info(_ message: String) {
if isJsonOutputMode {
debugLogs.append("INFO: \(message)")
} else {
fputs("INFO: \(message)\n", stderr)
}
}
func warn(_ message: String) {
if isJsonOutputMode {
debugLogs.append("WARN: \(message)")
} else {
fputs("WARN: \(message)\n", stderr)
}
}
func error(_ message: String) {
if isJsonOutputMode {
debugLogs.append("ERROR: \(message)")
} else {
fputs("ERROR: \(message)\n", stderr)
}
}
func getDebugLogs() -> [String] {
debugLogs
}
func clearDebugLogs() {
debugLogs.removeAll()
}
}