From 29dc71980394d77fbde57905befab1a486a49e27 Mon Sep 17 00:00:00 2001 From: kayos Date: Sat, 8 May 2021 16:52:47 -0700 Subject: [PATCH] retrofitted for logging engine --- main.go | 21 +++++++++------------ src/scanStuff/scanStuff.go | 16 +++++++++------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index bb99105..6915fda 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "flag" - "fmt" "os" "protomolecule/src/dust" "protomolecule/src/eros" @@ -11,7 +10,6 @@ import ( projVars "protomolecule/src/vars" - "github.com/fatih/color" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "tinygo.org/x/bluetooth" @@ -35,7 +33,7 @@ func init() { // define log file itself using the current date and time Now := time.Now() date := Now.Format(time.RFC3339) - logFileName := "protomolecule-" + date + logFileName := date + ".log" lf, err := os.OpenFile(logDir+logFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { panic(err.Error()) @@ -55,38 +53,37 @@ func main() { scanStuff.Scanners() - color.Red("Searching for: ") - for _, word := range values { - fmt.Print(word) - } + log.Info().Strs("target", values).Msg("Searching") /* err := adapter.Enable() if err != nil { - println("BLE stack unstable, could not enable", err.Error()) + log.Fatal().Err(err).Msg("BLE stack unstable, could not enable") return } */ + //var foundDevice bluetooth.ScanResult //turn the stuff on dust.Must("BLE stack", projVars.ScanAdapter.Enable()) - println("Scanning") + log.Info().Msg("Scanning") err := projVars.ScanAdapter.Scan(func(adapter *bluetooth.Adapter, result bluetooth.ScanResult) { if result.Address.String() == *projVars.Target { - - color.Cyan("found device:", result.Address.String(), result.RSSI, result.LocalName()) + log.Info().Str("address", result.Address.String()). + Int16("RSSI", result.RSSI).Str("LocalName",result.LocalName()) } /* if err != nil { - println("could not enable the stack", err.Error()) + log.Error().Err(err).Msg("could not enable the stack", err.Error()) return } */ }) + dust.Must("scanns n stuff", err) /* diff --git a/src/scanStuff/scanStuff.go b/src/scanStuff/scanStuff.go index 11893f7..abf3707 100644 --- a/src/scanStuff/scanStuff.go +++ b/src/scanStuff/scanStuff.go @@ -3,6 +3,7 @@ package scanStuff import ( "github.com/fatih/color" + "github.com/rs/zerolog/log" "protomolecule/src/dust" "protomolecule/src/eros" projVars "protomolecule/src/vars" @@ -13,25 +14,26 @@ import ( func Scanners() { //create list of devices in the AO - println("Creating Device Map") + log.Debug().Msg("Creating Device Map") dust.FirstList() - println("Enabling Adapter") + log.Info().Msg("Enabling Adapter") // Enable BLE interface. dust.Must("enable BLE stack", projVars.ScanAdapter.Enable()) //TODO: only scan a device once, skip if its in the map // Start scanning. - println("scanning...") + // redundant(?): log.Info().Msg("scanning...") //results := new(bluetooth.ScanResult) projVars.ScanAdapter.Scan(func(scanAdapter *bluetooth.Adapter, device bluetooth.ScanResult) { - if device.LocalName() != projVars.ScanList[device.Address.String()] { - color.Cyan("found device:") - println(device.Address.String(), device.RSSI, device.LocalName()) - println(device.AdvertisementPayload) + log.Info().Str("address", device.Address.String()). + Str("LocalName", device.LocalName()). + Int16("RSSI", device.RSSI).Str("AdvertisementPayload", string(device.AdvertisementPayload.Bytes())). + Msg("new_device_found") + //for _, uuid := range device.AdvertisementFields.ServiceUUIDs { //places captured devices into the eros DB