Skip to content

Commit

Permalink
Merge pull request #38 from CameronRP/update-logging
Browse files Browse the repository at this point in the history
Update logging and go version
  • Loading branch information
CameronRP authored Aug 28, 2024
2 parents 977ba8f + 0666f16 commit daab0cc
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- "1.17.x"
- "1.22.x"

script:
- go mod tidy
Expand All @@ -17,4 +17,4 @@ deploy:
script: curl -sL https://git.io/goreleaser | bash
on:
tags: true
go: "1.17.x"
go: "1.22.x"
9 changes: 7 additions & 2 deletions cmd/event-reporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ package main

import (
"encoding/json"
"log"
"os"
"strconv"
"strings"
"time"

"github.com/TheCacophonyProject/event-reporter/v3/eventclient"
"github.com/TheCacophonyProject/event-reporter/v3/eventstore"
"github.com/TheCacophonyProject/go-utils/logging"
"github.com/TheCacophonyProject/modemd/connrequester"
"github.com/TheCacophonyProject/modemd/modemlistener"
arg "github.com/alexflint/go-arg"
"github.com/sirupsen/logrus"

"github.com/TheCacophonyProject/go-api"
)
Expand All @@ -43,10 +44,12 @@ const (
)

var version = "No version provided"
var log *logrus.Logger

type argSpec struct {
DBPath string `arg:"-d,--db" help:"path to state database"`
Interval time.Duration `arg:"--interval" help:"time between event reports"`
logging.LogArgs
}

func (argSpec) Version() string {
Expand All @@ -72,7 +75,9 @@ func main() {

func runMain() error {
args := procArgs()
log.SetFlags(0) // Removes default timestamp flag

log = logging.NewLogger(args.LogLevel)

log.Printf("running version: %s", version)

store, err := eventstore.Open(args.DBPath)
Expand Down
1 change: 0 additions & 1 deletion cmd/event-reporter/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package main
import (
"encoding/json"
"errors"
"log"
"time"

"github.com/godbus/dbus"
Expand Down
26 changes: 24 additions & 2 deletions cmd/service-watcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ package main
import (
"context"
"encoding/json"
"log"
"os/exec"
"strconv"
"strings"
"time"

"github.com/TheCacophonyProject/event-reporter/v3/eventclient"
"github.com/TheCacophonyProject/go-utils/logging"
"github.com/alexflint/go-arg"
systemdbus "github.com/coreos/go-systemd/v22/dbus"
)

Expand All @@ -36,6 +37,23 @@ const (
numLogLines = 20 //TODO add into cacophony-config
)

var log = logging.NewLogger("info")
var version = "<not set>"

type argSpec struct {
logging.LogArgs
}

func (argSpec) Version() string {
return version
}

func procArgs() argSpec {
args := argSpec{}
arg.MustParse(&args)
return args
}

type LogReport struct {
Logs *[]string
Time int64
Expand All @@ -58,7 +76,11 @@ func main() {
}

func runMain() error {
log.SetFlags(0) // Removes default timestamp flag
args := procArgs()

log = logging.NewLogger(args.LogLevel)

log.Info("Running version: ", version)

conn, err := systemdbus.NewWithContext(context.Background())
if err != nil {
Expand Down
26 changes: 24 additions & 2 deletions cmd/version-reporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,33 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
package main

import (
"log"
"os/exec"
"runtime"
"strings"
"time"

"github.com/TheCacophonyProject/event-reporter/v3/eventclient"
"github.com/TheCacophonyProject/go-utils/logging"
"github.com/alexflint/go-arg"
)

var log = logging.NewLogger("info")
var version = "<not set>"

type argSpec struct {
logging.LogArgs
}

func (argSpec) Version() string {
return version
}

func procArgs() argSpec {
args := argSpec{}
arg.MustParse(&args)
return args
}

func main() {
err := runMain()
if err != nil {
Expand All @@ -36,7 +54,11 @@ func main() {
}

func runMain() error {
log.SetFlags(0) // Removes default timestamp flag
args := procArgs()

log = logging.NewLogger(args.LogLevel)

log.Info("Running version: ", version)

packageMpedData, err := getInstalledPackages()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion eventstore/eventstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"time"

"github.com/TheCacophonyProject/go-utils/logging"
"github.com/boltdb/bolt"
)

Expand All @@ -36,6 +36,7 @@ const (

var oldBucketName = []byte("events")
var idDataBucketName = []byte("id-data-events") // Bucket with the key being a uint64 and the value being a json
var log = logging.NewLogger("info")

// EventStore perists details for events which are to be sent to the
// Cacophony Events API.
Expand Down
10 changes: 4 additions & 6 deletions eventstore/eventstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package eventstore

import (
"encoding/json"
"io/ioutil"
"log"
"os"
"path/filepath"
"testing"
Expand All @@ -39,7 +37,7 @@ type Suite struct {
}

func (suite *Suite) SetupTest() {
tempDir, err := ioutil.TempDir(os.TempDir(), "eventstore_test")
tempDir, err := os.MkdirTemp(os.TempDir(), "eventstore_test")
suite.Require().NoError(err)
suite.tempDir = tempDir

Expand Down Expand Up @@ -137,15 +135,15 @@ func (s *Suite) TestAddAndGet() {
time2 := Now().Add(time.Second)
time3 := Now().Add(2 * time.Second)
events := map[int64]Event{
time1.Unix(): Event{
time1.Unix(): {
Description: EventDescription{Details: map[string]interface{}{"file": "abc"}, Type: "type1"},
Timestamp: time1,
},
time2.Unix(): Event{
time2.Unix(): {
Timestamp: time2,
Description: EventDescription{Details: map[string]interface{}{"file": "abc"}, Type: "type1"},
},
time3.Unix(): Event{
time3.Unix(): {
Timestamp: time3,
Description: EventDescription{Details: map[string]interface{}{"file": "abc"}, Type: "type1"},
},
Expand Down
29 changes: 28 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
module github.com/TheCacophonyProject/event-reporter/v3

go 1.15
go 1.22.3

require (
github.com/TheCacophonyProject/go-api v1.0.4
github.com/TheCacophonyProject/go-utils v0.1.1
github.com/TheCacophonyProject/modemd v1.6.0
github.com/alexflint/go-arg v1.4.2
github.com/boltdb/bolt v1.3.1
github.com/coreos/go-systemd/v22 v22.3.2
github.com/godbus/dbus v4.1.0+incompatible
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.7.0
)

require (
github.com/TheCacophonyProject/go-config v1.9.0 // indirect
github.com/alexflint/go-scalar v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.9.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.64.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/TheCacophonyProject/go-api v1.0.4/go.mod h1:F7UUNgsLhbw7hsiNBMRB9kQz9
github.com/TheCacophonyProject/go-config v0.0.0-20190922224052-7c2a21bc6b88/go.mod h1:gPUJLVu408NRz9/P3BrsxzOzLc+KJLrv+jVdDw3RI0Y=
github.com/TheCacophonyProject/go-config v1.9.0 h1:uangUL8e/76ApGzF2tYGKDm+DoDjezVhuJquTX41rHQ=
github.com/TheCacophonyProject/go-config v1.9.0/go.mod h1:+y80PSRZudMYuVrYTGOvzc66NxVJWKS4TuU442vmvhY=
github.com/TheCacophonyProject/go-utils v0.1.1 h1:VOt9EphEqRUYMqKJlJeliIarIMlCVKYGb1fdqM6b4YM=
github.com/TheCacophonyProject/go-utils v0.1.1/go.mod h1:jZPUZ4GtYVxnlTtqiYKMFWDT//kmxdbwjLW3HCyCmCE=
github.com/TheCacophonyProject/modemd v0.0.0-20190605010435-ae5b0f2eb760/go.mod h1:bfwJ/WcvDY9XtHKC5tcRfVrU8RWaW8DLYAAUfsrJr/4=
github.com/TheCacophonyProject/modemd v1.6.0 h1:o2Rp44VRKzk5OvgqjNgx7RBLYqsJBR4HAyPShnH80/0=
github.com/TheCacophonyProject/modemd v1.6.0/go.mod h1:0M7yJCdqhvoI5dVeDjOH6vsmbOBr1YhZ8DpAK4AkOA0=
Expand Down Expand Up @@ -93,7 +95,6 @@ github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkE
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand Down Expand Up @@ -324,6 +325,8 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
github.com/sagikazarmark/crypt v0.1.0/go.mod h1:B/mN0msZuINBtQ1zZLEQcegFJJf9vnYIR88KRMEuODE=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down Expand Up @@ -552,8 +555,9 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 h1:kwrAHlwJ0DUBZwQ238v+Uod/3eZ8B2K5rYsUHBQvzmI=
golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down

0 comments on commit daab0cc

Please sign in to comment.