Commit 66de9f2c authored by suyanlong's avatar suyanlong

fix log func

parent cb3e7668
......@@ -13,6 +13,9 @@ type Config struct {
}
type Log struct {
Dir string `toml:"dir" json:"dir"`
Filename string `mapstructure:"filename" json:"filename"`
ReportCaller bool `mapstructure:"report_caller"`
Level string `mapstructure:"level" json:"level"` // NoLevel:0, trace:1, debug:2, info:3, warn:4, error:5, off:6
}
......
......@@ -4,20 +4,20 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"time"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/db"
types33 "github.com/33cn/chain33/types"
evmxgotypes "github.com/33cn/plugin/plugin/dapp/evmxgo/types"
"github.com/hashicorp/go-hclog"
"github.com/spf13/cast"
"gitlab.33.cn/link33/sidecar-client-chain33/client/rpc"
"gitlab.33.cn/link33/sidecar-client-chain33/config"
"gitlab.33.cn/link33/sidecar-client-chain33/types"
"gitlab.33.cn/link33/sidecar-client-chain33/util"
"gitlab.33.cn/link33/sidecar/model/pb"
"gitlab.33.cn/link33/sidecar/pkg/log"
"gitlab.33.cn/link33/sidecar/pkg/plugins"
"go.uber.org/atomic"
)
......@@ -36,11 +36,7 @@ var (
PluginName = evmxgotypes.EvmxgoX
ID = evmxgotypes.EvmxgoX
execer = evmxgotypes.EvmxgoX
logger = hclog.New(&hclog.LoggerOptions{
Name: "chain33-client-" + PluginName,
Output: os.Stderr,
Level: hclog.Trace,
})
logger = log.NewWithModule("chain33-client-" + PluginName)
)
type Evmxgo struct {
......@@ -95,14 +91,28 @@ func (e *Evmxgo) ID() string {
// configPath 完整路径
func (e *Evmxgo) Initialize(configPath string, _ string, _ []byte) error {
// 初始化e.client工作
e.eventC = make(chan *pb.IBTP, 10)
e.done = make(chan bool)
e.ticker = time.NewTicker(2 * time.Second)
chain33Config, err := config.UnmarshalConfig(configPath)
if err != nil {
return fmt.Errorf("unmarshal config for plugin :%w", err)
}
err = log.Initialize(
log.WithReportCaller(chain33Config.Log.ReportCaller == true),
log.WithPersist(true),
log.WithFilePath(filepath.Join(filepath.Dir(configPath), "logs", "evmxgo.log")),
log.WithFileName("chain33-client-"+PluginName),
log.WithMaxSize(2*1024*1024),
log.WithMaxAge(24*time.Hour),
log.WithRotationTime(24*time.Hour),
)
if err != nil {
return fmt.Errorf("log initialize: %w", err)
}
log.ParseLevel(chain33Config.Log.Level)
// 初始化e.client工作
e.eventC = make(chan *pb.IBTP, 10)
e.done = make(chan bool)
e.ticker = time.NewTicker(2 * time.Second)
logger.Info("print chain33Config", "chain33Config", util.Sprint(chain33Config))
logger.Info("print privateKey", "privateKey", chain33Config.Chain33.PrivateKey)
e.pk = chain33Config.Chain33.PrivateKey
......@@ -110,7 +120,6 @@ func (e *Evmxgo) Initialize(configPath string, _ string, _ []byte) error {
e.fromID = chain33Config.Router.FromChain
e.toID = chain33Config.Router.ToChain
e.fee = chain33Config.Chain33.Fee
logger.SetLevel(hclog.LevelFromString(chain33Config.Log.Level))
// 初始化chain33 client rpc
client, err := rpc.NewClient("", chain33Config.Chain33.Addr)
......
This diff is collapsed.
This diff is collapsed.
......@@ -8,9 +8,11 @@ import (
"fmt"
"math/big"
"math/rand"
"os"
"path/filepath"
"time"
"gitlab.33.cn/link33/sidecar/pkg/log"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto"
......@@ -20,7 +22,6 @@ import (
util33 "github.com/33cn/chain33/util"
"github.com/33cn/plugin/plugin/dapp/paracross/executor"
paracorssTypes "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/hashicorp/go-hclog"
"github.com/spf13/cast"
"gitlab.33.cn/link33/sidecar-client-chain33/config"
"gitlab.33.cn/link33/sidecar-client-chain33/types"
......@@ -35,11 +36,7 @@ var (
PluginName = paracorssTypes.ParaX
ID = paracorssTypes.ParaX
execer = paracorssTypes.ParaX
logger = hclog.New(&hclog.LoggerOptions{
Name: "chain33-client-" + PluginName,
Output: os.Stderr,
Level: hclog.Trace,
})
logger = log.NewWithModule("chain33-client-" + PluginName)
)
type Paracross struct {
......@@ -115,14 +112,28 @@ func (p *Paracross) ID() string {
}
func (p *Paracross) Initialize(configPath string, ID string, extra []byte) error {
// 初始化e.client工作
p.eventC = make(chan *pb.IBTP, 10)
p.done = make(chan bool)
p.ticker = time.NewTicker(2 * time.Second)
chain33Config, err := config.UnmarshalConfig(configPath)
if err != nil {
return fmt.Errorf("unmarshal config for plugin :%w", err)
}
err = log.Initialize(
log.WithReportCaller(chain33Config.Log.ReportCaller == true),
log.WithPersist(true),
log.WithFilePath(filepath.Join(filepath.Dir(configPath), "logs", "paracross.log")),
log.WithFileName("chain33-client-"+PluginName),
log.WithMaxSize(2*1024*1024),
log.WithMaxAge(24*time.Hour),
log.WithRotationTime(24*time.Hour),
)
if err != nil {
return fmt.Errorf("log initialize: %w", err)
}
log.ParseLevel(chain33Config.Log.Level)
// 初始化e.client工作
p.eventC = make(chan *pb.IBTP, 10)
p.done = make(chan bool)
p.ticker = time.NewTicker(2 * time.Second)
logger.Info("print chain33Config", "chain33Config", util.Sprint(chain33Config))
logger.Info("print privateKey", "privateKey", chain33Config.Chain33.PrivateKey)
p.privateKey = util33.HexToPrivkey(chain33Config.Chain33.PrivateKey)
......@@ -132,7 +143,6 @@ func (p *Paracross) Initialize(configPath string, ID string, extra []byte) error
p.title = chain33Config.Chain33.Title
p.MinTxFeeRate = chain33Config.Chain33.Fee
p.isTest = chain33Config.Chain33.IsTest
logger.SetLevel(hclog.LevelFromString(chain33Config.Log.Level))
config33 = fmt.Sprintf(config33, p.title, chain33Config.Chain33.Addr)
logger.Info(config33)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment