Skip to content

Commit

Permalink
feat: switch logging timestamps to utc
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasonvdb committed Sep 20, 2024
1 parent ebb1440 commit 557bec1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 6 additions & 4 deletions lib/ios/Classes/LdkLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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)")
}
}
Expand All @@ -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()
Expand All @@ -71,6 +72,7 @@ class Logfile: TextOutputStream {
try? line.data(using: .utf8)?.write(to: logfile)
}
}

static var log = Logfile()
private init() {}
}

0 comments on commit 557bec1

Please sign in to comment.