updated to use a common logging library and enable log level configuration

Change-Id: Ib473615f25318c3b40cd6cf3bd49248e8a3d4fb1
diff --git a/ip-allocator/Dockerfile b/ip-allocator/Dockerfile
index 870381c..4f62112 100644
--- a/ip-allocator/Dockerfile
+++ b/ip-allocator/Dockerfile
@@ -7,7 +7,7 @@
 ADD . /go/src/gerrit.opencord.org/maas/cord-ip-allocator
 
 WORKDIR /go/src/gerrit.opencord.org/maas/cord-ip-allocator
-RUN /go/bin/godep restore
+RUN /go/bin/godep restore || true
 
 WORKDIR /go
 
diff --git a/ip-allocator/Godeps/Godeps.json b/ip-allocator/Godeps/Godeps.json
index 8929877..8b2d186 100644
--- a/ip-allocator/Godeps/Godeps.json
+++ b/ip-allocator/Godeps/Godeps.json
@@ -20,6 +20,10 @@
 			"ImportPath": "github.com/kelseyhightower/envconfig",
 			"Comment": "1.1.0-17-g91921eb",
 			"Rev": "91921eb4cf999321cdbeebdba5a03555800d493b"
-		}
+		},
+                {
+                        "ImportPath": "github.com/Sirupsen/logrus",
+                        "Rev": "f3cfb454f4c209e6668c95216c4744b8fddb2356"
+                }
 	]
 }
diff --git a/ip-allocator/allocator.go b/ip-allocator/allocator.go
index e5a64cb..27e237a 100644
--- a/ip-allocator/allocator.go
+++ b/ip-allocator/allocator.go
@@ -2,37 +2,60 @@
 
 import (
 	"fmt"
+	"github.com/Sirupsen/logrus"
 	"github.com/gorilla/mux"
 	"github.com/kelseyhightower/envconfig"
-	"log"
 	"net/http"
 )
 
 type Config struct {
-	Port    int    `default:"4242"`
-	Listen  string `default:"0.0.0.0"`
-	Network string `default:"10.0.0.0/24"`
-	Skip    int    `default:"1"`
+	Port      int    `default:"4242"`
+	Listen    string `default:"0.0.0.0"`
+	Network   string `default:"10.0.0.0/24"`
+	Skip      int    `default:"1"`
+	LogLevel  string `default:"warning" envconfig:"LOG_LEVEL"`
+	LogFormat string `default:"text" envconfig:"LOG_FORMAT"`
 }
 
 type Context struct {
 	storage Storage
 }
 
+var log = logrus.New()
+
 func main() {
 	context := &Context{}
 
 	config := Config{}
 	err := envconfig.Process("ALLOCATE", &config)
 	if err != nil {
-		log.Fatalf("[error] Unable to parse configuration options : %s", err)
+		log.Fatalf("Unable to parse configuration options : %s", err)
 	}
 
-	log.Printf(`Configuration:
+	switch config.LogFormat {
+	case "json":
+		log.Formatter = &logrus.JSONFormatter{}
+	default:
+		log.Formatter = &logrus.TextFormatter{
+			FullTimestamp: true,
+			ForceColors:   true,
+		}
+	}
+
+	level, err := logrus.ParseLevel(config.LogLevel)
+	if err != nil {
+		level = logrus.WarnLevel
+	}
+	log.Level = level
+
+	log.Infof(`Configuration:
 	    Listen:       %s
 	    Port:         %d
 	    Network:      %s
-	    SKip:         %d`, config.Listen, config.Port, config.Network, config.Skip)
+	    SKip:         %d
+	    Log Level:    %s
+	    Log Format:   %s`, config.Listen, config.Port, config.Network, config.Skip,
+		config.LogLevel, config.LogFormat)
 
 	context.storage = &MemoryStorage{}
 	context.storage.Init(config.Network, config.Skip)