Skip to content

Commit 59a4490

Browse files
committed
add enable/disable crash-report generation (default off)
1 parent a1118b5 commit 59a4490

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

config.ini

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ appName = CreateBridge
66
updateUrl = https://downloads.arduino.cc/
77
origins = https://local.arduino.cc:8000
88
#httpProxy = http://your.proxy:port # Proxy server for HTTP requests
9+
crashreport = false # enable crashreport logging

main.go

+21-18
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var (
6767
signatureKey = iniConf.String("signatureKey", "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvc0yZr1yUSen7qmE3cxF\nIE12rCksDnqR+Hp7o0nGi9123eCSFcJ7CkIRC8F+8JMhgI3zNqn4cUEn47I3RKD1\nZChPUCMiJCvbLbloxfdJrUi7gcSgUXrlKQStOKF5Iz7xv1M4XOP3JtjXLGo3EnJ1\npFgdWTOyoSrA8/w1rck4c/ISXZSinVAggPxmLwVEAAln6Itj6giIZHKvA2fL2o8z\nCeK057Lu8X6u2CG8tRWSQzVoKIQw/PKK6CNXCAy8vo4EkXudRutnEYHEJlPkVgPn\n2qP06GI+I+9zKE37iqj0k1/wFaCVXHXIvn06YrmjQw6I0dDj/60Wvi500FuRVpn9\ntwIDAQAB\n-----END PUBLIC KEY-----", "Pem-encoded public key to verify signed commandlines")
6868
updateUrl = iniConf.String("updateUrl", "", "")
6969
verbose = iniConf.Bool("v", true, "show debug logging")
70+
crashreport = iniConf.Bool("crashreport", false, "enable crashreport logging")
7071
)
7172

7273
// global clients
@@ -111,24 +112,6 @@ func main() {
111112
os.Exit(0)
112113
}
113114

114-
// save crashreport to file
115-
logFilename := "crashreport_" + time.Now().Format("20060102150405") + ".log"
116-
currDir, err := osext.ExecutableFolder()
117-
if err != nil {
118-
panic(err)
119-
}
120-
// handle logs directory creation
121-
logsDir := filepath.Join(currDir, "logs")
122-
if _, err := os.Stat(logsDir); os.IsNotExist(err) {
123-
os.Mkdir(logsDir, 0700)
124-
}
125-
logFile, err := os.OpenFile(filepath.Join(logsDir, logFilename), os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0644)
126-
if err != nil {
127-
log.Print("Cannot create file used for crash-report")
128-
} else {
129-
redirectStderr(logFile)
130-
}
131-
132115
// Launch main loop in a goroutine
133116
go loop()
134117

@@ -306,6 +289,26 @@ func loop() {
306289
log.SetOutput(new(NullWriter)) //route all logging to nullwriter
307290
}
308291

292+
// save crashreport to file
293+
if *crashreport {
294+
logFilename := "crashreport_" + time.Now().Format("20060102150405") + ".log"
295+
currDir, err := osext.ExecutableFolder()
296+
if err != nil {
297+
panic(err)
298+
}
299+
// handle logs directory creation
300+
logsDir := filepath.Join(currDir, "logs")
301+
if _, err := os.Stat(logsDir); os.IsNotExist(err) {
302+
os.Mkdir(logsDir, 0700)
303+
}
304+
logFile, err := os.OpenFile(filepath.Join(logsDir, logFilename), os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0644)
305+
if err != nil {
306+
log.Print("Cannot create file used for crash-report")
307+
} else {
308+
redirectStderr(logFile)
309+
}
310+
}
311+
309312
// launch the hub routine which is the singleton for the websocket server
310313
go h.run()
311314
// launch our serial port routine

0 commit comments

Comments
 (0)