Skip to content

Commit

Permalink
zap adapter logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing committed Nov 20, 2023
1 parent 747328c commit 9122e54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions _examples/actor-logging/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ require (
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/samber/slog-common v0.11.0 // indirect
github.com/samber/slog-zap/v2 v2.1.0 // indirect
github.com/twmb/murmur3 v1.1.6 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.39.0 // indirect
Expand All @@ -35,6 +38,7 @@ require (
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.12.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
13 changes: 12 additions & 1 deletion _examples/actor-logging/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
console "github.com/asynkron/goconsole"
"github.com/asynkron/protoactor-go/actor"
"github.com/lmittmann/tint"
slogzap "github.com/samber/slog-zap/v2"
"go.uber.org/zap"
"log/slog"
"os"
"time"
Expand Down Expand Up @@ -41,9 +43,18 @@ func coloredConsoleLogging(system *actor.ActorSystem) *slog.Logger {
With("system", system.ID)
}

func zapAdapterLogging(system *actor.ActorSystem) *slog.Logger {
zapLogger, _ := zap.NewProduction()

logger := slog.New(slogzap.Option{Level: slog.LevelDebug, Logger: zapLogger}.NewZapHandler())
return logger.
With("lib", "Proto.Actor").
With("system", system.ID)
}

func main() {

system := actor.NewActorSystem(actor.WithLoggerFactory(jsonLogging))
system := actor.NewActorSystem(actor.WithLoggerFactory(zapAdapterLogging))

props := actor.PropsFromProducer(func() actor.Actor { return &helloActor{} })

Expand Down

0 comments on commit 9122e54

Please sign in to comment.