diff --git a/.travis.yml b/.travis.yml index 2405a5f..176fcc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - "1.20.x" + - "1.22.x" script: - go mod tidy @@ -17,4 +17,4 @@ deploy: script: make release on: tags: true - go: "1.20.x" + go: "1.22.x" diff --git a/api/api.go b/api/api.go index 3979599..1368d6a 100644 --- a/api/api.go +++ b/api/api.go @@ -24,7 +24,6 @@ import ( "errors" "fmt" "io" - "log" "math/rand" "net" "net/http" @@ -51,8 +50,11 @@ import ( "github.com/TheCacophonyProject/trap-controller/trapdbusclient" netmanagerclient "github.com/TheCacophonyProject/rpi-net-manager/netmanagerclient" + "github.com/sirupsen/logrus" ) +var log *logrus.Logger + const ( cptvGlob = "*.cptv" failedUploadsFolder = "failed-uploads" @@ -68,7 +70,8 @@ type ManagementAPI struct { appVersion string } -func NewAPI(router *mux.Router, config *goconfig.Config, appVersion string) (*ManagementAPI, error) { +func NewAPI(router *mux.Router, config *goconfig.Config, appVersion string, l *logrus.Logger) (*ManagementAPI, error) { + log = l thermalRecorder := goconfig.DefaultThermalRecorder() if err := config.Unmarshal(goconfig.ThermalRecorderKey, &thermalRecorder); err != nil { return nil, err diff --git a/api/audiorecording.go b/api/audiorecording.go index 6d12c48..0054871 100644 --- a/api/audiorecording.go +++ b/api/audiorecording.go @@ -20,7 +20,6 @@ package api import ( "encoding/json" - "log" "net/http" goconfig "github.com/TheCacophonyProject/go-config" diff --git a/api/clock.go b/api/clock.go index d645890..650b45b 100644 --- a/api/clock.go +++ b/api/clock.go @@ -21,7 +21,6 @@ package api import ( "encoding/json" "fmt" - "log" "net/http" "os/exec" "strings" diff --git a/cmd/managementd/main.go b/cmd/managementd/main.go index 426ce72..5491639 100644 --- a/cmd/managementd/main.go +++ b/cmd/managementd/main.go @@ -25,7 +25,6 @@ import ( "encoding/json" "fmt" "io" - "log" "net" "net/http" "os" @@ -41,11 +40,14 @@ import ( goconfig "github.com/TheCacophonyProject/go-config" "github.com/TheCacophonyProject/go-cptv/cptvframe" + "github.com/TheCacophonyProject/go-utils/logging" "github.com/TheCacophonyProject/lepton3" managementinterface "github.com/TheCacophonyProject/management-interface" "github.com/TheCacophonyProject/management-interface/api" netmanagerclient "github.com/TheCacophonyProject/rpi-net-manager/netmanagerclient" "github.com/TheCacophonyProject/thermal-recorder/headers" + "github.com/alexflint/go-arg" + "github.com/sirupsen/logrus" ) const ( @@ -62,11 +64,29 @@ var ( headerInfo *headers.HeaderInfo frameCh = make(chan *FrameData, 4) currentFrame = -1 + log *logrus.Logger ) +type Args struct { + logging.LogArgs +} + +func (Args) Version() string { + return version +} + +func procArgs() Args { + args := Args{} + arg.MustParse(&args) + return args +} + // Set up and handle page requests. func main() { - log.SetFlags(0) // Removes timestamp output + args := procArgs() + + log = logging.NewLogger(args.LogLevel) + log.Printf("running version: %s", version) config, err := ParseConfig(configDir) @@ -121,7 +141,7 @@ func main() { // API apiRouter := router.PathPrefix("/api").Subrouter() - apiObj, err := api.NewAPI(apiRouter, config.config, version) + apiObj, err := api.NewAPI(apiRouter, config.config, version, log) if err != nil { log.Fatal(err) return diff --git a/cmd/signal-strength/main.go b/cmd/signal-strength/main.go index cc91ad9..99183e9 100644 --- a/cmd/signal-strength/main.go +++ b/cmd/signal-strength/main.go @@ -19,13 +19,13 @@ along with this program. If not, see . package main import ( - "log" - + "github.com/TheCacophonyProject/go-utils/logging" signalstrength "github.com/TheCacophonyProject/management-interface/signal-strength" ) +var log = logging.NewLogger("info") + func main() { - log.SetFlags(0) sig, err := signalstrength.Run() if err != nil { log.Fatal(err) diff --git a/go.mod b/go.mod index ee86ca2..cc54b73 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/TheCacophonyProject/management-interface -go 1.20 +go 1.22.3 require ( github.com/TheCacophonyProject/audiobait/v3 v3.0.1 @@ -19,9 +19,12 @@ require ( ) require ( + github.com/TheCacophonyProject/go-utils v0.1.1 github.com/TheCacophonyProject/rpi-net-manager v0.4.0-deb12 github.com/TheCacophonyProject/thermal-recorder v1.22.1-0.20230627011240-89964c0511f7 github.com/TheCacophonyProject/trap-controller v0.0.0-20230227002937-262a1adfaa47 + github.com/alexflint/go-arg v1.4.3 + github.com/sirupsen/logrus v1.9.3 golang.org/x/text v0.16.0 ) @@ -29,6 +32,7 @@ require ( require ( github.com/TheCacophonyProject/event-reporter/v3 v3.7.0 // indirect github.com/TheCacophonyProject/window v0.0.0-20200312071457-7fc8799fdce7 // indirect + github.com/alexflint/go-scalar v1.1.0 // indirect github.com/boltdb/bolt v1.3.1 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/gobuffalo/envy v1.10.2 // indirect diff --git a/go.sum b/go.sum index fdc536b..ea4327c 100644 --- a/go.sum +++ b/go.sum @@ -71,6 +71,8 @@ github.com/TheCacophonyProject/go-cptv v0.0.0-20200616224711-fc633122087a/go.mod github.com/TheCacophonyProject/go-cptv v0.0.0-20200818214604-bd5d4aa36043/go.mod h1:wG4/P/TsGtk33uBClYPjRlSbcdQrIASXutOUV8LMn2o= github.com/TheCacophonyProject/go-cptv v0.0.0-20211109233846-8c32a5d161f7 h1:sf9KTj7u3mFMx5NsLpQtf8FtP3BDZAgtHutanDygQgk= github.com/TheCacophonyProject/go-cptv v0.0.0-20211109233846-8c32a5d161f7/go.mod h1:T74NuMjo2YrLoyhAd0+9hj2pgVt8F7DWWzTMlU8aH6k= +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/lepton3 v0.0.0-20200121020734-2ae28662e1bc/go.mod h1:xzPAWtvVCbJdJC2Gn1cG0Ovs/VP7XGGiQpUU8wU4HME= github.com/TheCacophonyProject/lepton3 v0.0.0-20200213011619-1934a9300bd3/go.mod h1:xzPAWtvVCbJdJC2Gn1cG0Ovs/VP7XGGiQpUU8wU4HME= github.com/TheCacophonyProject/lepton3 v0.0.0-20200909032119-e2b2b778a8ee/go.mod h1:+FTQKx63hdEbuTe/nxNv9TQ2EWqdlzMZx7UNLGCX9SE= @@ -103,7 +105,10 @@ github.com/alexflint/go-arg v1.1.0/go.mod h1:3Rj4baqzWaGGmZA2+bVTV8zQOZEjBQAPBnL github.com/alexflint/go-arg v1.2.0/go.mod h1:3Rj4baqzWaGGmZA2+bVTV8zQOZEjBQAPBnL5xLT+ftY= github.com/alexflint/go-arg v1.3.0/go.mod h1:9iRbDxne7LcR/GSvEr7ma++GLpdIU1zrghf2y2768kM= github.com/alexflint/go-arg v1.4.2/go.mod h1:9iRbDxne7LcR/GSvEr7ma++GLpdIU1zrghf2y2768kM= +github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/uo= +github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA= github.com/alexflint/go-scalar v1.0.0/go.mod h1:GpHzbCOZXEKMEcygYQ5n/aa4Aq84zbxjy3MxYW0gjYw= +github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM= github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= @@ -141,6 +146,7 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -154,6 +160,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= @@ -237,6 +244,7 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -317,9 +325,11 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 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/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= @@ -370,6 +380,7 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -403,6 +414,8 @@ github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWR 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.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +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/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= @@ -666,6 +679,7 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBc 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/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/management-interface.go b/management-interface.go index 2d0a351..34cf620 100644 --- a/management-interface.go +++ b/management-interface.go @@ -23,7 +23,6 @@ import ( "html/template" "io" "io/ioutil" - "log" "net" "net/http" "os" @@ -38,10 +37,13 @@ import ( goconfig "github.com/TheCacophonyProject/go-config" "github.com/TheCacophonyProject/rpi-net-manager/netmanagerclient" + "github.com/TheCacophonyProject/go-utils/logging" "github.com/gobuffalo/packr" "github.com/gorilla/mux" ) +var log = logging.NewLogger("info") + // Using a packr box means the html files are bundled up in the binary application. var templateBox = packr.NewBox("./html")