Add --statediff.db.logstatements option. #307
@ -265,6 +265,9 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
|
|||||||
if ctx.IsSet(utils.StateDiffDBConnTimeout.Name) {
|
if ctx.IsSet(utils.StateDiffDBConnTimeout.Name) {
|
||||||
pgConfig.ConnTimeout = time.Duration(ctx.Duration(utils.StateDiffDBConnTimeout.Name).Seconds())
|
pgConfig.ConnTimeout = time.Duration(ctx.Duration(utils.StateDiffDBConnTimeout.Name).Seconds())
|
||||||
}
|
}
|
||||||
|
if ctx.IsSet(utils.StateDiffLogStatements.Name) {
|
||||||
|
pgConfig.LogStatements = ctx.Bool(utils.StateDiffLogStatements.Name)
|
||||||
|
}
|
||||||
indexerConfig = pgConfig
|
indexerConfig = pgConfig
|
||||||
case shared.DUMP:
|
case shared.DUMP:
|
||||||
dumpTypeStr := ctx.String(utils.StateDiffDBDumpDst.Name)
|
dumpTypeStr := ctx.String(utils.StateDiffDBDumpDst.Name)
|
||||||
|
|||||||
@ -179,6 +179,7 @@ var (
|
|||||||
utils.StateDiffWaitForSync,
|
utils.StateDiffWaitForSync,
|
||||||
utils.StateDiffWatchedAddressesFilePath,
|
utils.StateDiffWatchedAddressesFilePath,
|
||||||
utils.StateDiffUpsert,
|
utils.StateDiffUpsert,
|
||||||
|
utils.StateDiffLogStatements,
|
||||||
configFileFlag,
|
configFileFlag,
|
||||||
}, utils.NetworkFlags, utils.DatabasePathFlags)
|
}, utils.NetworkFlags, utils.DatabasePathFlags)
|
||||||
|
|
||||||
|
|||||||
@ -1078,6 +1078,11 @@ var (
|
|||||||
Usage: "Should the statediff service overwrite data existing in the database?",
|
Usage: "Should the statediff service overwrite data existing in the database?",
|
||||||
Value: false,
|
Value: false,
|
||||||
}
|
}
|
||||||
|
StateDiffLogStatements = &cli.BoolFlag{
|
||||||
|
Name: "statediff.db.logstatements",
|
||||||
|
Usage: "Should the statediff service log all database statements?",
|
||||||
|
Value: false,
|
||||||
|
}
|
||||||
StateDiffWritingFlag = &cli.BoolFlag{
|
StateDiffWritingFlag = &cli.BoolFlag{
|
||||||
Name: "statediff.writing",
|
Name: "statediff.writing",
|
||||||
Usage: "Activates progressive writing of state diffs to database as new block are synced",
|
Usage: "Activates progressive writing of state diffs to database as new block are synced",
|
||||||
|
|||||||
@ -70,6 +70,7 @@ type Config struct {
|
|||||||
MaxConnIdleTime time.Duration
|
MaxConnIdleTime time.Duration
|
||||||
MaxConnLifetime time.Duration
|
MaxConnLifetime time.Duration
|
||||||
ConnTimeout time.Duration
|
ConnTimeout time.Duration
|
||||||
|
LogStatements bool
|
||||||
|
|
||||||
// node info params
|
// node info params
|
||||||
ID string
|
ID string
|
||||||
|
|||||||
61
statediff/indexer/database/sql/postgres/log_adapter.go
Normal file
61
statediff/indexer/database/sql/postgres/log_adapter.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
// Copyright © 2023 Cerc
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package postgres
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/jackc/pgx/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LogAdapter struct {
|
||||||
|
l log.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLogAdapter(l log.Logger) *LogAdapter {
|
||||||
|
return &LogAdapter{l: l}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LogAdapter) Log(ctx context.Context, level pgx.LogLevel, msg string, data map[string]interface{}) {
|
||||||
|
var logger log.Logger
|
||||||
|
if data != nil {
|
||||||
|
var args = make([]interface{}, 0)
|
||||||
|
for key, value := range data {
|
||||||
|
if value != nil {
|
||||||
|
args = append(args, key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger = l.l.New(args...)
|
||||||
|
} else {
|
||||||
|
logger = l.l
|
||||||
|
}
|
||||||
|
|
||||||
|
switch level {
|
||||||
|
case pgx.LogLevelTrace:
|
||||||
|
logger.Trace(msg)
|
||||||
|
case pgx.LogLevelDebug:
|
||||||
|
logger.Debug(msg)
|
||||||
|
case pgx.LogLevelInfo:
|
||||||
|
logger.Info(msg)
|
||||||
|
case pgx.LogLevelWarn:
|
||||||
|
logger.Warn(msg)
|
||||||
|
case pgx.LogLevelError:
|
||||||
|
logger.Error(msg)
|
||||||
|
default:
|
||||||
|
logger.New("INVALID_PGX_LOG_LEVEL", level).Error(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,6 +20,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
|
||||||
"github.com/georgysavva/scany/pgxscan"
|
"github.com/georgysavva/scany/pgxscan"
|
||||||
"github.com/jackc/pgconn"
|
"github.com/jackc/pgconn"
|
||||||
"github.com/jackc/pgx/v4"
|
"github.com/jackc/pgx/v4"
|
||||||
@ -85,6 +87,11 @@ func MakeConfig(config Config) (*pgxpool.Config, error) {
|
|||||||
if config.MaxConnIdleTime != 0 {
|
if config.MaxConnIdleTime != 0 {
|
||||||
conf.MaxConnIdleTime = config.MaxConnIdleTime
|
conf.MaxConnIdleTime = config.MaxConnIdleTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.LogStatements {
|
||||||
|
conf.ConnConfig.Logger = NewLogAdapter(log.New())
|
||||||
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user