Skip to content

Commit 2f8a6f6

Browse files
committed
feat: add option to view log messages inside the app (fixes #286)
1 parent 191b31f commit 2f8a6f6

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

Localizable.xcstrings

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15874,6 +15874,46 @@
1587415874
}
1587515875
}
1587615876
},
15877+
"Log" : {
15878+
"localizations" : {
15879+
"de" : {
15880+
"stringUnit" : {
15881+
"state" : "translated",
15882+
"value" : "Protokoll"
15883+
}
15884+
},
15885+
"es" : {
15886+
"stringUnit" : {
15887+
"state" : "translated",
15888+
"value" : "Registro"
15889+
}
15890+
},
15891+
"it" : {
15892+
"stringUnit" : {
15893+
"state" : "translated",
15894+
"value" : "Registro"
15895+
}
15896+
},
15897+
"nl" : {
15898+
"stringUnit" : {
15899+
"state" : "translated",
15900+
"value" : "Logboek"
15901+
}
15902+
},
15903+
"uk" : {
15904+
"stringUnit" : {
15905+
"state" : "translated",
15906+
"value" : "Журнал"
15907+
}
15908+
},
15909+
"zh-Hans" : {
15910+
"stringUnit" : {
15911+
"state" : "translated",
15912+
"value" : "日志"
15913+
}
15914+
}
15915+
}
15916+
},
1587715917
"Logging" : {
1587815918
"localizations" : {
1587915919
"de" : {
@@ -29928,6 +29968,46 @@
2992829968
}
2992929969
}
2993029970
},
29971+
"View log messages" : {
29972+
"localizations" : {
29973+
"de" : {
29974+
"stringUnit" : {
29975+
"state" : "translated",
29976+
"value" : "Protokollnachrichten anzeigen"
29977+
}
29978+
},
29979+
"es" : {
29980+
"stringUnit" : {
29981+
"state" : "translated",
29982+
"value" : "Ver mensajes de registro"
29983+
}
29984+
},
29985+
"it" : {
29986+
"stringUnit" : {
29987+
"state" : "translated",
29988+
"value" : "Visualizza i messaggi di log"
29989+
}
29990+
},
29991+
"nl" : {
29992+
"stringUnit" : {
29993+
"state" : "translated",
29994+
"value" : "Logberichten bekijken"
29995+
}
29996+
},
29997+
"uk" : {
29998+
"stringUnit" : {
29999+
"state" : "translated",
30000+
"value" : "Переглянути журнали повідомлень"
30001+
}
30002+
},
30003+
"zh-Hans" : {
30004+
"stringUnit" : {
30005+
"state" : "translated",
30006+
"value" : "查看日志信息"
30007+
}
30008+
}
30009+
}
30010+
},
2993130011
"View settings" : {
2993230012
"localizations" : {
2993330013
"de" : {

Sushitrain/SupportView.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,33 @@ extension AppState {
9393
}
9494
}
9595

96+
private struct LogView: View {
97+
@Environment(AppState.self) private var appState
98+
@State private var lines: String = ""
99+
100+
var body: some View {
101+
ScrollView {
102+
Text(self.lines)
103+
.textSelection(.enabled)
104+
.multilineTextAlignment(.leading)
105+
.lineLimit(nil)
106+
.monospaced()
107+
.padding()
108+
.fixedSize(horizontal: false, vertical: true)
109+
}
110+
.navigationTitle("Log")
111+
#if os(iOS)
112+
.navigationBarTitleDisplayMode(.inline)
113+
#endif
114+
.task {
115+
Task {
116+
var error: NSError? = nil
117+
self.lines = appState.client.getLastLogLines(&error)
118+
}
119+
}
120+
}
121+
}
122+
96123
private struct SupportBundleView: View {
97124
@Environment(AppState.self) private var appState
98125
@State private var writingSupportBundle: Bool = false
@@ -189,6 +216,7 @@ private struct SupportBundleView: View {
189216

190217
struct SupportView: View {
191218
@Environment(AppState.self) private var appState
219+
@State private var showLog: Bool = false
192220

193221
var body: some View {
194222
Form {
@@ -239,6 +267,14 @@ struct SupportView: View {
239267
NavigationLink(destination: TroubleshootingView(userSettings: appState.userSettings)) {
240268
Label("Troubleshooting options", systemImage: "book.and.wrench")
241269
}
270+
271+
Button("View log messages", systemImage: "heart.text.clipboard") {
272+
showLog = true
273+
}.sheet(isPresented: $showLog) {
274+
NavigationStack {
275+
LogView()
276+
}
277+
}
242278
}
243279
}
244280
#if os(macOS)

SushitrainCore/src/sushitrain.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package sushitrain
88
import (
99
"archive/zip"
1010
"bufio"
11+
"bytes"
1112
"context"
1213
"crypto/tls"
1314
"encoding/json"
@@ -1486,6 +1487,15 @@ func (c *Client) ClearDatabase() error {
14861487
return os.RemoveAll(dbPath)
14871488
}
14881489

1490+
func (c *Client) GetLastLogLines() (string, error) {
1491+
var buf bytes.Buffer
1492+
err := c.logHandler.tail.write(&buf, true)
1493+
if err != nil {
1494+
return "", err
1495+
}
1496+
return buf.String(), nil
1497+
}
1498+
14891499
func (c *Client) WriteSupportBundle(path string, appInfo []byte) error {
14901500
out, err := os.Create(path)
14911501
if err != nil {

0 commit comments

Comments
 (0)