From 557bec1ab9f68d8f13ae77f69ec55b0bed93b058 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 20 Sep 2024 12:48:55 +0200 Subject: [PATCH] feat: switch logging timestamps to utc --- .../main/java/com/reactnativeldk/classes/LdkLogger.kt | 4 +++- lib/ios/Classes/LdkLogger.swift | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/android/src/main/java/com/reactnativeldk/classes/LdkLogger.kt b/lib/android/src/main/java/com/reactnativeldk/classes/LdkLogger.kt index 9a4d56d3..93c3a294 100644 --- a/lib/android/src/main/java/com/reactnativeldk/classes/LdkLogger.kt +++ b/lib/android/src/main/java/com/reactnativeldk/classes/LdkLogger.kt @@ -8,6 +8,7 @@ import org.ldk.structs.Record import java.io.File import java.text.SimpleDateFormat import java.util.Date +import java.util.TimeZone private fun levelString(level: Int): String { when (level) { @@ -58,7 +59,8 @@ object LogFile { } val dateFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") - val line = "${dateFormatter.format(Date())} $str\n" + dateFormatter.timeZone = TimeZone.getTimeZone("UTC") + val line = "${dateFormatter.format(Date())} UTC $str\n" logFile!!.appendText(line) } diff --git a/lib/ios/Classes/LdkLogger.swift b/lib/ios/Classes/LdkLogger.swift index ca3c944d..2182aa9b 100644 --- a/lib/ios/Classes/LdkLogger.swift +++ b/lib/ios/Classes/LdkLogger.swift @@ -8,7 +8,7 @@ import Foundation import LightningDevKit -fileprivate func levelString(_ level: Level) -> String { +private func levelString(_ level: Level) -> String { switch level { case .Gossip: return "GOSSIP" @@ -33,7 +33,7 @@ class LdkLogger: LightningDevKit.Bindings.Logger { override func log(record: Record) { let level = levelString(record.getLevel()) - //Only when the JS code has set the log level to active + // Only when the JS code has set the log level to active if activeLevels[level] == true { let line = "\(level) (LDK): \(record.getArgs()) (\(record.getModulePath()) \(record.getLine()))" LdkEventEmitter.shared.send(withEvent: .ldk_log, body: line) @@ -42,7 +42,7 @@ class LdkLogger: LightningDevKit.Bindings.Logger { } func setLevel(level: String, active: Bool) { - self.activeLevels[level] = active + activeLevels[level] = active LdkEventEmitter.shared.send(withEvent: .native_log, body: "Log level \(level) set to \(active)") } } @@ -61,7 +61,8 @@ class Logfile: TextOutputStream { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" - let line = "\(dateFormatter.string(from: Date())) \(str)\n" + dateFormatter.timeZone = TimeZone(abbreviation: "UTC") + let line = "\(dateFormatter.string(from: Date())) UTC \(str)\n" if let handle = try? FileHandle(forWritingTo: logfile) { handle.seekToEndOfFile() @@ -71,6 +72,7 @@ class Logfile: TextOutputStream { try? line.data(using: .utf8)?.write(to: logfile) } } + static var log = Logfile() private init() {} }