🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Better log and less noise in prod mode
Deluancdefabf7601d
diff --git a/api/media_annotation.go b/api/media_annotation.goindex 7ef670031..01a0067e0 100644--- a/api/media_annotation.go+++ b/api/media_annotation.go@@ -1,10 +1,12 @@package apiimport (+ "fmt""time""github.com/astaxie/beego""github.com/deluan/gosonic/api/responses"+ "github.com/deluan/gosonic/domain""github.com/deluan/gosonic/itunesbridge""github.com/deluan/gosonic/utils")@@ -12,10 +14,11 @@ import (type MediaAnnotationController struct {BaseAPIControlleritunes itunesbridge.ItunesControl+ mfRepo domain.MediaFileRepository}func (c *MediaAnnotationController) Prepare() {- utils.ResolveDependencies(&c.itunes)+ utils.ResolveDependencies(&c.itunes, &c.mfRepo)}func (c *MediaAnnotationController) Scrobble() {@@ -24,7 +27,13 @@ func (c *MediaAnnotationController) Scrobble() {submission := c.ParamBool("submission", true)if submission {- beego.Debug("Scrobbling", id, "at", time)+ mf, err := c.mfRepo.Get(id)+ if err != nil || mf == nil {+ beego.Error("Id", id, "not found!")+ c.SendError(responses.ERROR_DATA_NOT_FOUND, "Id not found")+ }++ beego.Info(fmt.Sprintf(`Scrobbling (%s) "%s" at %v`, id, mf.Title, time))if err := c.itunes.Scrobble(id, time); err != nil {beego.Error("Error scrobbling:", err)c.SendError(responses.ERROR_GENERIC, "Internal error")diff --git a/api/validation.go b/api/validation.goindex 4aab3b48e..0548628a3 100644--- a/api/validation.go+++ b/api/validation.go@@ -4,6 +4,8 @@ import ("encoding/hex""strings"+ "fmt"+"github.com/astaxie/beego""github.com/deluan/gosonic/api/responses")@@ -14,7 +16,7 @@ type ControllerInterface interface {SendError(errorCode int, message ...interface{})}-func Validate(controller ControllerInterface) {+func Validate(controller BaseAPIController) {if beego.AppConfig.String("disableValidation") != "true" {checkParameters(controller)authenticate(controller)@@ -22,18 +24,18 @@ func Validate(controller ControllerInterface) {}}-func checkParameters(c ControllerInterface) {+func checkParameters(c BaseAPIController) {requiredParameters := []string{"u", "p", "v", "c"}for _, p := range requiredParameters {if c.GetString(p) == "" {- beego.Warn("Missing required parameter:", p)+ logWarn(c, fmt.Sprintf(`Missing required parameter "%s"`, p))abortRequest(c, responses.ERROR_MISSING_PARAMETER)}}}-func authenticate(c ControllerInterface) {+func authenticate(c BaseAPIController) {user := c.GetString("u")pass := c.GetString("p")if strings.HasPrefix(pass, "enc:") {@@ -43,11 +45,15 @@ func authenticate(c ControllerInterface) {}}if user != beego.AppConfig.String("user") || pass != beego.AppConfig.String("password") {- beego.Warn("Invalid login:", user)+ logWarn(c, fmt.Sprintf(`Invalid login for user "%s"`, user))abortRequest(c, responses.ERROR_AUTHENTICATION_FAIL)}}-func abortRequest(c ControllerInterface, code int) {+func abortRequest(c BaseAPIController, code int) {c.SendError(code)}++func logWarn(c BaseAPIController, msg string) {+ beego.Warn(fmt.Sprintf("%s?%s: %s", c.Ctx.Request.URL.Path, c.Ctx.Request.URL.RawQuery, msg))+}diff --git a/conf/router.go b/conf/router.goindex d7f233353..922c97f3f 100644--- a/conf/router.go+++ b/conf/router.go@@ -52,7 +52,7 @@ func mapControllers() {func mapFilters() {var ValidateRequest = func(ctx *context.Context) {- c := &api.BaseAPIController{}+ c := api.BaseAPIController{}c.Ctx = ctxapi.Validate(c)}diff --git a/scanner/importer.go b/scanner/importer.goindex 5a8962391..d84b50790 100644--- a/scanner/importer.go+++ b/scanner/importer.go@@ -102,7 +102,7 @@ func (i *Importer) Run() {if err := i.importLibrary(); err != nil {beego.Error("Error persisting data:", err)}- beego.Info("Finished importing tracks from iTunes Library")+ beego.Debug("Finished importing tracks from iTunes Library")}func (i *Importer) lastModifiedSince() time.Time {@@ -126,6 +126,12 @@ func (i *Importer) importLibrary() (err error) {als := make(domain.Albums, len(i.scanner.Albums()))ars := make(domain.Artists, len(i.scanner.Artists()))pls := make(domain.Playlists, len(i.scanner.Playlists()))+ arc, _ := i.artistRepo.CountAll()+ alc, _ := i.albumRepo.CountAll()+ mfc, _ := i.mfRepo.CountAll()+ plc, _ := i.plsRepo.CountAll()+ alu := 0+ mfu := 0i.search.ClearAll()@@ -143,6 +149,7 @@ func (i *Importer) importLibrary() (err error) {if err := i.search.IndexMediaFile(mf); err != nil {beego.Error("Error indexing artist:", err)}+ mfu++if !i.lastScan.IsZero() {beego.Debug("-- Updated Track:", mf.Title)}@@ -161,6 +168,7 @@ func (i *Importer) importLibrary() (err error) {if err := i.search.IndexAlbum(al); err != nil {beego.Error("Error indexing artist:", err)}+ alu++if !i.lastScan.IsZero() {beego.Debug(fmt.Sprintf(`-- Updated Album:"%s" from "%s"`, al.Name, al.Artist))}@@ -206,19 +214,22 @@ func (i *Importer) importLibrary() (err error) {beego.Error(err)}- c, _ := i.artistRepo.CountAll()- beego.Info("Total Artists in database:", c)- c, _ = i.albumRepo.CountAll()- beego.Info("Total Albums in database:", c)- c, _ = i.mfRepo.CountAll()- beego.Info("Total MediaFiles in database:", c)- c, _ = i.plsRepo.CountAll()- beego.Info("Total Playlists in database:", c)+ arc2, _ := i.artistRepo.CountAll()+ alc2, _ := i.albumRepo.CountAll()+ mfc2, _ := i.mfRepo.CountAll()+ plc2, _ := i.plsRepo.CountAll()++ if arc != arc2 || alc != alc2 || mfc != mfc2 || plc != plc2 {+ beego.Info(fmt.Sprintf("Updated library totals: %d(%+d) artists, %d(%+d) albums, %d(%+d) songs, %d(%+d) playlists", arc2, arc2-arc, alc2, alc2-alc, mfc2, mfc2-mfc, plc2, plc2-plc))+ }+ if alu > 0 || mfu > 0 {+ beego.Info(fmt.Sprintf("Updated items: %d album(s), %d song(s)", alu, mfu))+ }if err == nil {millis := time.Now().UnixNano() / int64(time.Millisecond)i.propertyRepo.Put(consts.LastScan, fmt.Sprint(millis))- beego.Info("LastScan timestamp:", millis)+ beego.Debug("LastScan timestamp:", millis)}return errdiff --git a/scanner/itunes_scanner.go b/scanner/itunes_scanner.goindex 5342ea1d2..b8588cd9b 100644--- a/scanner/itunes_scanner.go+++ b/scanner/itunes_scanner.go@@ -47,7 +47,7 @@ type plsRelation struct {}func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (int, error) {- beego.Info("Checking for updates since", lastModifiedSince.String(), "- Library:", path)+ beego.Debug("Checking for updates since", lastModifiedSince.String(), "- Library:", path)xml, _ := os.Open(path)l, err := itl.ReadFromXML(xml)if err != nil {