github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/actor/middleware/logging.go (about)

     1  package middleware
     2  
     3  import (
     4  	"github.com/asynkron/protoactor-go/actor"
     5  	"log/slog"
     6  )
     7  
     8  // Logger is message middleware which logs messages before continuing to the next middleware.
     9  func Logger(next actor.ReceiverFunc) actor.ReceiverFunc {
    10  	fn := func(c actor.ReceiverContext, env *actor.MessageEnvelope) {
    11  		message := env.Message
    12  		c.Logger().Info("Actor got message", slog.Any("self", c.Self()), slog.Any("message", message))
    13  		next(c, env)
    14  	}
    15  
    16  	return fn
    17  }