]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Logging: Tag the entries in the merged log
authorRoopesh Chander <roop@roopc.net>
Thu, 13 Dec 2018 12:30:29 +0000 (18:00 +0530)
committerRoopesh Chander <roop@roopc.net>
Thu, 13 Dec 2018 12:30:32 +0000 (18:00 +0530)
So we know which entry is from the app and which is from the network
extension.

Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/Shared/Logging/Logger.swift
WireGuard/Shared/Logging/ringlogger.c
WireGuard/Shared/Logging/ringlogger.h
WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift

index bc0ffd4111f7aa1b4e822578f727e498bde51a71..9ba28a3f15fb3086c7ab978e2a7dc2c8ab268b89 100644 (file)
@@ -14,14 +14,18 @@ class Logger {
         return (logPtr != nil)
     }
 
-    static func writeLog(mergedWith otherLogFile: String, to targetFile: String) -> Bool {
+    static func writeLog(mergedWith otherLogFile: String, tag: String, otherTag: String, to targetFile: String) -> Bool {
         let otherlogPtr = otherLogFile.withCString { otherLogFileCStr -> UnsafeMutablePointer<log>? in
             return open_log(otherLogFileCStr)
         }
         if let thisLogPtr = Logger.logPtr, let otherlogPtr = otherlogPtr {
             return targetFile.withCString { targetFileCStr -> Bool in
-                let returnValue = write_logs_to_file(targetFileCStr, thisLogPtr, otherlogPtr)
-                return (returnValue == 0)
+                return tag.withCString { tagCStr -> Bool in
+                    return otherTag.withCString { otherTagCStr -> Bool in
+                        let returnValue = write_logs_to_file(targetFileCStr, tagCStr, thisLogPtr, otherTagCStr, otherlogPtr)
+                        return (returnValue == 0)
+                    }
+                }
             }
         }
         return false
index 11de0c3812b2d229615882694a3ad7010d7740d2..5c6fae6b4e59a52ecdcfa7fac6dfdfd26bc5ab45 100644 (file)
@@ -49,7 +49,7 @@ static bool first_before_second(const struct log_line *line1, const struct log_l
        return false;
 }
 
-int write_logs_to_file(const char *file_name, const struct log *log1, const struct log *log2)
+int write_logs_to_file(const char *file_name, const char *tag1, const struct log *log1, const char *tag2, const struct log *log2)
 {
        uint32_t i1, i2, len1 = log1->header.len, len2 = log2->header.len;
        char buf[MAX_LOG_LINE_LENGTH];
@@ -68,19 +68,22 @@ int write_logs_to_file(const char *file_name, const struct log *log1, const stru
                const struct log_line *line1 = &log1->lines[(log1->header.first + i1) % MAX_LINES];
                const struct log_line *line2 = &log2->lines[(log2->header.first + i2) % MAX_LINES];
                const struct log_line *line;
+               const char *tag;
 
                if (i1 < len1 && (i2 >= len2 || first_before_second(line1, line2))) {
                        line = line1;
+                       tag = (const char *) tag1;
                        ++i1;
                } else if (i2 < len2 && (i1 >= len1 || first_before_second(line2, line1))) {
                        line = line2;
+                       tag = (const char *) tag2;
                        ++i2;
                } else {
                        break;
                }
                memcpy(buf, line->line, MAX_LOG_LINE_LENGTH);
                buf[MAX_LOG_LINE_LENGTH - 1] = '\0';
-               if (fprintf(file, "%lu.%06d: %s\n", line->tv.tv_sec, line->tv.tv_usec, buf) < 0) {
+               if (fprintf(file, "%lu.%06d: [%s] %s\n", line->tv.tv_sec, line->tv.tv_usec, tag, buf) < 0) {
                        int ret = -errno;
                        fclose(file);
                        return ret;
index a8d07c03eea50e11f0a5322669128d8dae050f88..be1d33ca9b6a57407b6302111e2004b0c1c62b45 100644 (file)
@@ -24,7 +24,7 @@ struct log {
 };
 
 void write_msg_to_log(struct log *log, const char *msg);
-int write_logs_to_file(const char *file_name, const struct log *log1, const struct log *log2);
+int write_logs_to_file(const char *file_name, const char *tag1, const struct log *log1, const char *tag2, const struct log *log2);
 struct log *open_log(const char *file_name);
 
 #endif
index 43e277e82bf3103af427cafe38d338a845a93a34..f740919fd034e977df67dbcd953fe767c2cec67c 100644 (file)
@@ -118,7 +118,7 @@ class SettingsTableViewController: UITableViewController {
                 return
             }
 
-            let isWritten = Logger.writeLog(mergedWith: networkExtensionLogFilePath, to: destinationURL.path)
+            let isWritten = Logger.writeLog(mergedWith: networkExtensionLogFilePath, tag: "APP", otherTag: "EXT", to: destinationURL.path)
             guard isWritten else {
                 ErrorPresenter.showErrorAlert(title: "Log export failed", message: "Internal error merging logs", from: self)
                 return