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 {
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 {
case "bolt":
return bolt.New(u)

View File

@@ -15,7 +15,7 @@ func New(mqURL string) (models.MessageQueue, error) {
if err != nil {
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 {
case "memory":
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)
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
if _, err := runTask(task); err != nil {
log.WithError(err).WithFields(log.Fields{"async runner": i, "task_id": task.ID}).Error("Cannot run task")
continue
}
log.Info("Processed task:", task.ID)
log.Debug("Processed task:", task.ID)
// Delete task from queue
if err := deleteTask(url, task); err != nil {
log.WithError(err).WithFields(log.Fields{"async runner": i, "task_id": task.ID}).Error("Cannot delete task")
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":
task, err := s.MQ.Reserve(ctx)
if err != nil {
logrus.WithError(err)
logrus.WithError(err).Error()
c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesList))
return
}
@@ -106,19 +106,19 @@ func (s *Server) handleTaskRequest(c *gin.Context) {
case "DELETE":
body, err := ioutil.ReadAll(c.Request.Body)
if err != nil {
logrus.WithError(err)
logrus.WithError(err).Error()
c.JSON(http.StatusInternalServerError, err)
return
}
var task models.Task
if err = json.Unmarshal(body, &task); err != nil {
logrus.WithError(err)
logrus.WithError(err).Error()
c.JSON(http.StatusInternalServerError, err)
return
}
if err := s.MQ.Delete(ctx, &task); err != nil {
logrus.WithError(err)
logrus.WithError(err).Error()
c.JSON(http.StatusInternalServerError, err)
return
}

View File

@@ -9,6 +9,7 @@ import (
"sync"
log "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/datastore"
"github.com/iron-io/functions/api/mqs"
"github.com/iron-io/functions/api/runner"
@@ -46,6 +47,11 @@ func init() {
log.WithError(err).Fatalln("Invalid log level.")
}
log.SetLevel(logLevel)
gin.SetMode(gin.ReleaseMode)
if logLevel == log.DebugLevel {
gin.SetMode(gin.DebugMode)
}
}
func main() {
@@ -74,7 +80,7 @@ func main() {
}
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
if numAsync > 0 {
wgAsync.Add(1)