Update logging function

Change-Id: I2726d0a5b391abf7bf1ac55b9aab548ab232978f
diff --git a/bbsim.go b/bbsim.go
index 0374700..a25d4ec 100644
--- a/bbsim.go
+++ b/bbsim.go
@@ -26,7 +26,7 @@
 	"strings"
 	"sync"
 	"time"
-
+	"gerrit.opencord.org/voltha-bbsim/common"
 	"gerrit.opencord.org/voltha-bbsim/core"
 	"gerrit.opencord.org/voltha-bbsim/protos"
 )
@@ -67,7 +67,7 @@
 	// CLI Shows up
 	printBanner()
 	oltid, ip, port, npon, nonus, aaawait, dhcpwait, dhcpservip, delay, mode := getOptions()
-	log.Printf("ip:%s, baseport:%d, npon:%d, nonus:%d, mode:%d\n", ip, port, npon, nonus, mode)
+	logger.Debug("ip:%s, baseport:%d, npon:%d, nonus:%d, mode:%d\n", ip, port, npon, nonus, mode)
 
 	// Set up gRPC Server
 	var wg sync.WaitGroup
@@ -77,7 +77,7 @@
 	listener, gserver, err := core.CreateGrpcServer(oltid, npon, nonus, addressport)
 	server := core.Create(oltid, npon, nonus, aaawait, dhcpwait, dhcpservip, delay, gserver, mode, endchan)
 	if err != nil {
-		log.Println(err)
+		logger.Error("Failed to create gRPC server", err)
 	}
 	openolt.RegisterOpenoltServer(gserver, server)
 
@@ -99,5 +99,5 @@
 	}()
 	wg.Wait()
 	time.Sleep(5 * time.Second)
-	log.Println("Reach to the end line")
+	logger.Debug("Reach to the end line")
 }
diff --git a/common/logger.go b/common/logger.go
new file mode 100644
index 0000000..b2701e1
--- /dev/null
+++ b/common/logger.go
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package logger
+
+import (
+	"strings"
+	"log"
+)
+
+func Error(s string, opts ...interface{}){
+	trimmed := strings.TrimRight(s, "\n")
+	if len(opts) == 0{
+		log.Printf("[ERROR]:%s\n", trimmed)
+	}else{
+		fmt := "[ERROR]:" + trimmed + "\n"
+		log.Printf(fmt, opts...)
+	}
+}
+
+func Debug(s string, opts ...interface{}){
+	trimmed := strings.TrimRight(s, "\n")
+	if len(opts) == 0{
+		log.Printf("[DEBUG]:%s\n", trimmed)
+	}else{
+		fmt := "[DEBUG]:" + trimmed + "\n"
+		log.Printf(fmt, opts...)
+	}
+}
+
+func Info(s string, opts ...interface{}){
+	trimmed := strings.TrimRight(s, "\n")
+	if len(opts) == 0{
+		log.Printf("[INFO]:%s\n", trimmed)
+	}else{
+		fmt := "[INFO]:" + trimmed + "\n"
+		log.Printf(fmt, opts...)
+	}
+}
\ No newline at end of file
diff --git a/core/core_server.go b/core/core_server.go
index 76c219f..bb02c17 100644
--- a/core/core_server.go
+++ b/core/core_server.go
@@ -18,13 +18,12 @@
 
 import (
 	"errors"
-	"log"
 	"strconv"
 	"sync"
 	"time"
-
 	"gerrit.opencord.org/voltha-bbsim/device"
 	"gerrit.opencord.org/voltha-bbsim/protos"
+	"gerrit.opencord.org/voltha-bbsim/common"
 	"gerrit.opencord.org/voltha-bbsim/setup"
 	"github.com/google/gopacket"
 	"github.com/google/gopacket/layers"
@@ -77,7 +76,7 @@
 	s := new(Server)
 	s.Olt = device.CreateOlt(oltid, npon, 1)
 	nnni := s.Olt.NumNniIntf
-	log.Printf("OLT ID: %d was retrieved.\n", s.Olt.ID)
+	logger.Info("OLT ID: %d was retrieved.\n", s.Olt.ID)
 	s.Onumap = make(map[uint32][]*device.Onu)
 	s.AAAWait = aaawait
 	s.DhcpWait = dhcpwait
@@ -115,23 +114,23 @@
 	}
 	olt.OperState = "up"
 	*olt.InternalState = device.OLT_UP
-	log.Printf("OLT %s sent OltInd.\n", olt.Name)
+	logger.Info("OLT %s sent OltInd.\n", olt.Name)
 
 	// OLT sends Interface Indication to Adapter
 	if err := sendIntfInd(stream, olt); err != nil {
-		log.Printf("[ERROR] Fail to sendIntfInd: %v\n", err)
+		logger.Error("Fail to sendIntfInd: %v\n", err)
 		return err
 	}
-	log.Printf("OLT %s sent IntfInd.\n", olt.Name)
+	logger.Info("OLT %s sent IntfInd.\n", olt.Name)
 
 	// OLT sends Operation Indication to Adapter after activating each interface
 	//time.Sleep(IF_UP_TIME * time.Second)
 	*olt.InternalState = device.PONIF_UP
 	if err := sendOperInd(stream, olt); err != nil {
-		log.Printf("[ERROR] Fail to sendOperInd: %v\n", err)
+		logger.Error("Fail to sendOperInd: %v\n", err)
 		return err
 	}
-	log.Printf("OLT %s sent OperInd.\n", olt.Name)
+	logger.Info("OLT %s sent OperInd.\n", olt.Name)
 
 	// OLT sends ONU Discover Indication to Adapter after ONU discovery
 	for intfid, _ := range s.Onumap {
@@ -140,7 +139,7 @@
 
 	for intfid, _ := range s.Onumap {
 		sendOnuDiscInd(stream, s.Onumap[intfid])
-		log.Printf("OLT id:%d sent ONUDiscInd.\n", olt.ID)
+		logger.Info("OLT id:%d sent ONUDiscInd.\n", olt.ID)
 	}
 
 	// OLT Sends OnuInd after waiting all of those ONUs up
@@ -152,19 +151,19 @@
 
 	for intfid, _ := range s.Onumap {
 		sendOnuInd(stream, s.Onumap[intfid], s.Delay)
-		log.Printf("OLT id:%d sent ONUInd.\n", olt.ID)
+		logger.Info("OLT id:%d sent ONUInd.\n", olt.ID)
 	}
 
 	if s.Mode == DEFAULT {
 		//EnableIndication's stream should be kept even after activateOLT() is finished.
 		//Otherwise, OpenOLT adapter sends EnableIndication again.
 		<-s.Endchan
-		log.Println("core server thread receives close !")
+		logger.Debug("core server thread receives close ")
 	} else if s.Mode == AAA || s.Mode == BOTH {
 		s.TestFlag = true
 		var err error
 		s.Ioinfos, s.VethEnv, err = createIoinfos(oltid, s.VethEnv, s.Onumap)
-		log.Println("s.VethEnv", s.VethEnv)
+		logger.Debug("s.VethEnv:%v", s.VethEnv)
 		if err != nil {
 			return err
 		}
@@ -178,7 +177,7 @@
 		wg.Add(1)
 		go func() {
 			defer func() {
-				log.Println("runPacketInDaemon Done")
+				logger.Debug("runPacketInDaemon Done")
 				wg.Done()
 			}()
 
@@ -192,7 +191,7 @@
 		wg.Add(1)
 		go func() {
 			defer func() {
-				log.Println("exeAAATest Done")
+				logger.Debug("exeAAATest Done")
 				wg.Done()
 			}()
 
@@ -205,7 +204,7 @@
 			if s.Mode == BOTH {
 				go func() {
 					defer func() {
-						log.Println("exeDHCPTest Done")
+						logger.Debug("exeDHCPTest Done")
 					}()
 
 					err := s.exeDHCPTest()
@@ -220,7 +219,7 @@
 		cleanUpVeths(s.VethEnv) // Grace teardown
 		pnames := s.Processes
 		killProcesses(pnames)
-		log.Println("Grace shutdown down")
+		logger.Debug("Grace shutdown down")
 	}
 	return nil
 }
@@ -257,7 +256,7 @@
 }
 
 func (s *Server) runPacketInDaemon(stream openolt.Openolt_EnableIndicationServer) error {
-	log.Println("runPacketInDaemon Start")
+	logger.Debug("runPacketInDaemon Start")
 	unichannel := make(chan Packet, 2048)
 	flag := false
 
@@ -266,7 +265,7 @@
 			onuid := onu.OnuID
 			ioinfo, err := s.identifyUniIoinfo("inside", intfid, onuid)
 			if err != nil {
-				log.Printf("[ERROR] Fail to identifyUniIoinfo (onuid: %d): %v\n", onuid, err)
+				logger.Error("Fail to identifyUniIoinfo (onuid: %d): %v\n", onuid, err)
 				return err
 			}
 			uhandler := ioinfo.handler
@@ -288,9 +287,9 @@
 	for {
 		select {
 		case unipkt := <-unichannel:
-			log.Println("Received packet in grpc Server from UNI.")
+			logger.Debug("Received packet in grpc Server from UNI.")
 			if unipkt.Info == nil || unipkt.Info.iotype != "uni" {
-				log.Println("[WARNING] This packet does not come from UNI !")
+				logger.Info("WARNING: This packet does not come from UNI ")
 				continue
 			}
 
@@ -303,11 +302,11 @@
 			ethtype := le.EthernetType
 
 			if ethtype == 0x888e {
-				log.Printf("Received upstream packet is EAPOL.")
+				logger.Debug("Received upstream packet is EAPOL.")
 				//log.Println(unipkt.Pkt.Dump())
 				//log.Println(pkt.Dump())
 			} else if layerDHCP := pkt.Layer(layers.LayerTypeDHCPv4); layerDHCP != nil {
-				log.Printf("Received upstream packet is DHCP.")
+				logger.Debug("Received upstream packet is DHCP.")
 
 				//C-TAG
 				onu, _ := s.getOnuByID(onuid)
@@ -315,47 +314,47 @@
 				if ctag, ok := s.CtagMap[sn]; ok == true {
 					tagpkt, err := PushVLAN(pkt, uint16(ctag))
 					if err != nil {
-						log.Println("Error happend in C-tag tagging")
+						logger.Error("Fail to tag C-tag")
 					} else {
 						pkt = tagpkt
 					}
 				} else {
-					log.Printf("Could not find the onuid %d (SN: %s) in CtagMap %v!\n", onuid, sn, s.CtagMap)
+					logger.Error("Could not find the onuid %d (SN: %s) in CtagMap %v!\n", onuid, sn, s.CtagMap)
 				}
 			} else {
 				continue
 			}
 
-			log.Printf("sendPktInd intfid:%d (onuid: %d) gemid:%d\n", intfid, onuid, gemid)
+			logger.Debug("sendPktInd intfid:%d (onuid: %d) gemid:%d\n", intfid, onuid, gemid)
 			data = &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{IntfType: "pon", IntfId: intfid, GemportId: gemid, Pkt: pkt.Data()}}
 			if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-				log.Printf("[ERROR] Failed to send PktInd indication. %v\n", err)
+				logger.Error("Fail to send PktInd indication. %v\n", err)
 				return err
 			}
 
 		case nnipkt := <-nnichannel:
 			if nnipkt.Info == nil || nnipkt.Info.iotype != "nni" {
-				log.Println("[WARNING] This packet does not come from NNI !")
+				logger.Info("WARNING: This packet does not come from NNI ")
 				continue
 			}
 
-			log.Println("Received packet in grpc Server from NNI.")
+			logger.Debug("Received packet in grpc Server from NNI.")
 			intfid := nnipkt.Info.intfid
 			pkt := nnipkt.Pkt
-			log.Printf("sendPktInd intfid:%d\n", intfid)
+			logger.Info("sendPktInd intfid:%d\n", intfid)
 			data = &openolt.Indication_PktInd{PktInd: &openolt.PacketIndication{IntfType: "nni", IntfId: intfid, Pkt: pkt.Data()}}
 			if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-				log.Printf("[ERROR] Failed to send PktInd indication. %v\n", err)
+				logger.Error("Fail to send PktInd indication. %v\n", err)
 				return err
 			}
 
 		case <-s.Endchan:
 			if flag == false {
-				log.Println("PacketInDaemon thread receives close !")
+				logger.Debug("PacketInDaemon thread receives close ")
 				close(unichannel)
-				log.Println("Closed unichannel !")
+				logger.Debug("Closed unichannel ")
 				close(nnichannel)
-				log.Println("Closed nnichannel !")
+				logger.Debug("Closed nnichannel ")
 				flag = true
 				return nil
 			}
@@ -365,7 +364,7 @@
 }
 
 func (s *Server) exeAAATest() error {
-	log.Println("exeAAATest starts to sleep....")
+	logger.Info("exeAAATest stands by....")
 	infos, err := s.getUniIoinfos("outside")
 	if err != nil {
 		return err
@@ -379,16 +378,16 @@
 	for {
 		select {
 		case <-s.Endchan:
-			log.Println("exeAAATest thread receives close !")
+			logger.Debug("exeAAATest thread receives close ")
 			return nil
 		case <-time.After(time.Second * time.Duration(s.AAAWait)):
-			log.Println("exeAAATest Start")
 			err = setup.ActivateWPASups(univeths, s.Delay)
 			if err != nil {
 				return err
 			}
+			logger.Info("WPA Supplicants are successfully activated ")
 			s.Processes = append(s.Processes, "wpa_supplicant")
-			log.Println("s.Processes:", s.Processes)
+			logger.Debug("Running Process:%v", s.Processes)
 			return nil
 		}
 	}
@@ -396,7 +395,7 @@
 }
 
 func (s *Server) exeDHCPTest() error {
-	log.Println("exeDHCPTest starts to sleep....")
+	logger.Info("exeDHCPTest stands by....")
 	info, err := s.identifyNniIoinfo("outside")
 
 	if err != nil {
@@ -408,6 +407,7 @@
 		return err
 	}
 	s.Processes = append(s.Processes, "dhcpd")
+	logger.Debug("Running Process:%v", s.Processes)
 
 	infos, err := s.getUniIoinfos("outside")
 	if err != nil {
@@ -422,16 +422,16 @@
 	for {
 		select {
 		case <-s.Endchan:
-			log.Println("exeDHCPTest thread receives close !")
+			logger.Debug("exeDHCPTest thread receives close ")
 			return nil
 		case <-time.After(time.Second * time.Duration(s.DhcpWait)):
-			log.Println("exeDHCPTest Start")
 			err = setup.ActivateDHCPClients(univeths, s.Delay)
 			if err != nil {
 				return err
 			}
+			logger.Info("DHCP clients are successfully activated ")
 			s.Processes = append(s.Processes, "dhclient")
-			log.Println("s.Processes:", s.Processes)
+			logger.Debug("Running Process:%v", s.Processes)
 			return nil
 		}
 	}
@@ -444,10 +444,10 @@
 		pkt, _ := layerEth.(*layers.Ethernet)
 		ethtype := pkt.EthernetType
 		if ethtype == 0x888e {
-			log.Printf("Received downstream packet is EAPOL.")
+			logger.Debug("Received downstream packet is EAPOL.")
 			//log.Println(rawpkt.Dump())
 		} else if layerDHCP := rawpkt.Layer(layers.LayerTypeDHCPv4); layerDHCP != nil {
-			log.Printf("Received downstream packet is DHCP.")
+			logger.Debug("Received downstream packet is DHCP.")
 			//log.Println(rawpkt.Dump())
 			rawpkt, _, _ = PopVLAN(rawpkt)
 			rawpkt, _, _ = PopVLAN(rawpkt)
@@ -462,7 +462,7 @@
 		SendUni(handle, rawpkt)
 		return nil
 	}
-	log.Printf("[WARNING] Received packet is not supported")
+	logger.Info("WARNING: Received packet is not supported")
 	return nil
 }
 
@@ -470,7 +470,7 @@
 	poppkt, _, err := PopVLAN(rawpkt)
 	poppkt, _, err = PopVLAN(poppkt)
 	if err != nil {
-		log.Println(err)
+		logger.Error("%s", err)
 		return err
 	}
 	ioinfo, err := s.identifyNniIoinfo("inside")
@@ -507,8 +507,8 @@
 			}
 		}
 	}
-	err := errors.New("No mathced SN is found !")
-	log.Println(err)
+	err := errors.New("No mathced SN is found ")
+	logger.Error("%s", err)
 	return nil, err
 }
 
@@ -520,8 +520,8 @@
 			}
 		}
 	}
-	err := errors.New("No matched OnuID is found !")
-	log.Println(err)
+	err := errors.New("No matched OnuID is found ")
+	logger.Error("%s", err)
 	return nil, err
 }
 
@@ -539,7 +539,7 @@
 
 func cleanUpVeths(vethenv []string) error {
 	if len(vethenv) > 0 {
-		log.Println("cleanUp veths !")
+		logger.Debug("cleanUpVeths called ")
 		setup.TearVethDown(vethenv)
 	}
 	return nil
@@ -553,7 +553,7 @@
 }
 
 func setupVethHandler(inveth string, outveth string, vethenv []string) (*pcap.Handle, []string, error) {
-	log.Printf("setupVethHandler: %s and %s\n", inveth, outveth)
+	logger.Debug("SetupVethHandler(%s, %s) called ", inveth, outveth)
 	err1 := setup.CreateVethPairs(inveth, outveth)
 	vethenv = append(vethenv, inveth)
 	if err1 != nil {
@@ -580,7 +580,7 @@
 	if err != nil {
 		return nil, err
 	}
-	log.Printf("Server handle created for %s\n", vethname)
+	logger.Debug("Server handle is created for %s\n", vethname)
 	return handle, nil
 }
 
diff --git a/core/grpc_service.go b/core/grpc_service.go
index 329292d..dce608b 100644
--- a/core/grpc_service.go
+++ b/core/grpc_service.go
@@ -19,6 +19,7 @@
 import (
 	"gerrit.opencord.org/voltha-bbsim/device"
 	"gerrit.opencord.org/voltha-bbsim/protos"
+	"gerrit.opencord.org/voltha-bbsim/common"
 	"github.com/google/gopacket"
 	"github.com/google/gopacket/layers"
 	"golang.org/x/net/context"
@@ -30,28 +31,28 @@
 
 // gRPC Service
 func (s *Server) DisableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
-	log.Printf("OLT receives DisableOLT()\n")
+	logger.Info("OLT receives DisableOLT()\n")
 	if s.EnableServer != nil {
 		if err := sendOltIndDown(*s.EnableServer); err != nil {
 			return new(openolt.Empty), err
 		}
-		log.Println("Successfuly sent OLT DOWN indication !")
+		logger.Info("Successfuly sent OLT DOWN indication")
 	}
 	return new(openolt.Empty), nil
 }
 
 func (s *Server) ReenableOlt(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
-	log.Printf("OLT receives Reenable()\n")
+	logger.Info("OLT receives Reenable()\n")
 	return new(openolt.Empty), nil
 }
 
 func (s *Server) CollectStatistics(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
-	log.Printf("OLT receives CollectStatistics()\n")
+	logger.Info("OLT receives CollectStatistics()\n")
 	return new(openolt.Empty), nil
 }
 
 func (s *Server) GetDeviceInfo(c context.Context, empty *openolt.Empty) (*openolt.DeviceInfo, error) {
-	log.Printf("OLT receives GetDeviceInfo()\n")
+	logger.Info("OLT receives GetDeviceInfo()\n")
 	devinfo := new(openolt.DeviceInfo)
 	devinfo.Vendor = "CORD"
 	devinfo.OnuIdStart = 0
@@ -61,7 +62,7 @@
 }
 
 func (s *Server) ActivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
-	log.Printf("OLT receives ActivateONU()\n")
+	logger.Info("OLT receives ActivateONU()\n")
 	result := device.ValidateONU(*onu, s.Onumap)
 	if result == true {
 		matched, error := s.getOnuBySN(onu.SerialNumber)
@@ -71,29 +72,29 @@
 		onuid := onu.OnuId
 		matched.OnuID = onuid
 		matched.UpdateIntStatus(device.ONU_ACTIVATED)
-		log.Printf("ONU IntfID: %d OnuID: %d activated succesufully.\n", onu.IntfId, onu.OnuId)
+		logger.Info("ONU IntfID: %d OnuID: %d activated succesufully.\n", onu.IntfId, onu.OnuId)
 	}
 	return new(openolt.Empty), nil
 }
 
 func (s *Server) DeactivateOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
-	log.Printf("OLT receives DeactivateONU()\n")
+	logger.Info("OLT receives DeactivateONU()\n")
 	return new(openolt.Empty), nil
 }
 
 func (s *Server) DeleteOnu(c context.Context, onu *openolt.Onu) (*openolt.Empty, error) {
-	log.Printf("OLT receives DeleteONU()\n")
+	logger.Info("OLT receives DeleteONU()\n")
 	return new(openolt.Empty), nil
 }
 
 func (s *Server) OmciMsgOut(c context.Context, msg *openolt.OmciMsg) (*openolt.Empty, error) {
-	log.Printf("OLT %d receives OmciMsgOut to IF %v (ONU-ID: %v) pkt:%x.\n", s.Olt.ID, msg.IntfId, msg.OnuId, msg.Pkt)
+	logger.Info("OLT %d receives OmciMsgOut to IF %v (ONU-ID: %v) pkt:%x.\n", s.Olt.ID, msg.IntfId, msg.OnuId, msg.Pkt)
 	//s.olt.Queue = append(s.olt.Queue, *msg)
 	return new(openolt.Empty), nil
 }
 
 func (s *Server) OnuPacketOut(c context.Context, packet *openolt.OnuPacket) (*openolt.Empty, error) {
-	log.Printf("OLT %d receives OnuPacketOut () to IF-ID:%d ONU-ID %d.\n", s.Olt.ID, packet.IntfId, packet.OnuId)
+	logger.Info("OLT %d receives OnuPacketOut () to IF-ID:%d ONU-ID %d.\n", s.Olt.ID, packet.IntfId, packet.OnuId)
 	onuid := packet.OnuId
 	intfid := packet.IntfId
 	rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
@@ -104,7 +105,7 @@
 }
 
 func (s *Server) UplinkPacketOut(c context.Context, packet *openolt.UplinkPacket) (*openolt.Empty, error) {
-	log.Printf("OLT %d receives UplinkPacketOut().\n", s.Olt.ID)
+	logger.Info("OLT %d receives UplinkPacketOut().\n", s.Olt.ID)
 	rawpkt := gopacket.NewPacket(packet.Pkt, layers.LayerTypeEthernet, gopacket.Default)
 	if err := s.uplinkPacketOut(rawpkt); err != nil {
 		return new(openolt.Empty), err
@@ -113,8 +114,8 @@
 }
 
 func (s *Server) FlowAdd(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
-	log.Printf("OLT %d receives FlowAdd().\n", s.Olt.ID)
-	log.Printf("Flow's ONU-ID: %d, CTAG: %d\n", flow.OnuId, flow.Action.IVid)
+	logger.Info("OLT %d receives FlowAdd().\n", s.Olt.ID)
+	logger.Debug("Flow's ONU-ID: %d, CTAG: %d\n", flow.OnuId, flow.Action.IVid)
 	//onuid := uint32(flow.OnuId)
 	//ctag := flow.Action.IVid
 	//s.CtagMap[onuid] = ctag
@@ -122,39 +123,39 @@
 }
 
 func (s *Server) FlowRemove(c context.Context, flow *openolt.Flow) (*openolt.Empty, error) {
-	log.Printf("OLT %d receives FlowRemove().\n", s.Olt.ID)
+	logger.Info("OLT %d receives FlowRemove().\n", s.Olt.ID)
 	return new(openolt.Empty), nil
 }
 
 func (s *Server) HeartbeatCheck(c context.Context, empty *openolt.Empty) (*openolt.Heartbeat, error) {
-	log.Printf("OLT %d receives HeartbeatCheck().\n", s.Olt.ID)
+	logger.Info("OLT %d receives HeartbeatCheck().\n", s.Olt.ID)
 	signature := new(openolt.Heartbeat)
 	signature.HeartbeatSignature = s.Olt.HeartbeatSignature
 	return signature, nil
 }
 
 func (s *Server) EnablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
-	log.Printf("OLT %d receives EnablePonIf().\n", s.Olt.ID)
+	logger.Info("OLT %d receives EnablePonIf().\n", s.Olt.ID)
 	return new(openolt.Empty), nil
 }
 
 func (s *Server) DisablePonIf(c context.Context, intf *openolt.Interface) (*openolt.Empty, error) {
-	log.Printf("OLT %d receives DisablePonIf().\n", s.Olt.ID)
+	logger.Info("OLT %d receives DisablePonIf().\n", s.Olt.ID)
 	return new(openolt.Empty), nil
 }
 
 func (s *Server) Reboot(c context.Context, empty *openolt.Empty) (*openolt.Empty, error) {
-	log.Printf("OLT %d receives Reboot ().\n", s.Olt.ID)
+	logger.Info("OLT %d receives Reboot ().\n", s.Olt.ID)
 	// Initialize OLT & Env
 	if s.TestFlag == true{
-		log.Println("Initialized by Reboot")
+		logger.Debug("Initialized by Reboot")
 		cleanUpVeths(s.VethEnv)
 		close(s.Endchan)
 		processes := s.Processes
-		log.Println("processes:", processes)
+		logger.Debug("Runnig Processes:", processes)
 		killProcesses(processes)
-		exec.Command("rm", "/var/run/dhcpd.pid").Run()
-		exec.Command("touch", "/var/run/dhcpd.pid").Run()
+		exec.Command("rm", "/var/run/dhcpd.pid").Run()	//This is for DHCP server activation
+		exec.Command("touch", "/var/run/dhcpd.pid").Run()	//This is for DHCP server activation
 		s.Initialize()
 	}
 	olt := s.Olt
@@ -172,17 +173,17 @@
 		s.gRPCserver.Stop()
 	}()
 	s.EnableServer = &stream
-	log.Printf("OLT receives EnableInd.\n")
+	logger.Info("OLT receives EnableInd.\n")
 	if err := s.activateOLT(stream); err != nil {
-		log.Printf("Failed to activate OLT: %v\n", err)
+		logger.Error("Failed to activate OLT: %v\n", err)
 		return err
 	}
-	log.Println("Core server down.")
+	logger.Debug("Core server down.")
 	return nil
 }
 
 func CreateGrpcServer(oltid uint32, npon uint32, nonus uint32, addrport string) (l net.Listener, g *grpc.Server, e error) {
-	log.Printf("Listening %s ...", addrport)
+	logger.Info("Listening %s ...", addrport)
 	g = grpc.NewServer()
 	l, e = net.Listen("tcp", addrport)
 	return
diff --git a/core/io_info.go b/core/io_info.go
index c913192..21e1b9a 100644
--- a/core/io_info.go
+++ b/core/io_info.go
@@ -18,8 +18,8 @@
 
 import (
 	"github.com/google/gopacket/pcap"
+	"gerrit.opencord.org/voltha-bbsim/common"
 	"errors"
-	"log"
 )
 
 type Ioinfo struct {
@@ -37,8 +37,8 @@
 			return ioinfo, nil
 		}
 	}
-	err := errors.New("No matched Ioinfo is found !")
-	log.Println(err)
+	err := errors.New("No matched Ioinfo is found")
+	logger.Error("%s", err)
 	return nil, err
 }
 
@@ -48,8 +48,8 @@
 			return ioinfo, nil
 		}
 	}
-	err := errors.New("No matched Ioinfo is found !")
-	log.Println(err)
+	err := errors.New("No matched Ioinfo is found")
+	logger.Error("%s", err)
 	return nil, err
 }
 
@@ -61,8 +61,8 @@
 		}
 	}
 	if len(ioinfos) == 0 {
-		err := errors.New("No matched Ioinfo is found !")
-		log.Println(err)
+		err := errors.New("No matched Ioinfo is found")
+		logger.Error("%s", err)
 		return nil, err
 	}
 	return ioinfos, nil
diff --git a/core/io_worker.go b/core/io_worker.go
index 3b59b49..1fa97bd 100644
--- a/core/io_worker.go
+++ b/core/io_worker.go
@@ -20,16 +20,16 @@
 	"github.com/google/gopacket"
 	"github.com/google/gopacket/layers"
 	"github.com/google/gopacket/pcap"
+	"gerrit.opencord.org/voltha-bbsim/common"
 	"errors"
-	"log"
 	"net"
 )
 
 func RecvWorker(io *Ioinfo, handler *pcap.Handle, r chan Packet) {
-	log.Printf("recvWorker runs. handler: %v", *handler)
+	logger.Debug("recvWorker runs. handler: %v", *handler)
 	packetSource := gopacket.NewPacketSource(handler, handler.LinkType())
 	for packet := range packetSource.Packets() {
-		log.Printf("recv packet from IF: %v \n", *handler)
+		logger.Debug("recv packet from IF: %v \n", *handler)
 		//log.Println(packet.Dump())
 		pkt := Packet{}
 		pkt.Info = io
@@ -41,18 +41,18 @@
 func SendUni(handle *pcap.Handle, packet gopacket.Packet) {
 	err := handle.WritePacketData(packet.Data())
 	if err != nil {
-		log.Printf("Error in send packet to UNI-IF: %v e:%s\n", *handle, err)
+		logger.Error("Error in send packet to UNI-IF: %v e:%s\n", *handle, err)
 	}
-	log.Printf("Successfully send packet to UNI-IF: %v \n", *handle)
+	logger.Debug("Successfully send packet to UNI-IF: %v \n", *handle)
 	//log.Println(packet.Dump())
 }
 
 func SendNni(handle *pcap.Handle, packet gopacket.Packet) {
 	err := handle.WritePacketData(packet.Data())
 	if err != nil{
-		log.Printf("Error in send packet to NNI e:%s\n", err)
+		logger.Error("Error in send packet to NNI e:%s\n", err)
 	}
-	log.Printf("send packet to NNI-IF: %v \n", *handle)
+	logger.Debug("send packet to NNI-IF: %v \n", *handle)
 	//log.Println(packet.Dump())
 }
 
@@ -75,7 +75,7 @@
 				gopacket.Default,
 			)
 			vid := uint16(4095 & layer.VLANIdentifier)
-			log.Printf("Pop the 802.1Q header (VID: %d)", vid)
+			logger.Debug("Pop the 802.1Q header (VID: %d)", vid)
 			return retpkt, vid, nil
 		}
 	}
@@ -110,7 +110,7 @@
 			layers.LayerTypeEthernet,
 			gopacket.Default,
 		)
-		log.Printf("Push the 802.1Q header (VID: %d)", vid)
+		logger.Debug("Push the 802.1Q header (VID: %d)", vid)
 		return ret, nil
 	}
 	return nil, errors.New("failed to push vlan")
diff --git a/core/openolt_service.go b/core/openolt_service.go
index a0d00bf..ef92704 100644
--- a/core/openolt_service.go
+++ b/core/openolt_service.go
@@ -17,17 +17,16 @@
 package core
 
 import (
-	"log"
 	"time"
-
-	"gerrit.opencord.org/voltha-bbsim/device"
 	"gerrit.opencord.org/voltha-bbsim/protos"
+	"gerrit.opencord.org/voltha-bbsim/device"
+	"gerrit.opencord.org/voltha-bbsim/common"
 )
 
 func sendOltIndUp(stream openolt.Openolt_EnableIndicationServer, olt *device.Olt) error {
 	data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "up"}}
 	if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-		log.Printf("Failed to send OLT UP indication: %v\n", err)
+		logger.Error("Failed to send OLT UP indication: %v\n", err)
 		return err
 	}
 	return nil
@@ -36,7 +35,7 @@
 func sendOltIndDown(stream openolt.Openolt_EnableIndicationServer) error {
 	data := &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "down"}}
 	if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-		log.Printf("Failed to send OLT DOWN indication: %v\n", err)
+		logger.Error("Failed to send OLT DOWN indication: %v\n", err)
 		return err
 	}
 	return nil
@@ -48,10 +47,10 @@
 		if intf.Type == "pon" { // There is no need to send IntfInd for NNI
 			data := &openolt.Indication_IntfInd{&openolt.IntfIndication{IntfId: intf.IntfID, OperState: intf.OperState}}
 			if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-				log.Printf("Failed to send Intf [id: %d] indication : %v\n", i, err)
+				logger.Error("Failed to send Intf [id: %d] indication : %v\n", i, err)
 				return err
 			}
-			log.Printf("SendIntfInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type)
+			logger.Info("SendIntfInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type)
 		}
 	}
 	return nil
@@ -62,10 +61,10 @@
 		intf := olt.Intfs[i]
 		data := &openolt.Indication_IntfOperInd{&openolt.IntfOperIndication{Type: intf.Type, IntfId: intf.IntfID, OperState: intf.OperState}}
 		if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-			log.Printf("Failed to send IntfOper [id: %d] indication : %v\n", i, err)
+			logger.Error("Failed to send IntfOper [id: %d] indication : %v\n", i, err)
 			return err
 		}
-		log.Printf("SendOperInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type)
+		logger.Info("SendOperInd olt:%d intf:%d (%s)\n", olt.ID, intf.IntfID, intf.Type)
 	}
 	return nil
 }
@@ -73,11 +72,11 @@
 func sendOnuDiscInd(stream openolt.Openolt_EnableIndicationServer, onus []*device.Onu) error {
 	for i, onu := range onus {
 		data := &openolt.Indication_OnuDiscInd{&openolt.OnuDiscIndication{IntfId: onu.IntfID, SerialNumber: onu.SerialNumber}}
-		log.Printf("sendONUDiscInd Onuid: %d\n", i)
 		if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-			log.Printf("Failed to send ONUDiscInd [id: %d]: %v\n", i, err)
+			logger.Error("Failed to send ONUDiscInd [id: %d]: %v\n", i, err)
 			return err
 		}
+		logger.Info("sendONUDiscInd Onuid: %d\n", i)
 	}
 	return nil
 }
@@ -86,11 +85,11 @@
 	for i, onu := range onus {
 		time.Sleep(time.Duration(delay) * time.Second)
 		data := &openolt.Indication_OnuInd{&openolt.OnuIndication{IntfId: onu.IntfID, OnuId: onu.OnuID, OperState: "up", AdminState: "up", SerialNumber: onu.SerialNumber}}
-		log.Printf("sendONUInd Onuid: %d\n", i)
 		if err := stream.Send(&openolt.Indication{Data: data}); err != nil {
-			log.Printf("Failed to send ONUInd [id: %d]: %v\n", i, err)
+			logger.Error("Failed to send ONUInd [id: %d]: %v\n", i, err)
 			return err
 		}
+		logger.Info("sendONUInd Onuid: %d\n", i)
 	}
 	return nil
 }
diff --git a/device/device_onu.go b/device/device_onu.go
index c0b9ff9..92f96b5 100644
--- a/device/device_onu.go
+++ b/device/device_onu.go
@@ -17,10 +17,10 @@
 package device
 
 import (
- 	"gerrit.opencord.org/voltha-bbsim/protos"
-	"log"
 	"reflect"
 	"sync"
+	"gerrit.opencord.org/voltha-bbsim/protos"
+	"gerrit.opencord.org/voltha-bbsim/common"
 )
 
 type onuState int
@@ -84,7 +84,7 @@
 func UpdateOnusOpStatus(ponif uint32, onus []*Onu, opstatus string) {
 	for i, onu := range onus {
 		onu.OperState = "up"
-		log.Printf("(PONIF:%d) ONU [%d] discovered.\n", ponif, i)
+		logger.Info("(PONIF:%d) ONU [%d] discovered.\n", ponif, i)
 	}
 }
 
diff --git a/setup/setup_env.go b/setup/setup_env.go
index 82dd6cf..ffbc9a0 100644
--- a/setup/setup_env.go
+++ b/setup/setup_env.go
@@ -17,9 +17,10 @@
 package setup
 
 import (
-	"log"
 	"os/exec"
 	"time"
+	"log"
+	"gerrit.opencord.org/voltha-bbsim/common"
 )
 
 const (
@@ -32,7 +33,7 @@
 func ActivateWPASups(vethnames []string, delay int) error {
 	for _, vethname := range vethnames {
 		time.Sleep(time.Duration(delay) * time.Second)
-		log.Printf("ActivateWPASups for interface %v\n", vethname)
+		logger.Debug("ActivateWPASups for interface %v\n", vethname)
 		if err := activateWPASupplicant(vethname); err != nil {
 			return err
 		}
@@ -43,7 +44,7 @@
 func ActivateDHCPClients(vethnames []string, delay int) error {
 	for _, vethname := range vethnames {
 		time.Sleep(time.Duration(delay) * time.Second)
-		log.Printf("activateDHCPClient for interface %v\n", vethname)
+		logger.Debug("activateDHCPClient for interface %v\n", vethname)
 		if err := activateDHCPClient(vethname); err != nil {
 			return err
 		}
@@ -54,10 +55,10 @@
 func KillProcess(name string) error {
 	err := exec.Command("pkill", name).Run()
 	if err != nil {
-		log.Printf("[ERROR] Fail to pkill %s: %v\n", name, err)
+		logger.Error("Fail to pkill %s: %v\n", name, err)
 		return err
 	}
-	log.Printf("Successfully killed %s\n", name)
+	logger.Info("Successfully killed %s\n", name)
 	return nil
 }
 
@@ -70,34 +71,34 @@
 func CreateVethPairs(name1 string, name2 string) (err error) {
 	err = exec.Command("ip", "link", "add", name1, "type", "veth", "peer", "name", name2).Run()
 	if err != nil {
-		log.Printf("[ERROR] Fail to createVeth() for %s and %s veth creation error: %s\n", name1, name2, err.Error())
+		logger.Error("Fail to createVeth() for %s and %s veth creation error: %s\n", name1, name2, err.Error())
 		return
 	}
-	log.Printf("%s & %s was created.", name1, name2)
+	logger.Info("%s & %s was created.", name1, name2)
 	err = exec.Command("ip", "link", "set", name1, "up").Run()
 	if err != nil {
-		log.Println("[ERROR] Fail to createVeth() veth1 up", err)
+		logger.Error("Fail to createVeth() veth1 up", err)
 		return
 	}
 	err = exec.Command("ip", "link", "set", name2, "up").Run()
 	if err != nil {
-		log.Println("[ERROR] Fail to createVeth() veth2 up", err)
+		logger.Error("Fail to createVeth() veth2 up", err)
 		return
 	}
-	log.Printf("%s & %s was up.", name1, name2)
+	logger.Info("%s & %s was up.", name1, name2)
 	return
 }
 
 func RemoveVeth(name string) {
 	err := exec.Command("ip", "link", "del", name).Run()
 	if err != nil {
-		log.Println("[ERROR] Fail to removeVeth()", err)
+		logger.Error("Fail to removeVeth()", err)
 	}
-	log.Printf("%s was removed.", name)
+	logger.Info("%s was removed.", name)
 }
 
 func RemoveVeths(names []string) {
-	log.Printf("RemoveVeths() :%s\n", names)
+	logger.Info("RemoveVeths() :%s\n", names)
 	for _, name := range names {
 		RemoveVeth(name)
 	}
@@ -108,19 +109,19 @@
 	conf := "/etc/wpa_supplicant/wpa_supplicant.conf"
 	err = exec.Command(cmd, "-D", "wired", "-i", vethname, "-c", conf).Start()
 	if err != nil {
-		log.Printf("[ERROR] Fail to activateWPASupplicant() for: %s %v\n", vethname, err)
+		logger.Error("Fail to activateWPASupplicant() for :%s %v\n", vethname, err)
 		return
 	}
-	log.Printf("activateWPASupplicant() for: %s\n", vethname)
+	logger.Info("activateWPASupplicant() for :%s\n", vethname)
 	return
 }
 
 func activateDHCPClient(vethname string) (err error) {
-	log.Printf("activateDHCPClient() start for: %s\n", vethname)
+	logger.Debug("activateDHCPClient() start for: %s\n", vethname)
 	cmd := exec.Command("/usr/local/bin/dhclient", vethname)
 	// if err := cmd.Run(); err != nil {
 	if err := cmd.Start(); err != nil {
-		log.Printf("[ERROR] Failed to activateDHCPClient() for: %s", vethname)
+		logger.Error("Fail to activateDHCPClient() for: %s", vethname)
 		log.Panic(err)
 	}
 
@@ -130,28 +131,28 @@
 	// 	log.Printf("[ERROR] Failed to kill activateDHCPClient() for: %s", vethname, err)
 	// }
 
-	log.Printf("activateDHCPClient() done for: %s\n", vethname)
+	logger.Debug("activateDHCPClient() done for: %s\n", vethname)
 	return
 }
 
 func ActivateDHCPServer(veth string, serverip string) error {
 	err := exec.Command("ip", "addr", "add", serverip, "dev", veth).Run()
 	if err != nil {
-		log.Printf("[ERROR] Fail to add ip to %s address: %s\n", veth, err)
+		logger.Error("Fail to add ip to %s address: %s\n", veth, err)
 		return err
 	}
 	err = exec.Command("ip", "link", "set", veth, "up").Run()
 	if err != nil {
-		log.Printf("[ERROR] Fail to set %s up: %s\n", veth, err)
+		logger.Error("Fail to set %s up: %s\n", veth, err)
 		return err
 	}
 	cmd := "/usr/local/bin/dhcpd"
 	conf := "/etc/dhcp/dhcpd.conf"
 	err = exec.Command(cmd, "-cf", conf, veth).Run()
 	if err != nil {
-		log.Printf("[ERROR] Fail to activateDHCP Server (): %s\n", err)
+		logger.Error("Fail to activateDHCP Server (): %s\n", err)
 		return err
 	}
-	log.Printf("Activate DHCP Server()\n")
+	logger.Info("DHCP Server is successfully activated !\n")
 	return err
 }