Switch from zerolog to go.arsenm.dev/logger

This commit is contained in:
Elara Musayelyan 2023-01-04 15:00:15 -08:00
parent 8c5eca51f9
commit 492242bd54
8 changed files with 81 additions and 85 deletions

View file

@ -77,7 +77,7 @@ func (a *Agent) RequestPasskey(device dbus.ObjectPath) (uint32, *dbus.Error) {
if a.ReqPasskey == nil {
return 0, errAuthFailed
}
log.Debug().Msg("Passkey requested, calling onReqPasskey callback")
log.Debug("Passkey requested, calling onReqPasskey callback").Send()
passkey, err := a.ReqPasskey()
if err != nil {
return 0, errAuthFailed

16
dfu.go
View file

@ -313,7 +313,7 @@ func (dfu *DFU) Reset() {
// on waits for the given command to be received on
// the control point characteristic, then runs the callback.
func (dfu *DFU) on(cmd []byte, onCmdCb func(data []byte) error) error {
log.Debug().Hex("expecting", cmd).Msg("Waiting for DFU command")
log.Debug("Waiting for DFU command").Bytes("expecting", cmd).Send()
// Use for loop in case of invalid property
for {
select {
@ -325,10 +325,10 @@ func (dfu *DFU) on(cmd []byte, onCmdCb func(data []byte) error) error {
}
// Assert propery value as byte slice
data := propChanged.Value.([]byte)
log.Debug().
Hex("expecting", cmd).
Hex("received", data).
Msg("Received DFU command")
log.Debug("Received DFU command").
Bytes("expecting", cmd).
Bytes("received", data).
Send()
// If command has prefix of given command
if bytes.HasPrefix(data, cmd) {
// Return callback with data after command
@ -413,7 +413,7 @@ func (dfu *DFU) stepSeven() error {
if err != nil {
return err
}
log.Debug().Msg("Sent firmware image segment")
log.Debug("Sent firmware image segment").Send()
// Increment bytes sent by amount read
dfu.bytesSent += len(segment)
}
@ -421,10 +421,10 @@ func (dfu *DFU) stepSeven() error {
err := dfu.on(DFUNotifPktRecvd, func(data []byte) error {
// Set bytes received to data returned by InfiniTime
dfu.bytesRecvd = int(binary.LittleEndian.Uint32(data))
log.Debug().
log.Debug("Received packet receipt notification").
Int("sent", dfu.bytesSent).
Int("rcvd", dfu.bytesRecvd).
Msg("Received packet receipt notification")
Send()
if dfu.bytesRecvd != dfu.bytesSent {
return ErrDFUSizeMismatch
}

2
go.mod
View file

@ -6,6 +6,6 @@ require (
github.com/fxamacker/cbor/v2 v2.4.0
github.com/godbus/dbus/v5 v5.0.6
github.com/muka/go-bluetooth v0.0.0-20220819140550-1d8857e3b268
github.com/rs/zerolog v1.26.1
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
)

37
go.sum
View file

@ -1,4 +1,3 @@
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -7,14 +6,17 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88=
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.6 h1:mkgN1ofwASrYnJ5W6U/BxG15eXXXjirgZc7CLqkcaro=
github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/muka/go-bluetooth v0.0.0-20220819140550-1d8857e3b268 h1:kOnq7TfaAO2Vc/MHxPqFIXe00y1qBxJAvhctXdko6vo=
github.com/muka/go-bluetooth v0.0.0-20220819140550-1d8857e3b268/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
@ -22,56 +24,49 @@ github.com/paypal/gatt v0.0.0-20151011220935-4ae819d591cf/go.mod h1:+AwQL2mK3Pd3
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc=
github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/suapapa/go_eddystone v1.3.1/go.mod h1:bXC11TfJOS+3g3q/Uzd7FKd5g62STQEfeEIhcKe4Qy8=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.arsenm.dev/logger v0.0.0-20230104224016-562ab8b78b50 h1:63Eh7CyVrNzG7m80FIzkCCQScBlTkniXEphfdhiExrE=
go.arsenm.dev/logger v0.0.0-20230104224016-562ab8b78b50/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw=
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df h1:8mBHvEe7BJmpOeKSMA5YLqrGo9dCpePocTeR0C1+/2w=
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -15,14 +15,14 @@ import (
"github.com/muka/go-bluetooth/bluez/profile/adapter"
"github.com/muka/go-bluetooth/bluez/profile/device"
"github.com/muka/go-bluetooth/bluez/profile/gatt"
"github.com/rs/zerolog"
"go.arsenm.dev/infinitime/blefs"
"go.arsenm.dev/logger"
)
// This global is used to store the logger.
// log.Logger is not used as it would interfere
// with the package importing the library
var log zerolog.Logger
var log logger.Logger
const BTName = "InfiniTime"
@ -104,15 +104,14 @@ type Options struct {
Whitelist []string
OnReqPasskey func() (uint32, error)
OnReconnect func()
Logger zerolog.Logger
LogLevel zerolog.Level
Logger logger.Logger
LogLevel logger.LogLevel
}
var DefaultOptions = &Options{
AttemptReconnect: true,
WhitelistEnabled: false,
Logger: zerolog.Nop(),
LogLevel: zerolog.Disabled,
Logger: logger.NewNop(),
}
// Connect will attempt to connect to a
@ -126,7 +125,8 @@ func Connect(ctx context.Context, opts *Options) (*Device, error) {
opts = DefaultOptions
}
log = opts.Logger.Level(opts.LogLevel)
log = opts.Logger
opts.Logger.SetLevel(opts.LogLevel)
// Set passkey request callback
setOnPasskeyReq(opts.OnReqPasskey)
@ -168,25 +168,25 @@ func connect(ctx context.Context, opts *Options, first bool) (dev *device.Device
// device, skip
if opts.WhitelistEnabled &&
!contains(opts.Whitelist, listDev.Properties.Address) {
log.Debug().
log.Debug("InfiniTime device skipped as it is not in whitelist").
Str("mac", listDev.Properties.Address).
Msg("InfiniTime device skipped as it is not in whitelist")
Send()
continue
}
// Set device
dev = listDev
log.Debug().
log.Debug("InfiniTime device found in list").
Str("mac", dev.Properties.Address).
Msg("InfiniTime device found in list")
Send()
break
}
// If device not set
if dev == nil {
log.Debug().Msg("No device found in list, attempting to discover")
log.Debug("No device found in list, attempting to discover").Send()
// Discover devices on adapter
discoverCh, cancel, err := bt.Discover(defaultAdapter, &adapter.DiscoveryFilter{Transport: "le"})
if err != nil {
@ -216,18 +216,18 @@ func connect(ctx context.Context, opts *Options, first bool) (dev *device.Device
// device, skip
if opts.WhitelistEnabled &&
!contains(opts.Whitelist, discovered.Properties.Address) {
log.Debug().
log.Debug("Discovered InfiniTime device skipped as it is not in whitelist").
Str("mac", discovered.Properties.Address).
Msg("Discovered InfiniTime device skipped as it is not in whitelist")
Send()
continue
}
// Set device
dev = discovered
log.Debug().
log.Debug("InfiniTime device discovered").
Str("mac", dev.Properties.Address).
Msg("InfiniTime device discovered")
Send()
break discoverLoop
case <-ctx.Done():
break discoverLoop
@ -249,7 +249,7 @@ func connect(ctx context.Context, opts *Options, first bool) (dev *device.Device
reconnRequired := false
// If device is not connected
if !dev.Properties.Connected {
log.Debug().Msg("Device not connected, connecting")
log.Debug("Device not connected, connecting").Send()
// Connect to device
err = dev.Connect()
if err != nil {
@ -261,7 +261,7 @@ func connect(ctx context.Context, opts *Options, first bool) (dev *device.Device
// If device is not paired
if !dev.Properties.Paired {
log.Debug().Msg("Device not paired, pairing")
log.Debug("Device not paired, pairing").Send()
// Pair device
err = dev.Pair()
if err != nil {
@ -279,7 +279,7 @@ func connect(ctx context.Context, opts *Options, first bool) (dev *device.Device
// was required, and the OnReconnect callback exists,
// run it
if !first && reconnRequired && opts.OnReconnect != nil {
log.Debug().Msg("Reconnected to device, running OnReconnect callback")
log.Debug("Reconnected to device, running OnReconnect callback").Send()
opts.OnReconnect()
}
@ -312,7 +312,7 @@ func reconnect(ctx context.Context, opts *Options, dev *device.Device1) {
// If less than 3 seconds have passed and more than 6
// disconnects have occurred, remove the device and reset
if secsSince <= 3 && amtDisconnects >= 6 {
opts.Logger.Warn().Msg("At least 6 disconnects have occurred in the last three seconds. If this continues, try removing the InfiniTime device from bluetooth.")
opts.Logger.Warn("At least 6 disconnects have occurred in the last three seconds. If this continues, try removing the InfiniTime device from bluetooth.").Send()
lastDisconnect = time.Unix(0, 0)
amtDisconnects = 0
}
@ -324,7 +324,7 @@ func reconnect(ctx context.Context, opts *Options, dev *device.Device1) {
for i := 0; i < 6; i++ {
// If three tries failed, remove device
if i == 3 {
opts.Logger.Warn().Msg("Multiple connection attempts have failed. If this continues, try removing the InfiniTime device from bluetooth.")
opts.Logger.Warn("Multiple connection attempts have failed. If this continues, try removing the InfiniTime device from bluetooth.").Send()
}
// Connect to device
newDev, err := connect(ctx, opts, false)
@ -454,10 +454,10 @@ func (i *Device) resolveChars() error {
charResolved = false
}
if charResolved {
log.Debug().
log.Debug("Resolved characteristic").
Str("uuid", char.Properties.UUID).
Str("name", charNames[char.Properties.UUID]).
Msg("Resolved characteristic")
Send()
}
}
return nil
@ -559,7 +559,7 @@ func (i *Device) WatchHeartRate(ctx context.Context) (<-chan uint8, error) {
for {
select {
case <-ctx.Done():
log.Debug().Str("func", "WatchMotion").Msg("Received done signal")
log.Debug("Received done signal").Str("func", "WatchMotion").Send()
close(out)
i.heartRateChar.StopNotify()
return
@ -569,7 +569,7 @@ func (i *Device) WatchHeartRate(ctx context.Context) (<-chan uint8, error) {
// Send heart rate to channel
out <- uint8(event.Value.([]byte)[1])
} else if event.Name == "Notifying" && !event.Value.(bool) {
log.Debug().Str("func", "WatchMotion").Msg("Notifications stopped, restarting")
log.Debug("Notifications stopped, restarting").Str("func", "WatchMotion").Send()
i.heartRateChar.StartNotify()
}
}
@ -603,7 +603,7 @@ func (i *Device) WatchBatteryLevel(ctx context.Context) (<-chan uint8, error) {
for {
select {
case <-ctx.Done():
log.Debug().Str("func", "WatchMotion").Msg("Received done signal")
log.Debug("Received done signal").Str("func", "WatchMotion").Send()
close(out)
i.battLevelChar.StopNotify()
return
@ -613,7 +613,7 @@ func (i *Device) WatchBatteryLevel(ctx context.Context) (<-chan uint8, error) {
// Send heart rate to channel
out <- uint8(event.Value.([]byte)[0])
} else if event.Name == "Notifying" && !event.Value.(bool) {
log.Debug().Str("func", "WatchMotion").Msg("Notifications stopped, restarting")
log.Debug("Notifications stopped, restarting").Str("func", "WatchMotion").Send()
i.battLevelChar.StartNotify()
}
}
@ -647,7 +647,7 @@ func (i *Device) WatchStepCount(ctx context.Context) (<-chan uint32, error) {
for {
select {
case <-ctx.Done():
log.Debug().Str("func", "WatchMotion").Msg("Received done signal")
log.Debug("Received done signal").Str("func", "WatchMotion").Send()
close(out)
i.stepCountChar.StopNotify()
return
@ -657,7 +657,7 @@ func (i *Device) WatchStepCount(ctx context.Context) (<-chan uint32, error) {
// Send step count to channel
out <- binary.LittleEndian.Uint32(event.Value.([]byte))
} else if event.Name == "Notifying" && !event.Value.(bool) {
log.Debug().Str("func", "WatchMotion").Msg("Notifications stopped, restarting")
log.Debug("Notifications stopped, restarting").Str("func", "WatchMotion").Send()
i.stepCountChar.StartNotify()
}
}
@ -691,7 +691,7 @@ func (i *Device) WatchMotion(ctx context.Context) (<-chan MotionValues, error) {
for {
select {
case <-ctx.Done():
log.Debug().Str("func", "WatchMotion").Msg("Received done signal")
log.Debug("Received done signal").Str("func", "WatchMotion").Send()
close(out)
i.motionValChar.StopNotify()
return
@ -703,7 +703,7 @@ func (i *Device) WatchMotion(ctx context.Context) (<-chan MotionValues, error) {
// Send step count to channel
out <- motionVals
} else if event.Name == "Notifying" && !event.Value.(bool) {
log.Debug().Str("func", "WatchMotion").Msg("Notifications stopped, restarting")
log.Debug("Notifications stopped, restarting").Str("func", "WatchMotion").Send()
i.motionValChar.StartNotify()
}
}
@ -759,8 +759,8 @@ func (i *Device) SetTime(t time.Time) error {
offset -= 3600
}
bufTz := &bytes.Buffer{}
binary.Write(bufTz, binary.LittleEndian, uint8(offset / 3600 * 4))
binary.Write(bufTz, binary.LittleEndian, uint8(dst / 3600 * 4))
binary.Write(bufTz, binary.LittleEndian, uint8(offset/3600*4))
binary.Write(bufTz, binary.LittleEndian, uint8(dst/3600*4))
return i.localTimeChar.WriteValue(bufTz.Bytes(), nil)
}
@ -866,13 +866,13 @@ func (i *Device) AddWeatherEvent(event interface{}) error {
return err
}
log.Debug().Interface("event", event).Msg("Adding weather event")
log.Debug("Adding weather event").Any("event", event).Send()
// Write data to weather data characteristic
return i.weatherDataChar.WriteValue(data, nil)
}
func (i *Device) checkStatus(char *gatt.GattCharacteristic1, uuid string) error {
log.Debug().Msg("Checking characteristic status")
log.Debug("Checking characteristic status").Send()
connected, err := i.device.GetConnected()
if err != nil {
return err
@ -881,12 +881,12 @@ func (i *Device) checkStatus(char *gatt.GattCharacteristic1, uuid string) error
return ErrNotConnected
}
if char == nil {
log.Debug().Msg("Characteristic not available (nil)")
log.Debug("Characteristic not available (nil)").Send()
return ErrCharNotAvail{uuid}
}
log.Debug().
log.Debug("Characteristic available").
Str("uuid", char.Properties.UUID).
Str("name", charNames[char.Properties.UUID]).
Msg("Characteristic available")
Send()
return nil
}

View file

@ -72,7 +72,7 @@ func (mc MusicCtrl) WatchEvents() (<-chan MusicEvent, error) {
for event := range ch {
// If value changes
if event.Name == "Value" {
log.Debug().Bytes("value", event.Value.([]byte)).Msg("Received music event from watch")
log.Debug("Received music event from watch").Bytes("value", event.Value.([]byte)).Send()
// Send music event to channel
musicEventCh <- MusicEvent(event.Value.([]byte)[0])
}

View file

@ -2,6 +2,7 @@ package infinitime
import (
"errors"
"github.com/muka/go-bluetooth/bluez/profile/gatt"
)
@ -119,7 +120,7 @@ const (
)
func (n *NavigationService) SetFlag(flag NavFlag) error {
log.Debug().Str("func", "SetFlag").Msg("Sending flag")
log.Debug("Sending flag").Str("func", "SetFlag").Send()
if err := n.dev.checkStatus(n.flagsChar, NavFlagsChar); err != nil {
return err
}
@ -127,7 +128,7 @@ func (n *NavigationService) SetFlag(flag NavFlag) error {
}
func (n *NavigationService) SetNarrative(narrative string) error {
log.Debug().Str("func", "SetNarrative").Msg("Sending narrative")
log.Debug("Sending narrative").Str("func", "SetNarrative").Send()
if err := n.dev.checkStatus(n.narrativeChar, NavNarrativeChar); err != nil {
return err
}
@ -135,7 +136,7 @@ func (n *NavigationService) SetNarrative(narrative string) error {
}
func (n *NavigationService) SetManDist(manDist string) error {
log.Debug().Str("func", "SetNarrative").Msg("Sending maneuver distance")
log.Debug("Sending maneuver distance").Str("func", "SetNarrative").Send()
if err := n.dev.checkStatus(n.mandistChar, NavManDistChar); err != nil {
return err
}
@ -143,7 +144,7 @@ func (n *NavigationService) SetManDist(manDist string) error {
}
func (n *NavigationService) SetProgress(progress uint8) error {
log.Debug().Str("func", "SetNarrative").Msg("Sending progress")
log.Debug("Sending progress").Str("func", "SetNarrative").Send()
if err := n.dev.checkStatus(n.progressChar, NavProgressChar); err != nil {
return err
}

View file

@ -80,7 +80,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
m.Close()
log.Debug().Msg("Decoded manifest file")
log.Debug("Decoded manifest file").Send()
go func() {
defer close(out)
@ -88,7 +88,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
for _, file := range manifest.Obsolete {
name := filepath.Base(file.Path)
log.Debug().Str("file", file.Path).Msg("Removing file")
log.Debug("Removing file").Str("file", file.Path).Send()
err := fs.RemoveAll(file.Path)
if err != nil {
@ -100,7 +100,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return
}
log.Debug().Str("file", file.Path).Msg("Removed file")
log.Debug("Removed file").Str("file", file.Path).Send()
out <- ResourceLoadProgress{
Name: name,
@ -131,11 +131,11 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return
}
log.Debug().Str("file", file.Path).Msg("Making directories")
log.Debug("Making directories").Str("file", file.Path).Send()
err = fs.MkdirAll(filepath.Dir(file.Path))
if err != nil {
log.Debug().Err(err).Msg("Error making directories")
log.Debug("Error making directories").Err(err).Send()
out <- ResourceLoadProgress{
Name: file.Name,
Operation: ResourceOperationUpload,
@ -146,14 +146,14 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return
}
log.Debug().
log.Debug("Creating file").
Str("file", file.Path).
Int64("size", srcFi.Size()).
Msg("Creating file")
Send()
dst, err := fs.Create(file.Path, uint32(srcFi.Size()))
if err != nil {
log.Debug().Err(err).Msg("Error creating file")
log.Debug("Error creating file").Err(err).Send()
out <- ResourceLoadProgress{
Name: file.Name,
Operation: ResourceOperationUpload,
@ -167,10 +167,10 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
progCh := dst.Progress()
go func() {
for sent := range progCh {
log.Debug().
log.Debug("Progress event sent").
Int64("total", srcFi.Size()).
Uint32("sent", sent).
Msg("Progress event sent")
Send()
out <- ResourceLoadProgress{
Name: file.Name,
@ -187,7 +187,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
n, err := io.Copy(dst, src)
if err != nil {
log.Debug().Err(err).Msg("Error writing to file")
log.Debug("Error writing to file").Err(err).Send()
out <- ResourceLoadProgress{
Name: file.Name,
Operation: ResourceOperationUpload,