Skip to content

Commit

Permalink
Merge pull request #1726 from 0chain/fix/logging-and-put-txn-timeout
Browse files Browse the repository at this point in the history
Fix logging and timeout
  • Loading branch information
dabasov authored Jan 6, 2025
2 parents 9f52f52 + 28d85b7 commit fd17b62
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
6 changes: 1 addition & 5 deletions core/client/init_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ import (
)

var (
logging logger.Logger
logging = logger.GetLogger()
nodeClient *Node
)

func init() {
logging.Init(logger.DEBUG, "0chain-core")
}

// Node Maintains central states of SDK (client's context, network).
// Initialized through [Init] function.
// Use client.GetNode() to get its instance after Init is called.
Expand Down
38 changes: 38 additions & 0 deletions core/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package logger

import (
"fmt"
"github.com/0chain/gosdk/core/version"
"gopkg.in/natefinch/lumberjack.v2"
"io"
"log"
"os"
Expand Down Expand Up @@ -142,3 +144,39 @@ func (l *Logger) Close() {
}
}
}

// Initialize common logger
var logging Logger

func GetLogger() *Logger {
return &logging
}

func CloseLog() {
logging.Close()
}

func init() {
logging.Init(DEBUG, "0chain-core-sdk")
}

// SetLogLevel set the log level.
// lvl - 0 disabled; higher number (upto 4) more verbosity
func SetLogLevel(lvl int) {
logging.SetLevel(lvl)
}

// SetLogFile - sets file path to write log
// verbose - true - console output; false - no console output
func SetLogFile(logFile string, verbose bool) {
ioWriter := &lumberjack.Logger{
Filename: logFile,
MaxSize: 100, // MB
MaxBackups: 5, // number of backups
MaxAge: 28, //days
LocalTime: false,
Compress: false, // disabled by default
}
logging.SetLogFile(ioWriter, verbose)
logging.Info("******* Wallet SDK Version:", version.VERSIONSTR, " ******* (SetLogFile)")
}
4 changes: 2 additions & 2 deletions core/transaction/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
lru "github.com/hashicorp/golang-lru"
)

var Logger logger.Logger
var Logger = logger.GetLogger()

const STORAGE_SCADDRESS = "6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d7"
const MINERSC_SCADDRESS = "6dba10422e368813802877a85039d3985d96760ed844092319743fb3a76712d9"
Expand Down Expand Up @@ -270,7 +270,7 @@ func (t *Transaction) VerifySigWith(pubkey string, verifyHandler VerifyFunc) (bo
}

func SendTransactionSync(txn *Transaction, miners []string) error {
const requestTimeout = 30 * time.Second // Timeout for each request
const requestTimeout = 3 * time.Second // Timeout for each request

fails := make(chan error, len(miners))
var wg sync.WaitGroup
Expand Down
8 changes: 1 addition & 7 deletions zboxcore/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,5 @@ package logger

import "github.com/0chain/gosdk/core/logger"

var defaultLogLevel = logger.DEBUG

// Logger global logger instance
var Logger logger.Logger

func init() {
Logger.Init(defaultLogLevel, "0box-sdk")
}
var Logger = logger.GetLogger()
2 changes: 1 addition & 1 deletion zboxcore/sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func SetLogFile(logFile string, verbose bool) {

// GetLogger retrieves logger instance
func GetLogger() *logger.Logger {
return &l.Logger
return l.Logger
}

type BackPool struct {
Expand Down
8 changes: 2 additions & 6 deletions zcncore/wallet_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ const (
)

var defaultLogLevel = logger.DEBUG

Check failure on line 81 in zcncore/wallet_base.go

View workflow job for this annotation

GitHub Actions / lint

var `defaultLogLevel` is unused (unused)
var logging logger.Logger
var logging = logger.GetLogger()

// GetLogger returns the logger instance
func GetLogger() *logger.Logger {
return &logging
return logging
}

// CloseLog closes log file
Expand Down Expand Up @@ -141,10 +141,6 @@ type AuthCallback interface {
OnSetupComplete(status int, err string)
}

func init() {
logging.Init(defaultLogLevel, "0chain-core-sdk")
}

func checkSdkInit() error {
_, err := client.GetNode()
if err != nil {
Expand Down

0 comments on commit fd17b62

Please sign in to comment.