43 lines
1.1 KiB
Swift
43 lines
1.1 KiB
Swift
import Combine
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
let isConsoleLoggingEnabled = false
|
|
|
|
enum LogLevels: String {
|
|
case info = "\u{F449}"
|
|
case warning = "\u{F071}"
|
|
case error = "\u{EA76}"
|
|
}
|
|
|
|
// For database errors logging
|
|
func logIt(_ level: LogLevels, _ message: String) {
|
|
#if DEBUG
|
|
let timeStr = dateFormatter.string(from: Date())
|
|
let str = "\(timeStr) \(level.rawValue) \(message)"
|
|
print(str)
|
|
if isConsoleLoggingEnabled {
|
|
NSLog(str)
|
|
}
|
|
#endif
|
|
}
|
|
|
|
private var dateFormatter: DateFormatter {
|
|
let formatter = DateFormatter()
|
|
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") as Locale
|
|
formatter.dateFormat = "MM-dd HH:mm:ss.SSS"
|
|
return formatter
|
|
}
|
|
|
|
// For thread debugging
|
|
func ptInfo(_ message: String) {
|
|
#if DEBUG
|
|
let timeStr = dateFormatter.string(from: Date())
|
|
let str = "\(timeStr) \(message) -> \(Thread.current), \(String(validatingUTF8: __dispatch_queue_get_label(nil)) ?? "no queue label")"
|
|
print(str)
|
|
if isConsoleLoggingEnabled {
|
|
NSLog(str)
|
|
}
|
|
#endif
|
|
}
|