diff options
author | Robin Jarry <robin@jarry.cc> | 2023-06-04 21:52:39 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-06-12 11:23:05 +0200 |
commit | 68e1809b3c602f2119505df78eea3d1d93854f83 (patch) | |
tree | ce878c8aaa2301a5c640a868f3244244d51e0353 /worker | |
parent | 531440f33610e8bdccaf31b916da990d144fa0ae (diff) | |
download | aerc-68e1809b3c602f2119505df78eea3d1d93854f83.tar.gz |
worker: use named logger
Add a named logger for each worker based on the account name.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'worker')
-rw-r--r-- | worker/types/worker.go | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/worker/types/worker.go b/worker/types/worker.go index b1927b90..c2fad1ba 100644 --- a/worker/types/worker.go +++ b/worker/types/worker.go @@ -21,6 +21,7 @@ type Worker struct { Backend Backend Actions chan WorkerMessage Name string + logger log.Logger actionCallbacks map[int64]func(msg WorkerMessage) messageCallbacks map[int64]func(msg WorkerMessage) @@ -37,6 +38,7 @@ func NewWorker(name string) *Worker { actionCallbacks: make(map[int64]func(msg WorkerMessage)), messageCallbacks: make(map[int64]func(msg WorkerMessage)), actionQueue: list.New(), + logger: log.NewLogger(name, 3), } } @@ -86,9 +88,9 @@ func (worker *Worker) PostAction(msg WorkerMessage, cb func(msg WorkerMessage)) worker.setId(msg) if resp := msg.InResponseTo(); resp != nil { - log.Tracef("(%s) PostAction %T:%T", worker.Name, msg, resp) + worker.Tracef("PostAction %T:%T", msg, resp) } else { - log.Tracef("(%s) PostAction %T", worker.Name, msg) + worker.Tracef("PostAction %T", msg) } // write to Actions channel without blocking worker.queue(msg) @@ -111,9 +113,9 @@ func (worker *Worker) PostMessage(msg WorkerMessage, msg.setAccount(worker.Name) if resp := msg.InResponseTo(); resp != nil { - log.Tracef("(%s) PostMessage %T:%T", worker.Name, msg, resp) + worker.Tracef("PostMessage %T:%T", msg, resp) } else { - log.Tracef("(%s) PostMessage %T", worker.Name, msg) + worker.Tracef("PostMessage %T", msg) } WorkerMessages <- msg @@ -126,9 +128,9 @@ func (worker *Worker) PostMessage(msg WorkerMessage, func (worker *Worker) ProcessMessage(msg WorkerMessage) WorkerMessage { if resp := msg.InResponseTo(); resp != nil { - log.Tracef("(%s) ProcessMessage %T(%d):%T(%d)", worker.Name, msg, msg.getId(), resp, resp.getId()) + worker.Tracef("ProcessMessage %T(%d):%T(%d)", msg, msg.getId(), resp, resp.getId()) } else { - log.Tracef("(%s) ProcessMessage %T(%d)", worker.Name, msg, msg.getId()) + worker.Tracef("ProcessMessage %T(%d)", msg, msg.getId()) } if inResponseTo := msg.InResponseTo(); inResponseTo != nil { worker.Lock() @@ -148,9 +150,9 @@ func (worker *Worker) ProcessMessage(msg WorkerMessage) WorkerMessage { func (worker *Worker) ProcessAction(msg WorkerMessage) WorkerMessage { if resp := msg.InResponseTo(); resp != nil { - log.Tracef("(%s) ProcessAction %T(%d):%T(%d)", worker.Name, msg, msg.getId(), resp, resp.getId()) + worker.Tracef("ProcessAction %T(%d):%T(%d)", msg, msg.getId(), resp, resp.getId()) } else { - log.Tracef("(%s) ProcessAction %T(%d)", worker.Name, msg, msg.getId()) + worker.Tracef("ProcessAction %T(%d)", msg, msg.getId()) } if inResponseTo := msg.InResponseTo(); inResponseTo != nil { worker.Lock() @@ -185,3 +187,23 @@ func (worker *Worker) PostMessageInfoError(msg WorkerMessage, uid uint32, err er func (worker *Worker) PathSeparator() string { return worker.Backend.PathSeparator() } + +func (worker *Worker) Tracef(message string, args ...interface{}) { + worker.logger.Tracef(message, args...) +} + +func (worker *Worker) Debugf(message string, args ...interface{}) { + worker.logger.Debugf(message, args...) +} + +func (worker *Worker) Infof(message string, args ...interface{}) { + worker.logger.Infof(message, args...) +} + +func (worker *Worker) Warnf(message string, args ...interface{}) { + worker.logger.Warnf(message, args...) +} + +func (worker *Worker) Errorf(message string, args ...interface{}) { + worker.logger.Errorf(message, args...) +} |