mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(ios): add Logger class (#6284)
This commit is contained in:
committed by
GitHub
parent
d42fd0710c
commit
ea7fd016ca
46
core/tauri/mobile/ios-api/Sources/Tauri/Logger.swift
Normal file
46
core/tauri/mobile/ios-api/Sources/Tauri/Logger.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
import os.log
|
||||
import UIKit
|
||||
|
||||
/// Wrapper class for os_log function
|
||||
public class Logger {
|
||||
private static var _enabled = false
|
||||
public static var enabled: Bool {
|
||||
get {
|
||||
#if DEBUG
|
||||
return true
|
||||
#else
|
||||
return _enabled
|
||||
#endif
|
||||
}
|
||||
set {
|
||||
Logger._enabled = newValue
|
||||
}
|
||||
}
|
||||
|
||||
static func log(_ items: Any..., category: String, type: OSLogType) {
|
||||
if Logger.enabled {
|
||||
var message = ""
|
||||
let last = items.count - 1
|
||||
for (index, item) in items.enumerated() {
|
||||
message += "\(item)"
|
||||
if index != last {
|
||||
message += " "
|
||||
}
|
||||
}
|
||||
let log = OSLog(subsystem: Bundle.main.bundleIdentifier ?? "-", category: category)
|
||||
os_log("%{public}@", log: log, type: type, String(message.prefix(4068)))
|
||||
}
|
||||
}
|
||||
|
||||
public static func debug(_ items: Any..., category: String = "app") {
|
||||
Logger.log(items, category: category, type: OSLogType.debug)
|
||||
}
|
||||
|
||||
public static func info(_ items: Any..., category: String = "app") {
|
||||
Logger.log(items, category: category, type: OSLogType.info)
|
||||
}
|
||||
|
||||
public static func error(_ items: Any..., category: String = "app") {
|
||||
Logger.log(items, category: category, type: OSLogType.error)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user