Skip to content

Commit

Permalink
Refactore the log message format (#456)
Browse files Browse the repository at this point in the history
Signed-off-by: Taras Drozdovskyi <t.drozdovsky@samsung.com>
  • Loading branch information
tdrozdovsky committed Jan 25, 2022
1 parent 3fd3445 commit 062a772
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 115 deletions.
32 changes: 14 additions & 18 deletions cmd/edge-orchestration/capi/main.go
Expand Up @@ -82,32 +82,28 @@ import (

"github.com/lf-edge/edge-home-orchestration-go/internal/common/fscreator"
"github.com/lf-edge/edge-home-orchestration-go/internal/common/logmgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/storagemgr"

"github.com/lf-edge/edge-home-orchestration-go/internal/controller/configuremgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/discoverymgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/storagemgr"
mnedcmgr "github.com/lf-edge/edge-home-orchestration-go/internal/controller/discoverymgr/mnedc"
scoringmgr "github.com/lf-edge/edge-home-orchestration-go/internal/controller/scoringmgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/securemgr/authenticator"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/securemgr/authorizer"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/securemgr/verifier"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/servicemgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/servicemgr/executor/nativeexecutor"

"github.com/lf-edge/edge-home-orchestration-go/internal/db/bolt/wrapper"
"github.com/lf-edge/edge-home-orchestration-go/internal/orchestrationapi"

"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/cipher/dummy"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/cipher/sha256"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/client/restclient"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/externalhandler"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/internalhandler"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/route"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/tls"

"github.com/lf-edge/edge-home-orchestration-go/internal/db/bolt/wrapper"
)

const logPrefix = "interface"
const logPrefix = "[interface]"

// Handle Platform Dependencies
const (
Expand Down Expand Up @@ -145,7 +141,7 @@ func OrchestrationInit(secure C.int, mnedc C.int) C.int {
flag.Parse()

logmgr.InitLogfile(logPath)
log.Printf("[%s] OrchestrationInit", logPrefix)
log.Println(logPrefix, "OrchestrationInit")
log.Println(">>> commitID : ", commitID)
log.Println(">>> version : ", version)
log.Println(">>> buildTime : ", buildTime)
Expand All @@ -158,7 +154,7 @@ func OrchestrationInit(secure C.int, mnedc C.int) C.int {

isSecured := false
if secure == 1 {
log.Println("Orchestration init with secure option")
log.Println(logPrefix, "Orchestration init with secure option")
isSecured = true
}

Expand Down Expand Up @@ -187,7 +183,7 @@ func OrchestrationInit(secure C.int, mnedc C.int) C.int {
builder.SetClient(restIns)
orcheEngine = builder.Build()
if orcheEngine == nil {
log.Fatalf("[%s] Orchestaration initialize fail", logPrefix)
log.Fatalf("%s Orchestaration initialize fail", logPrefix)
return -1
}

Expand All @@ -202,7 +198,7 @@ func OrchestrationInit(secure C.int, mnedc C.int) C.int {

internalapi, err := orchestrationapi.GetInternalAPI()
if err != nil {
log.Fatalf("[%s] Orchestaration internal api : %s", logPrefix, err.Error())
log.Fatalf("%s Orchestaration internal api : %s", logPrefix, err.Error())
}
ihandle := internalhandler.GetHandler()
ihandle.SetOrchestrationAPI(internalapi)
Expand All @@ -215,7 +211,7 @@ func OrchestrationInit(secure C.int, mnedc C.int) C.int {

externalapi, err := orchestrationapi.GetExternalAPI()
if err != nil {
log.Fatalf("[%s] Orchestaration external api : %s", logPrefix, err.Error())
log.Fatalf("%s Orchestaration external api : %s", logPrefix, err.Error())
}
ehandle := externalhandler.GetHandler()
ehandle.SetOrchestrationAPI(externalapi)
Expand All @@ -224,7 +220,7 @@ func OrchestrationInit(secure C.int, mnedc C.int) C.int {

restEdgeRouter.Start()

log.Println(logPrefix, "orchestration init done")
log.Println(logPrefix, "Orchestration init done")
mnedcmgr.GetServerInstance().SetCipher(cipher)
if isSecured {
mnedcmgr.GetServerInstance().SetCertificateFilePath(certificateFilePath)
Expand All @@ -234,10 +230,10 @@ func OrchestrationInit(secure C.int, mnedc C.int) C.int {
isMNEDCClient := false
if mnedc == 1 {
isMNEDCServer = true
log.Println("Orchestration init with MNEDC server option")
log.Println(logPrefix, "Orchestration init with MNEDC server option")
} else if mnedc == 2 {
isMNEDCClient = true
log.Println("Orchestration init with MNEDC client option")
log.Println(logPrefix, "Orchestration init with MNEDC client option")
}

go func() {
Expand All @@ -253,7 +249,7 @@ func OrchestrationInit(secure C.int, mnedc C.int) C.int {
// OrchestrationRequestService performs request from service applications which uses orchestration service
//export OrchestrationRequestService
func OrchestrationRequestService(cAppName *C.char, cSelfSelection C.int, cRequester *C.char, serviceInfo *C.RequestServiceInfo, count C.int) C.ResponseService {
log.Printf("[%s] OrchestrationRequestService", logPrefix)
log.Printf("%s OrchestrationRequestService", logPrefix)

appName := C.GoString(cAppName)

Expand All @@ -272,7 +268,7 @@ func OrchestrationRequestService(cAppName *C.char, cSelfSelection C.int, cReques

externalAPI, err := orchestrationapi.GetExternalAPI()
if err != nil {
log.Fatalf("[%s] Orchestaration external api : %s", logPrefix, err.Error())
log.Fatalf("%s Orchestaration external api : %s", logPrefix, err.Error())
}

selfSel := true
Expand All @@ -293,7 +289,7 @@ func OrchestrationRequestService(cAppName *C.char, cSelfSelection C.int, cReques
ServiceInfo: requestInfos,
ServiceRequester: requester,
})
log.Println("requestService handle : ", res)
log.Println(logPrefix, "requestService handle : ", res)

ret := C.ResponseService{}
ret.Message = C.CString(res.Message)
Expand Down
14 changes: 7 additions & 7 deletions cmd/edge-orchestration/javaapi/javaapi.go
Expand Up @@ -52,7 +52,7 @@ import (

// Handle Platform Dependencies
const (
logPrefix = "interface"
logPrefix = "[interface]"
platform = "android"
executionType = "android"

Expand Down Expand Up @@ -109,7 +109,7 @@ func (r *ReqeustService) SetExecutionCommand(execType string, command string) {
switch execType {
case "native", "android", "container":
default:
log.Printf("[%s] Invalid execution type: %s", logPrefix, execType)
log.Printf("%s Invalid execution type: %s", logPrefix, execType)
return
}

Expand Down Expand Up @@ -180,7 +180,7 @@ func OrchestrationInit(executeCallback ExecuteCallback, edgeDir string, isSecure
}

logmgr.InitLogfile(logPath)
log.Printf("[%s] OrchestrationInit", logPrefix)
log.Printf("%s OrchestrationInit", logPrefix)

wrapper.SetBoltDBPath(dbPath)

Expand Down Expand Up @@ -209,7 +209,7 @@ func OrchestrationInit(executeCallback ExecuteCallback, edgeDir string, isSecure

orcheEngine = builder.Build()
if orcheEngine == nil {
log.Fatalf("[%s] Orchestration initialize fail", logPrefix)
log.Fatalf("%s Orchestration initialize fail", logPrefix)
return
}

Expand All @@ -227,7 +227,7 @@ func OrchestrationInit(executeCallback ExecuteCallback, edgeDir string, isSecure

internalapi, err := orchestrationapi.GetInternalAPI()
if err != nil {
log.Fatalf("[%s] Orchestration internal api : %s", logPrefix, err.Error())
log.Fatalf("%s Orchestration internal api : %s", logPrefix, err.Error())
}
ihandle := internalhandler.GetHandler()
ihandle.SetOrchestrationAPI(internalapi)
Expand All @@ -249,12 +249,12 @@ func OrchestrationInit(executeCallback ExecuteCallback, edgeDir string, isSecure

// OrchestrationRequestService performs request from service applications which uses orchestration service
func OrchestrationRequestService(request *ReqeustService) *ResponseService {
log.Printf("[%s] OrchestrationRequestService", logPrefix)
log.Printf("%s OrchestrationRequestService", logPrefix)
log.Println("Service name: ", request.ServiceName)

externalAPI, err := orchestrationapi.GetExternalAPI()
if err != nil {
log.Fatalf("[%s] Orchestaration external api : %s", logPrefix, err.Error())
log.Fatalf("%s Orchestaration external api : %s", logPrefix, err.Error())
}

changed := orchestrationapi.ReqeustService{
Expand Down
24 changes: 10 additions & 14 deletions cmd/edge-orchestration/main.go
Expand Up @@ -28,31 +28,27 @@ import (
"github.com/lf-edge/edge-home-orchestration-go/internal/common/sigmgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/cloudsyncmgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/storagemgr"

"github.com/lf-edge/edge-home-orchestration-go/internal/controller/configuremgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/discoverymgr"
mnedcmgr "github.com/lf-edge/edge-home-orchestration-go/internal/controller/discoverymgr/mnedc"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/scoringmgr"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/securemgr/authenticator"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/securemgr/authorizer"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/securemgr/verifier"
"github.com/lf-edge/edge-home-orchestration-go/internal/controller/servicemgr"
mnedcmgr "github.com/lf-edge/edge-home-orchestration-go/internal/controller/discoverymgr/mnedc"
executor "github.com/lf-edge/edge-home-orchestration-go/internal/controller/servicemgr/executor/containerexecutor"

"github.com/lf-edge/edge-home-orchestration-go/internal/db/bolt/wrapper"
"github.com/lf-edge/edge-home-orchestration-go/internal/orchestrationapi"

"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/cipher/dummy"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/cipher/sha256"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/client/restclient"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/externalhandler"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/internalhandler"
"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/route"

"github.com/lf-edge/edge-home-orchestration-go/internal/db/bolt/wrapper"
"github.com/lf-edge/edge-home-orchestration-go/internal/webui"
)

const logPrefix = "interface"
const logPrefix = "[interface]"

// Handle Platform Dependencies
const (
Expand Down Expand Up @@ -81,15 +77,15 @@ var (

func main() {
if err := orchestrationInit(); err != nil {
log.Fatalf("[%s] Orchestaration initialize fail : %s", logPrefix, err.Error())
log.Fatalf("%s Orchestaration initialize fail : %s", logPrefix, err.Error())
}
sigmgr.Watch()
}

// orchestrationInit runs orchestration service and discovers other orchestration services in other devices
func orchestrationInit() error {
logmgr.InitLogfile(logPath)
log.Printf("[%s] OrchestrationInit", logPrefix)
log.Println(logPrefix, "OrchestrationInit")
log.Println(">>> commitID : ", commitID)
log.Println(">>> version : ", version)
log.Println(">>> buildTime : ", buildTime)
Expand All @@ -107,7 +103,7 @@ func orchestrationInit() error {
isSecured := false
if len(secure) > 0 {
if strings.Compare(strings.ToLower(secure), "true") == 0 {
log.Println("Orchestration init with secure option")
log.Println(logPrefix, "Orchestration init with secure option")
isSecured = true
}
}
Expand Down Expand Up @@ -140,7 +136,7 @@ func orchestrationInit() error {

orcheEngine := builder.Build()
if orcheEngine == nil {
log.Fatalf("[%s] Orchestaration initialize fail", logPrefix)
log.Fatalf("%s Orchestration initialize fail", logPrefix)
return errors.New("fail to init orchestration")
}

Expand All @@ -155,7 +151,7 @@ func orchestrationInit() error {

internalapi, err := orchestrationapi.GetInternalAPI()
if err != nil {
log.Fatalf("[%s] Orchestaration internal api : %s", logPrefix, err.Error())
log.Fatalf("%s Orchestaration internal api : %s", logPrefix, err.Error())
}
ihandle := internalhandler.GetHandler()
ihandle.SetOrchestrationAPI(internalapi)
Expand All @@ -169,7 +165,7 @@ func orchestrationInit() error {
// external rest api
externalapi, err := orchestrationapi.GetExternalAPI()
if err != nil {
log.Fatalf("[%s] Orchestaration external api : %s", logPrefix, err.Error())
log.Fatalf("%s Orchestaration external api : %s", logPrefix, err.Error())
}
ehandle := externalhandler.GetHandler()
ehandle.SetOrchestrationAPI(externalapi)
Expand All @@ -196,7 +192,7 @@ func orchestrationInit() error {
if strings.Compare(strings.ToLower(ui), "true") == 0 {
webui.Start()
}
log.Println(logPrefix, "orchestration init done")
log.Println(logPrefix, "Orchestration init done")

return nil
}
6 changes: 3 additions & 3 deletions internal/common/networkhelper/detector/detector_netlink.go
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/vishvananda/netlink"
)

const logPrefix = "detector_netlink"
const logPrefix = "[detectornetlink]"

type detectorImpl struct{}

Expand Down Expand Up @@ -79,10 +79,10 @@ func detectionHandler(detect netlink.AddrUpdate) bool {
}

if updatedAddr.NewAddr {
log.Println(logPrefix, "[DetectionHandler]", "New Connection : ", updatedAddr.LinkAddress.IP)
log.Println(logPrefix, "New Connection : ", updatedAddr.LinkAddress.IP)
return true
}

log.Println(logPrefix, "[DetectionHandler]", "Disconnected : ", updatedAddr.LinkAddress.IP)
log.Println(logPrefix, "Disconnected : ", updatedAddr.LinkAddress.IP)
return true
}
2 changes: 1 addition & 1 deletion internal/common/resourceutil/resourceutil.go
Expand Up @@ -66,7 +66,7 @@ const (
// NetRTT defined network/rtt
NetRTT = "network/rtt"

logPrefix = "resourceutil"
logPrefix = "[resourceutil]"
defaultProcessingTime = 5
)

Expand Down

0 comments on commit 062a772

Please sign in to comment.