From f613fcafd2d47e7f19859a2a5a9b6567cf1f49bc Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Wed, 29 Jun 2022 08:42:11 +0600 Subject: [PATCH] torrent verbosity allow debug #4569 Open --- .../downloader/downloadercfg/downloadercfg.go | 8 ++++---- .../downloader/downloadercfg/logger.go | 19 +++++++++---------- cmd/downloader/main.go | 4 ++-- cmd/utils/flags.go | 6 +++--- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/cmd/downloader/downloader/downloadercfg/downloadercfg.go b/cmd/downloader/downloader/downloadercfg/downloadercfg.go index 51fb7a752..761c421f3 100644 --- a/cmd/downloader/downloader/downloadercfg/downloadercfg.go +++ b/cmd/downloader/downloader/downloadercfg/downloadercfg.go @@ -54,7 +54,7 @@ func Default() *torrent.ClientConfig { return torrentConfig } -func New(snapDir string, verbosity lg.Level, natif nat.Interface, downloadRate, uploadRate datasize.ByteSize, port, connsPerFile, downloadSlots int) (*Cfg, error) { +func New(snapDir string, verbosity lg.Level, dbg bool, natif nat.Interface, downloadRate, uploadRate datasize.ByteSize, port, connsPerFile, downloadSlots int) (*Cfg, error) { torrentConfig := Default() // We would-like to reduce amount of goroutines in Erigon, so reducing next params torrentConfig.EstablishedConnsPerTorrent = connsPerFile // default: 50 @@ -114,9 +114,9 @@ func New(snapDir string, verbosity lg.Level, natif nat.Interface, downloadRate, } // debug - //if lg.Debug == verbosity { - // torrentConfig.Debug = true - //} + if dbg { + torrentConfig.Debug = true + } torrentConfig.Logger = lg.Default.FilterLevel(verbosity) torrentConfig.Logger.Handlers = []lg.Handler{adapterHandler{}} diff --git a/cmd/downloader/downloader/downloadercfg/logger.go b/cmd/downloader/downloader/downloadercfg/logger.go index f21650263..7c71fa81e 100644 --- a/cmd/downloader/downloader/downloadercfg/logger.go +++ b/cmd/downloader/downloader/downloadercfg/logger.go @@ -14,26 +14,25 @@ func init() { utp.Logger.Handlers = []lg.Handler{noopHandler{}} } -func Int2LogLevel(level int) (lg.Level, error) { - lvl := lg.Level{} - +func Int2LogLevel(level int) (lvl lg.Level, dbg bool, err error) { switch level { case 0: - lvl = lg.NotSet - case 1: lvl = lg.Critical - case 2: + case 1: lvl = lg.Error - case 3: + case 2: lvl = lg.Warning - case 4: + case 3: lvl = lg.Info + case 4: + lvl = lg.Debug case 5: lvl = lg.Debug + dbg = true default: - return lvl, fmt.Errorf("invalid level set, expected a number between 0-5 but got: %d", level) + return lvl, dbg, fmt.Errorf("invalid level set, expected a number between 0-5 but got: %d", level) } - return lvl, nil + return lvl, dbg, nil } type noopHandler struct{} diff --git a/cmd/downloader/main.go b/cmd/downloader/main.go index ac415b95e..6f833871a 100644 --- a/cmd/downloader/main.go +++ b/cmd/downloader/main.go @@ -114,7 +114,7 @@ var rootCmd = &cobra.Command{ func Downloader(ctx context.Context) error { dirs := datadir.New(datadirCli) - torrentLogLevel, err := downloadercfg.Int2LogLevel(torrentVerbosity) + torrentLogLevel, dbg, err := downloadercfg.Int2LogLevel(torrentVerbosity) if err != nil { return err } @@ -134,7 +134,7 @@ func Downloader(ctx context.Context) error { return fmt.Errorf("invalid nat option %s: %w", natSetting, err) } - cfg, err := downloadercfg.New(dirs.Snap, torrentLogLevel, natif, downloadRate, uploadRate, torrentPort, torrentConnsPerFile, torrentDownloadSlots) + cfg, err := downloadercfg.New(dirs.Snap, torrentLogLevel, dbg, natif, downloadRate, uploadRate, torrentPort, torrentConnsPerFile, torrentDownloadSlots) if err != nil { return err } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 31b3a90ad..a06e6050f 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -646,7 +646,7 @@ var ( } TorrentVerbosityFlag = cli.IntFlag{ Name: "torrent.verbosity", - Value: 3, + Value: 2, Usage: "0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (must set --verbosity to equal or higher level and has defeault: 3)", } TorrentDownloadRateFlag = cli.StringFlag{ @@ -1401,11 +1401,11 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C panic(err) } log.Info("torrent verbosity", "level", ctx.GlobalInt(TorrentVerbosityFlag.Name)) - lvl, err := downloadercfg.Int2LogLevel(ctx.GlobalInt(TorrentVerbosityFlag.Name)) + lvl, dbg, err := downloadercfg.Int2LogLevel(ctx.GlobalInt(TorrentVerbosityFlag.Name)) if err != nil { panic(err) } - cfg.Downloader, err = downloadercfg.New(cfg.Dirs.Snap, lvl, nodeConfig.P2P.NAT, downloadRate, uploadRate, ctx.GlobalInt(TorrentPortFlag.Name), ctx.GlobalInt(TorrentConnsPerFileFlag.Name), ctx.GlobalInt(TorrentDownloadSlotsFlag.Name)) + cfg.Downloader, err = downloadercfg.New(cfg.Dirs.Snap, lvl, dbg, nodeConfig.P2P.NAT, downloadRate, uploadRate, ctx.GlobalInt(TorrentPortFlag.Name), ctx.GlobalInt(TorrentConnsPerFileFlag.Name), ctx.GlobalInt(TorrentDownloadSlotsFlag.Name)) if err != nil { panic(err) }