Skip to content

Commit

Permalink
Add debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Dec 22, 2023
1 parent 6311d6f commit dcc2fb8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.vscode
*debug*
goldwarden*
2 changes: 1 addition & 1 deletion browserbiometrics/communication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions browserbiometrics/logging/debuglogger.go
Original file line number Diff line number Diff line change
@@ -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("")
}
2 changes: 1 addition & 1 deletion browserbiometrics/logging/nooplogger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !logging
//go:build nooplogging

package logging

Expand Down
4 changes: 4 additions & 0 deletions browserbiometrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"strings"

"github.com/quexten/goldwarden/browserbiometrics/logging"
)

const appID = "com.quexten.bw-bio-handler"
Expand All @@ -25,7 +27,9 @@ func Main() {
return
}

logging.Debugf("Starting browserbiometrics")
transportKey = generateTransportKey()
logging.Debugf("Generated transport key")

setupCommunication()
readLoop()
Expand Down
2 changes: 2 additions & 0 deletions browserbiometrics/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit dcc2fb8

Please sign in to comment.