Add debug logging

This commit is contained in:
Bernd Schoolmann 2023-12-22 15:29:58 +01:00
parent 6311d6fbac
commit dcc2fb8bdc
No known key found for this signature in database
6 changed files with 40 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
.vscode
*debug*
goldwarden*

View File

@ -52,7 +52,7 @@ func readMessageLength(msg []byte) int {
func send(msg SendMessage) {
byteMsg := dataToBytes(msg)
logging.Debugf("Sending message: " + string(byteMsg))
logging.Debugf("[SENSITIVE] Sending message: " + string(byteMsg))
writeMessageLength(byteMsg)
var msgBuf bytes.Buffer

View File

@ -0,0 +1,32 @@
//go:build !nooplogging
package logging
import (
"fmt"
"os"
"time"
)
func writeLog(level string, format string, args ...interface{}) {
file, _ := os.OpenFile("/tmp/DELETE_ME.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
// log with date and time
file.WriteString("[" + level + "] ")
file.WriteString(time.Now().Format("2006-01-02 15:04:05") + " ")
file.WriteString(fmt.Sprintf(format, args...))
file.WriteString("\n")
file.Close()
}
func Debugf(format string, args ...interface{}) {
writeLog("DEBUG", format, args...)
}
func Errorf(format string, args ...interface{}) {
writeLog("ERROR", format, args...)
}
func Panicf(format string, args ...interface{}) {
writeLog("PANIC", format, args...)
panic("")
}

View File

@ -1,4 +1,4 @@
//go:build !logging
//go:build nooplogging
package logging

View File

@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"strings"
"github.com/quexten/goldwarden/browserbiometrics/logging"
)
const appID = "com.quexten.bw-bio-handler"
@ -25,7 +27,9 @@ func Main() {
return
}
logging.Debugf("Starting browserbiometrics")
transportKey = generateTransportKey()
logging.Debugf("Generated transport key")
setupCommunication()
readLoop()

View File

@ -18,11 +18,13 @@ func readLoop() {
lengthBytes := make([]byte, 4)
lengthNum := int(0)
logging.Debugf("Sending connected message")
send(SendMessage{
Command: "connected",
AppID: appID,
})
logging.Debugf("Starting read loop")
for b, err := s.Read(lengthBytes); b > 0 && err == nil; b, err = s.Read(lengthBytes) {
lengthNum = readMessageLength(lengthBytes)