From f458255801f7adca98f5af947d864aa908ff418f Mon Sep 17 00:00:00 2001 From: Bernardo Ramos Date: Tue, 29 Oct 2024 01:21:13 +0000 Subject: [PATCH] add some logs --- contract/internal_operations.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/contract/internal_operations.go b/contract/internal_operations.go index 1b4da6847..cb8613e98 100644 --- a/contract/internal_operations.go +++ b/contract/internal_operations.go @@ -2,7 +2,6 @@ package contract import ( "encoding/json" - "log" "sync" "github.com/aergoio/aergo/v2/internal/enc/base58" @@ -44,14 +43,14 @@ func getCurrentCall(ctx *vmContext, callDepth int32) *InternalCall { opCall := &ctx.internalOpsCall for { if opCall == nil { - log.Printf("no call found at depth %d", depth) + ctrLgr.Printf("no call found at depth %d", depth) break } if depth == callDepth { return opCall } if len(opCall.Operations) == 0 { - log.Printf("no operations found at depth %d", depth) + ctrLgr.Printf("no operations found at depth %d", depth) break } opCall = opCall.Operations[len(opCall.Operations)-1].Call @@ -65,6 +64,8 @@ func logOperation(ctx *vmContext, amount string, operation string, args ...strin return 0 } + ctrLgr.Printf("logOperation: depth: %d, amount: %s, operation: %s, args: %v", ctx.callDepth, amount, operation, args) + opsLock.Lock() defer opsLock.Unlock() @@ -82,7 +83,7 @@ func logOperation(ctx *vmContext, amount string, operation string, args ...strin opCall := getCurrentCall(ctx, ctx.callDepth) if opCall == nil { - log.Printf("no call found") + ctrLgr.Printf("no call found") return 0 } // add the operation to the list @@ -96,6 +97,8 @@ func logOperationResult(ctx *vmContext, operationId int64, result string) { return } + ctrLgr.Printf("logOperationResult: depth: %d, operationId: %d, result: %s", ctx.callDepth, operationId, result) + opsLock.Lock() defer opsLock.Unlock() @@ -113,7 +116,7 @@ func logOperationResult(ctx *vmContext, operationId int64, result string) { } } - log.Printf("no operation found with ID %d to store result", operationId) + ctrLgr.Printf("no operation found with ID %d to store result", operationId) } func logInternalCall(ctx *vmContext, contract string, function string, args []interface{}) error { @@ -121,9 +124,11 @@ func logInternalCall(ctx *vmContext, contract string, function string, args []in return nil } + ctrLgr.Printf("logInternalCall: depth: %d, contract: %s, function: %s, args: %s", ctx.callDepth, contract, function, argsToJson(args)) + opCall := getCurrentCall(ctx, ctx.callDepth-1) if opCall == nil { - log.Printf("no call found") + ctrLgr.Printf("no call found") return nil } @@ -141,6 +146,7 @@ func logInternalCall(ctx *vmContext, contract string, function string, args []in } func logFirstCall(ctx *vmContext, contract string, function string, args []interface{}) { + ctrLgr.Printf("logFirstCall: depth: %d, contract: %s, function: %s, args: %s", ctx.callDepth, contract, function, argsToJson(args)) ctx.internalOpsCall.Contract = contract ctx.internalOpsCall.Function = function ctx.internalOpsCall.Args = args @@ -154,6 +160,17 @@ func logCall(ctx *vmContext, contract string, function string, args []interface{ } } +func argsToJson(argsList []interface{}) (string) { + if argsList == nil { + return "" + } + args, err := json.Marshal(argsList) + if err != nil { + return "" + } + return string(args) +} + func getInternalOperations(ctx *vmContext) string { if doNotLog(ctx) { return "" @@ -172,7 +189,7 @@ func getInternalOperations(ctx *vmContext) string { data, err := json.Marshal(internalOps) if err != nil { - log.Fatal("Failed to marshal operations:", err) + ctrLgr.Fatal().Err(err).Msg("Failed to marshal operations") return "" }