Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: switch logging timestamps to utc #273

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}
}
Loading