Skip to main content

Logging

The Go SDK uses the standard library log/slog package for logging.

By default logs will go to the slog default handler. However, you may provide any slog handler upon creating the Restate server instance, which allows you to direct the logs to other log libraries:


myHandler := slog.NewJSONHandler(os.Stdout, nil)
server.NewRestate().
WithLogger(myHandler, true).
Bind(restate.Reflect(Monitoring{})).
Start(context.Background(), "0.0.0.0:9080")

Avoiding duplicate logging

If you use the default slog logger or another logger, log statements will be printed over and over again during replays. To avoid this, you can use the Restate context logger, which is a *slog.Logger that suppresses duplicate log statements during replays:


ctx.Log().Info("This will not be printed again during replays")
ctx.Log().Debug("This will not be printed again during replays")

When providing a custom log handler using WithLogger, you can provide false as the second argument, in which case logs will not be dropped during replay allowing you to handle them as you prefer. You can still determine whether they would have been dropped using rcontext.LogContextFrom on the context passed to your log handler.