Peekaboo/peekaboo-cli/Sources/peekaboo/Logger.swift
Peter Steinberger 670e1c485a Add GitHub Actions CI workflow for Node.js builds
- Configure CI to run on macOS-latest
- Test with Node.js 20.x and 22.x
- Run npm build and tests on push/PR

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-25 01:25:35 +02:00

54 lines
No EOL
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] {
return debugLogs
}
func clearDebugLogs() {
debugLogs.removeAll()
}
}