Log OpenVPN tunnel via SwiftyBeaver file
This way debug log is updated without manual flush. Useful for immediate access.
This commit is contained in:
parent
3807b4754b
commit
ff235e2b96
|
@ -66,8 +66,8 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
|
||||||
/// The log separator between sessions.
|
/// The log separator between sessions.
|
||||||
public var logSeparator = "--- EOF ---"
|
public var logSeparator = "--- EOF ---"
|
||||||
|
|
||||||
/// The maximum number of lines in the log.
|
/// The maximum size of the log.
|
||||||
public var maxLogLines = 1000
|
public var maxLogSize = 20000
|
||||||
|
|
||||||
/// The log level when `OpenVPNTunnelProvider.Configuration.shouldDebug` is enabled.
|
/// The log level when `OpenVPNTunnelProvider.Configuration.shouldDebug` is enabled.
|
||||||
public var debugLogLevel: SwiftyBeaver.Level = .debug
|
public var debugLogLevel: SwiftyBeaver.Level = .debug
|
||||||
|
@ -100,7 +100,7 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
|
||||||
|
|
||||||
// MARK: Constants
|
// MARK: Constants
|
||||||
|
|
||||||
private let memoryLog = MemoryDestination()
|
private var logFile: FileDestination?
|
||||||
|
|
||||||
private let tunnelQueue = DispatchQueue(label: OpenVPNTunnelProvider.description(), qos: .utility)
|
private let tunnelQueue = DispatchQueue(label: OpenVPNTunnelProvider.description(), qos: .utility)
|
||||||
|
|
||||||
|
@ -173,23 +173,15 @@ open class OpenVPNTunnelProvider: NEPacketTunnelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare for logging (append)
|
// prepare for logging (append)
|
||||||
if let content = cfg.debugLog {
|
|
||||||
var existingLog = content.components(separatedBy: "\n")
|
|
||||||
if let i = existingLog.firstIndex(of: logSeparator) {
|
|
||||||
existingLog.removeFirst(i + 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
existingLog.append("")
|
|
||||||
existingLog.append(logSeparator)
|
|
||||||
existingLog.append("")
|
|
||||||
memoryLog.start(with: existingLog)
|
|
||||||
}
|
|
||||||
configureLogging(
|
configureLogging(
|
||||||
debug: cfg.shouldDebug,
|
debug: cfg.shouldDebug,
|
||||||
customFormat: cfg.debugLogFormat
|
customFormat: cfg.debugLogFormat
|
||||||
)
|
)
|
||||||
|
|
||||||
// logging only ACTIVE from now on
|
// logging only ACTIVE from now on
|
||||||
|
log.info("")
|
||||||
|
log.info(logSeparator)
|
||||||
|
log.info("")
|
||||||
|
|
||||||
// override library configuration
|
// override library configuration
|
||||||
CoreConfiguration.masksPrivateData = cfg.masksPrivateData
|
CoreConfiguration.masksPrivateData = cfg.masksPrivateData
|
||||||
|
@ -833,18 +825,22 @@ extension OpenVPNTunnelProvider {
|
||||||
log.addDestination(console)
|
log.addDestination(console)
|
||||||
}
|
}
|
||||||
|
|
||||||
let memory = memoryLog
|
let file = FileDestination(logFileURL: cfg.urlForDebugLog)
|
||||||
memory.minLevel = logLevel
|
file.minLevel = logLevel
|
||||||
memory.format = logFormat
|
file.format = logFormat
|
||||||
memory.maxLines = maxLogLines
|
file.logFileMaxSize = maxLogSize
|
||||||
log.addDestination(memoryLog)
|
log.addDestination(file)
|
||||||
|
|
||||||
|
logFile = file
|
||||||
}
|
}
|
||||||
|
|
||||||
private func flushLog() {
|
private func flushLog() {
|
||||||
log.debug("Flushing log...")
|
log.debug("Flushing log...")
|
||||||
if let url = cfg.urlForDebugLog {
|
|
||||||
memoryLog.flush(to: url)
|
// XXX: should enforce SwiftyBeaver flush?
|
||||||
}
|
// if let url = cfg.urlForDebugLog {
|
||||||
|
// memoryLog.flush(to: url)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private func logCurrentSSID() {
|
private func logCurrentSSID() {
|
||||||
|
|
Loading…
Reference in New Issue