summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmils <emils@mullvad.net>2023-09-22 14:28:07 +0200
committerBug Magnet <marco.nikic@mullvad.net>2024-04-17 12:40:40 +0200
commit4838c055d1280d6950d968ef37562649defc6304 (patch)
tree60ad78b95aacf012ed2af9677804feac81c27fcb
parent9f803202fd37f6fd3132590424c7e9b19966dbe2 (diff)
downloadmullvadvpn-4838c055d1280d6950d968ef37562649defc6304.tar.xz
mullvadvpn-4838c055d1280d6950d968ef37562649defc6304.zip
Add a header to log files
-rw-r--r--ios/MullvadLogging/Logging.swift3
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj2
-rw-r--r--ios/MullvadVPN/AppDelegate.swift4
-rw-r--r--ios/MullvadVPNTests/LoggingTests.swift31
4 files changed, 38 insertions, 2 deletions
diff --git a/ios/MullvadLogging/Logging.swift b/ios/MullvadLogging/Logging.swift
index 76c3c57f8c..c6d86a549b 100644
--- a/ios/MullvadLogging/Logging.swift
+++ b/ios/MullvadLogging/Logging.swift
@@ -49,11 +49,12 @@ public struct LoggerBuilder {
outputs.append(.osLogOutput(subsystem))
}
- public func install() {
+ public func install(header: String) {
LoggingSystem.bootstrap { label -> LogHandler in
let logHandlers: [LogHandler] = outputs.map { output in
switch output {
case let .fileOutput(stream):
+ stream.write("\(header)\n")
return CustomFormatLogHandler(label: label, streams: [stream])
case let .osLogOutput(subsystem):
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index fca1fe112c..1312c0c182 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -2948,6 +2948,7 @@
7A83A0C52B29A750008B5CE7 /* APIAccessMethodsTests.swift */,
A900E9BD2ACC654100C95F67 /* APIProxy+Stubs.swift */,
A9EC20E72A5D3A8C0040D56E /* CoordinatesTests.swift */,
+ 01168B192BBEE7F800D5F382 /* LoggingTests.swift */,
5896AE85246D6AD8005B36CB /* CustomDateComponentsFormattingTests.swift */,
58915D622A25F8400066445B /* DeviceCheckOperationTests.swift */,
A900E9BB2ACC609200C95F67 /* DevicesProxy+Stubs.swift */,
@@ -5112,6 +5113,7 @@
7A3FD1B52AD4465A0042BEA6 /* AppMessageHandlerTests.swift in Sources */,
58C7A4702A8649ED0060C66F /* PingerTests.swift in Sources */,
A97D25B22B0CB02D00946B2D /* ProtocolObfuscatorTests.swift in Sources */,
+ 01168B1A2BBEE7F800D5F382 /* LoggingTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/ios/MullvadVPN/AppDelegate.swift b/ios/MullvadVPN/AppDelegate.swift
index be750d8524..dda8fdc5e4 100644
--- a/ios/MullvadVPN/AppDelegate.swift
+++ b/ios/MullvadVPN/AppDelegate.swift
@@ -357,9 +357,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
#if DEBUG
loggerBuilder.addOSLogOutput(subsystem: ApplicationTarget.mainApp.bundleIdentifier)
#endif
- loggerBuilder.install()
+ loggerBuilder.install(header: "TODO: Add version info here")
logger = Logger(label: "AppDelegate")
+
+ loggerBuilder.logLevel = .debug
}
private func addApplicationNotifications(application: UIApplication) {
diff --git a/ios/MullvadVPNTests/LoggingTests.swift b/ios/MullvadVPNTests/LoggingTests.swift
new file mode 100644
index 0000000000..3c1abefbc1
--- /dev/null
+++ b/ios/MullvadVPNTests/LoggingTests.swift
@@ -0,0 +1,31 @@
+//
+// LoggingTests.swift
+// MullvadVPNTests
+//
+// Created by Emils on 04/04/2024.
+// Copyright © 2024 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+import XCTest
+@testable import MullvadLogging
+
+class MullvadLoggingTests: XCTestCase {
+ func testLogHeader() {
+ let dummySig = "test-sgi";
+ let testFileName = "test"
+ let expectedHeader = "Header of a log file"
+
+ var builder = LoggerBuilder()
+ try! builder.addFileOutput(securityGroupIdentifier: dummySig, basename: testFileName)
+
+ builder.install(header: expectedHeader)
+
+ let logFileUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: dummySig)!.appendingPathComponent("Logs", isDirectory: true).appendingPathComponent("\(testFileName).log", isDirectory: false)
+
+ let contents = String(decoding: try! Data(contentsOf: logFileUrl), as: UTF8.self)
+
+ XCTAssert(contents.hasPrefix(expectedHeader))
+ XCTAssertEqual("\(expectedHeader)\n", contents)
+ }
+}