Log messages cleanup (#158)

This commit is contained in:
C Cirello
2016-10-13 18:11:31 +02:00
committed by Seif Lotfy سيف لطفي
parent 4cbfb3ccfd
commit 34b4b25092
5 changed files with 18 additions and 11 deletions

View File

@@ -15,7 +15,7 @@ func New(dbURL string) (models.Datastore, error) {
if err != nil { if err != nil {
logrus.WithFields(logrus.Fields{"url": dbURL}).Fatal("bad DB URL") logrus.WithFields(logrus.Fields{"url": dbURL}).Fatal("bad DB URL")
} }
logrus.WithFields(logrus.Fields{"db": u.Scheme}).Info("creating new datastore") logrus.WithFields(logrus.Fields{"db": u.Scheme}).Debug("creating new datastore")
switch u.Scheme { switch u.Scheme {
case "bolt": case "bolt":
return bolt.New(u) return bolt.New(u)

View File

@@ -15,7 +15,7 @@ func New(mqURL string) (models.MessageQueue, error) {
if err != nil { if err != nil {
logrus.WithError(err).WithFields(logrus.Fields{"url": mqURL}).Fatal("bad MQ URL") logrus.WithError(err).WithFields(logrus.Fields{"url": mqURL}).Fatal("bad MQ URL")
} }
logrus.WithFields(logrus.Fields{"mq": u.Scheme}).Info("selecting MQ") logrus.WithFields(logrus.Fields{"mq": u.Scheme}).Debug("selecting MQ")
switch u.Scheme { switch u.Scheme {
case "memory": case "memory":
return NewMemoryMQ(), nil return NewMemoryMQ(), nil

View File

@@ -128,23 +128,24 @@ func startAsyncRunners(ctx context.Context, wg *sync.WaitGroup, i int, url strin
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
continue continue
} }
log.Info("Picked up task:", task.ID) log.Debug("Picked up task:", task.ID)
log.Info("Running task:", task.ID) log.Debug("Running task:", task.ID)
// Process Task // Process Task
if _, err := runTask(task); err != nil { if _, err := runTask(task); err != nil {
log.WithError(err).WithFields(log.Fields{"async runner": i, "task_id": task.ID}).Error("Cannot run task") log.WithError(err).WithFields(log.Fields{"async runner": i, "task_id": task.ID}).Error("Cannot run task")
continue continue
} }
log.Info("Processed task:", task.ID) log.Debug("Processed task:", task.ID)
// Delete task from queue // Delete task from queue
if err := deleteTask(url, task); err != nil { if err := deleteTask(url, task); err != nil {
log.WithError(err).WithFields(log.Fields{"async runner": i, "task_id": task.ID}).Error("Cannot delete task") log.WithError(err).WithFields(log.Fields{"async runner": i, "task_id": task.ID}).Error("Cannot delete task")
continue continue
} }
log.Debug("Deleted task:", task.ID)
log.Info("Deleted task:", task.ID) log.Info("Task complete:", task.ID)
} }
} }
} }

View File

@@ -98,7 +98,7 @@ func (s *Server) handleTaskRequest(c *gin.Context) {
case "GET": case "GET":
task, err := s.MQ.Reserve(ctx) task, err := s.MQ.Reserve(ctx)
if err != nil { if err != nil {
logrus.WithError(err) logrus.WithError(err).Error()
c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesList)) c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesList))
return return
} }
@@ -106,19 +106,19 @@ func (s *Server) handleTaskRequest(c *gin.Context) {
case "DELETE": case "DELETE":
body, err := ioutil.ReadAll(c.Request.Body) body, err := ioutil.ReadAll(c.Request.Body)
if err != nil { if err != nil {
logrus.WithError(err) logrus.WithError(err).Error()
c.JSON(http.StatusInternalServerError, err) c.JSON(http.StatusInternalServerError, err)
return return
} }
var task models.Task var task models.Task
if err = json.Unmarshal(body, &task); err != nil { if err = json.Unmarshal(body, &task); err != nil {
logrus.WithError(err) logrus.WithError(err).Error()
c.JSON(http.StatusInternalServerError, err) c.JSON(http.StatusInternalServerError, err)
return return
} }
if err := s.MQ.Delete(ctx, &task); err != nil { if err := s.MQ.Delete(ctx, &task); err != nil {
logrus.WithError(err) logrus.WithError(err).Error()
c.JSON(http.StatusInternalServerError, err) c.JSON(http.StatusInternalServerError, err)
return return
} }

View File

@@ -9,6 +9,7 @@ import (
"sync" "sync"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/datastore" "github.com/iron-io/functions/api/datastore"
"github.com/iron-io/functions/api/mqs" "github.com/iron-io/functions/api/mqs"
"github.com/iron-io/functions/api/runner" "github.com/iron-io/functions/api/runner"
@@ -46,6 +47,11 @@ func init() {
log.WithError(err).Fatalln("Invalid log level.") log.WithError(err).Fatalln("Invalid log level.")
} }
log.SetLevel(logLevel) log.SetLevel(logLevel)
gin.SetMode(gin.ReleaseMode)
if logLevel == log.DebugLevel {
gin.SetMode(gin.DebugMode)
}
} }
func main() { func main() {
@@ -74,7 +80,7 @@ func main() {
} }
apiURL, port, numAsync := viper.GetString(envAPIURL), viper.GetString(envPort), viper.GetInt(envNumAsync) apiURL, port, numAsync := viper.GetString(envAPIURL), viper.GetString(envPort), viper.GetInt(envNumAsync)
log.Info("async workers:", numAsync) log.Debug("async workers:", numAsync)
var wgAsync sync.WaitGroup var wgAsync sync.WaitGroup
if numAsync > 0 { if numAsync > 0 {
wgAsync.Add(1) wgAsync.Add(1)