VPNC control and logging (#748)

VPNC control and logging
This commit is contained in:
isamnezia 2024-04-15 01:04:01 +03:00 committed by GitHub
parent f588fe29db
commit 151e662027
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 149 additions and 35 deletions

View file

@ -16,6 +16,11 @@ struct Log {
private static let appGroupID = "group.org.amnezia.AmneziaVPN"
static let appLogURL = {
let sharedContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupID)!
return sharedContainerURL.appendingPathComponent("app.log", isDirectory: false)
}()
static let neLogURL = {
let sharedContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupID)!
return sharedContainerURL.appendingPathComponent("ne.log", isDirectory: false)
@ -70,8 +75,12 @@ struct Log {
}
static func log(_ type: OSLogType, title: String = "", message: String, url: URL = neLogURL) {
NSLog("\(title) \(message)")
guard isLoggingEnabled else { return }
osLog.log(level: type, "\(title) \(message)")
let date = Date()
let level = Record.Level(from: type)
let messages = message.split(whereSeparator: \.isNewline)
@ -107,3 +116,7 @@ extension Log: CustomStringConvertible {
.joined(separator: "\n")
}
}
func log(_ type: OSLogType, title: String = "", message: String) {
Log.log(type, title: "App: \(title)", message: message, url: Log.appLogURL)
}