refactor: remove the use of logging module in most code

This commit is contained in:
yusing
2025-05-23 23:28:33 +08:00
parent 20a1649275
commit 63c4bdc73d
51 changed files with 194 additions and 203 deletions

View File

@@ -7,9 +7,9 @@ import (
"sync/atomic"
"time"
"github.com/rs/zerolog/log"
"github.com/yusing/go-proxy/internal/common"
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/logging"
"github.com/yusing/go-proxy/internal/utils/strutils"
)
@@ -116,14 +116,14 @@ func (t *Task) Finish(reason any) {
func (t *Task) finish(reason any) {
t.cancel(fmtCause(reason))
if !waitWithTimeout(t.childrenDone) {
logging.Debug().
log.Debug().
Str("task", t.name).
Strs("subtasks", t.listChildren()).
Msg("Timeout waiting for subtasks to finish")
}
go t.runCallbacks()
if !waitWithTimeout(t.callbacksDone) {
logging.Debug().
log.Debug().
Str("task", t.name).
Strs("callbacks", t.listCallbacks()).
Msg("Timeout waiting for callbacks to finish")
@@ -134,7 +134,7 @@ func (t *Task) finish(reason any) {
}
t.parent.subChildCount()
allTasks.Remove(t)
logging.Trace().Msg("task " + t.name + " finished")
log.Trace().Msg("task " + t.name + " finished")
}
// Subtask returns a new subtask with the given name, derived from the parent's context.
@@ -166,7 +166,7 @@ func (t *Task) Subtask(name string, needFinish ...bool) *Task {
}()
}
logging.Trace().Msg("task " + child.name + " started")
log.Trace().Msg("task " + child.name + " started")
return child
}
@@ -189,7 +189,7 @@ func (t *Task) MarshalText() ([]byte, error) {
func (t *Task) invokeWithRecover(fn func(), caller string) {
defer func() {
if err := recover(); err != nil {
logging.Error().
log.Error().
Interface("err", err).
Msg("panic in task " + t.name + "." + caller)
if common.IsDebug {

View File

@@ -9,7 +9,7 @@ import (
"syscall"
"time"
"github.com/yusing/go-proxy/internal/logging"
"github.com/rs/zerolog/log"
F "github.com/yusing/go-proxy/internal/utils/functional"
)
@@ -68,10 +68,10 @@ func GracefulShutdown(timeout time.Duration) (err error) {
case <-after:
b, err := json.Marshal(DebugTaskList())
if err != nil {
logging.Warn().Err(err).Msg("failed to marshal tasks")
log.Warn().Err(err).Msg("failed to marshal tasks")
return context.DeadlineExceeded
}
logging.Warn().RawJSON("tasks", b).Msgf("Timeout waiting for these %d tasks to finish", allTasks.Size())
log.Warn().RawJSON("tasks", b).Msgf("Timeout waiting for these %d tasks to finish", allTasks.Size())
return context.DeadlineExceeded
}
}
@@ -87,6 +87,6 @@ func WaitExit(shutdownTimeout int) {
<-sig
// gracefully shutdown
logging.Info().Msg("shutting down")
log.Info().Msg("shutting down")
_ = GracefulShutdown(time.Second * time.Duration(shutdownTimeout))
}