Skip to content

Commit

Permalink
[LOG]Add loggers for logical/physical sql and tx(#596) (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mulavar authored Jun 25, 2023
1 parent 5c4ff75 commit c95f464
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 55 deletions.
8 changes: 6 additions & 2 deletions conf/bootstrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ supervisor:

logging_config:
log_name: arana_log
log_path: ./
log_path: log
log_level: 7 #KERN_DEBUG
log_max_size: 10
log_max_backups: 5
log_max_age: 30
log_compress: false
default_log_name: "arana.log"
default_log_name: arana.log
tx_log_name: tx.log
sql_log_enabled: false
sql_log_name: sql.log
physical_sql_log_name: physql.log
2 changes: 1 addition & 1 deletion pkg/config/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func LoadBootOptions(path string) (*BootOptions, error) {
return nil, err
}

log.Init(cfg.LogPath, log.InfoLevel, cfg.LoggingConfig)
log.Init(cfg.LoggingConfig)
return &cfg, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (executor *RedirectExecutor) ExecutorComQuery(ctx *proto.Context, h func(re
return h(nil, 0, errEmptyQuery)
}

log.Debugf("ComQuery: '%s'", query)
log.DebugfWithLogType(log.LogicalSqlLog, "ComQuery: '%s'", query)

charset, collation := getCharsetCollation(ctx.C.CharacterSet())

Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/namespace/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func UpdateSlowThreshold() Command {

func UpdateSlowLogger(path string, cfg *log.LoggingConfig) Command {
return func(ns *Namespace) error {
ns.slowLog = log.NewLogger(path, log.WarnLevel, cfg)
ns.slowLog = log.NewSlowLogger(path, cfg)
return nil
}
}
2 changes: 1 addition & 1 deletion pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func (pi *defaultRuntime) Begin(ctx context.Context, hooks ...TxHook) (proto.Tx,
defer span.End()

tx := newCompositeTx(ctx, pi, hooks...)
log.Debugf("begin transaction: %s", tx)
log.DebugfWithLogType(log.TxLog, "begin transaction: %s", tx)
return tx, nil
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/runtime/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (tx *compositeTx) Commit(ctx context.Context) (proto.Result, uint16, error)
if err := tx.doCommit(ctx); err != nil {
return nil, 0, err
}
log.Debugf("commit %s success: total=%d", tx, len(tx.txs))
log.DebugfWithLogType(log.TxLog, "commit %s success: total=%d", tx, len(tx.txs))
return resultx.New(), 0, nil
}

Expand All @@ -324,7 +324,7 @@ func (tx *compositeTx) doPrepareCommit(ctx context.Context) error {
k, v := k, v
g.Go(func() error {
if err := v.Prepare(ctx); err != nil {
log.Errorf("prepare commit %s for group %s failed: %v", tx, k, err)
log.ErrorfWithLogType(log.TxLog, "prepare commit %s for group %s failed: %v", tx, k, err)
return err
}
return nil
Expand All @@ -347,7 +347,7 @@ func (tx *compositeTx) doCommit(ctx context.Context) error {
k, v := k, v
g.Go(func() error {
if _, _, err := v.Commit(ctx); err != nil {
log.Errorf("commit %s for group %s failed: %v", tx, k, err)
log.ErrorfWithLogType(log.TxLog, "commit %s for group %s failed: %v", tx, k, err)
return err
}
return nil
Expand Down Expand Up @@ -381,7 +381,7 @@ func (tx *compositeTx) Rollback(ctx context.Context) (proto.Result, uint16, erro
return nil, 0, err
}

log.Debugf("rollback %s success: total=%d", tx, len(tx.txs))
log.DebugfWithLogType(log.TxLog, "rollback %s success: total=%d", tx, len(tx.txs))
return resultx.New(), 0, nil
}

Expand All @@ -393,7 +393,7 @@ func (tx *compositeTx) doPrepareRollback(ctx context.Context) error {
k, v := k, v
g.Go(func() error {
if err := v.Prepare(ctx); err != nil {
log.Errorf("prepare rollback %s for group %s failed: %v", tx, k, err)
log.ErrorfWithLogType(log.TxLog, "prepare rollback %s for group %s failed: %v", tx, k, err)
return err
}
return nil
Expand All @@ -416,7 +416,7 @@ func (tx *compositeTx) doRollback(ctx context.Context) error {
k, v := k, v
g.Go(func() error {
if _, _, err := v.Rollback(ctx); err != nil {
log.Errorf("rollback %s for group %s failed: %v", tx, k, err)
log.ErrorfWithLogType(log.TxLog, "rollback %s for group %s failed: %v", tx, k, err)
return err
}
return nil
Expand Down Expand Up @@ -445,7 +445,7 @@ func (tx *compositeTx) setTxState(ctx context.Context, state TxState) {
tx.txState = state
for i := range tx.hooks {
if err := tx.hooks[i].OnTxStateChange(ctx, state, tx); err != nil {
log.Errorf("[TX] %s trigger trx state change fail : %+v", tx, err)
log.ErrorfWithLogType(log.TxLog, "[TX] %s trigger trx state change fail : %+v", tx, err)
}
}
}
Expand Down
Loading

0 comments on commit c95f464

Please sign in to comment.