Files
Ascently/ios/Ascently/Utils/AppLogger.swift
2025-11-18 12:58:45 -07:00

47 lines
1.5 KiB
Swift

import Foundation
/// Centralized logging utility for the iOS app.
///
/// All log output is automatically compiled out in non-debug builds to avoid leaking
/// sensitive information. Use this instead of calling `print` directly.
enum AppLogger {
enum LogLevel: String {
case debug = "DEBUG"
case info = "INFO"
case warning = "WARN"
case error = "ERROR"
}
static func debug(_ message: @autoclosure () -> String, tag: String = #fileID) {
log(level: .debug, tag: tag, message: message())
}
static func info(_ message: @autoclosure () -> String, tag: String = #fileID) {
log(level: .info, tag: tag, message: message())
}
static func warning(_ message: @autoclosure () -> String, tag: String = #fileID) {
log(level: .warning, tag: tag, message: message())
}
static func error(_ message: @autoclosure () -> String, tag: String = #fileID) {
log(level: .error, tag: tag, message: message())
}
static func log(level: LogLevel, tag: String, message: @autoclosure () -> String) {
#if DEBUG
let lastPath = (tag as NSString).lastPathComponent
let resolvedTag = lastPath.isEmpty ? tag : lastPath
Swift.print("[\(level.rawValue)][\(resolvedTag)] \(message())")
#endif
}
}
enum LogTag {
static let climbingData = "ClimbingData"
static let dataManagement = "DataManagementSection"
static let exportData = "ExportDataView"
static let syncSection = "SyncSection"
}