Improving logs

Change-Id: I75021b47851b3af946dc3a9b41a516934b4b2e3a
diff --git a/omci_handlers.go b/omci_handlers.go
index 1ebaaea..ec7f712 100644
--- a/omci_handlers.go
+++ b/omci_handlers.go
@@ -20,7 +20,7 @@
 	"encoding/binary"
 	"errors"
 	"fmt"
-	"log"
+	log "github.com/sirupsen/logrus"
 )
 
 type OmciMsgHandler func(class OmciClass, content OmciContent, key OnuKey) ([]byte, error)
@@ -42,9 +42,15 @@
 func mibReset(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
 	var pkt []byte
 
-	log.Printf("%v - Omci MibReset", key)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Omci MibReset")
 	if state, ok := OnuOmciStateMap[key]; ok {
-		log.Printf("%v - Reseting OnuOmciState", key)
+		log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Reseting OnuOmciState")
 		state.ResetOnuOmciState()
 	}
 
@@ -61,7 +67,10 @@
 func mibUpload(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
 	var pkt []byte
 
-	log.Printf("%v - Omci MibUpload", key)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Omci MibUpload")
 
 	pkt = []byte{
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
@@ -84,7 +93,11 @@
 
 	// commandNumber is the "Command number" attribute received in "MIB Upload Next" OMCI message
 	commandNumber := (uint16(content[1])) | (uint16(content[0])<<8)
-	log.Printf("%v - Omci MibUploadNext %d", key, commandNumber)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+		"CommandNumber": commandNumber,
+	}).Tracef("Omci MibUploadNext")
 
 	switch commandNumber {
 	case 0:
@@ -235,7 +248,7 @@
 	     218, 222, 226, 230, 234, 238, 242, 246,
 	     250, 254, 258, 262, 266, 270, 274, 278:
 		// Prior-Q with mask downstream
-		log.Println("Mib-upload for prior-q with mask")
+		log.Tracef("Mib-upload for prior-q with mask")
 		// For downstream PQ, pkt[10] is 0x00
 		// So the instanceId will be like 0x0001, 0x0002,... etc
 		pkt = []byte{
@@ -278,7 +291,7 @@
 
 		// Only for verification. To be removed
 		if state.tcontPointer > state.tcontInstance {
-			log.Println("Error: Invalid TcontPointer")
+			log.Tracef("Error: Invalid TcontPointer")
 			break
 		}
 
@@ -363,7 +376,7 @@
 
 	default:
 		state.extraMibUploadCtr++
-		errstr := fmt.Sprintf("%v - Invalid MibUpload request: %d, extras: %d", key, state.mibUploadCtr, state.extraMibUploadCtr)
+		errstr := fmt.Sprintf("%v - Invalid MibUpload request: %d, extras: %d", key, state.mibUploadCtr, state)
 		return nil, errors.New(errstr)
 	}
 
@@ -382,7 +395,10 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci Set", key)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Omci Set")
 
 	return pkt, nil
 }
@@ -392,11 +408,17 @@
 
 	if class == GEMPortNetworkCTP {
 		if onuOmciState, ok := OnuOmciStateMap[key]; !ok {
-			log.Printf("%v - ONU Key Error", key)
+			log.WithFields(log.Fields{
+				"IntfId": key.IntfId,
+				"OnuId": key.OnuId,
+			}).Tracef("ONU Key Error")
 			return nil, errors.New("ONU Key Error")
 		} else {
 			onuOmciState.gemPortId = binary.BigEndian.Uint16(content[:2])
-			log.Printf("%v - Gem Port Id %d", key, onuOmciState.gemPortId)
+			log.WithFields(log.Fields{
+				"IntfId": key.IntfId,
+				"OnuId": key.OnuId,
+			}).Tracef("Gem Port Id %d", key, onuOmciState)
 			// FIXME
 			OnuOmciStateMap[key].state = DONE
 		}
@@ -410,7 +432,10 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci Create", key)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Omci Create")
 
 	return pkt, nil
 }
@@ -428,7 +453,10 @@
 
 	pkt = GetAttributes(class, content, key, pkt)
 
-	log.Printf("%v - Omci Get", key)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Omci Get")
 	return pkt, nil
 }
 
@@ -443,7 +471,10 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci GetAllAlarms", key)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Omci GetAllAlarms")
 
 	return pkt, nil
 }
@@ -459,7 +490,10 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci syncTime", key)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Omci syncTime")
 
 	return pkt, nil
 }
@@ -475,7 +509,10 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci GetAllAlarmsNext", key)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Omci GetAllAlarmsNext")
 
 	return pkt, nil
 }
@@ -491,7 +528,10 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci Delete", key)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Omci Delete")
 
 	return pkt, nil
 }
@@ -506,7 +546,10 @@
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
-	log.Printf("%v - Omci Reboot", key)
+	log.WithFields(log.Fields{
+		"IntfId": key.IntfId,
+		"OnuId": key.OnuId,
+	}).Tracef("Omci Reboot")
 	return pkt, nil
 }