-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66fc99c
commit 5d0ab45
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module actorlogging | ||
|
||
go 1.21 | ||
|
||
replace github.com/asynkron/protoactor-go => ../.. | ||
|
||
require ( | ||
github.com/asynkron/goconsole v0.0.0-20160504192649-bfa12eebf716 | ||
github.com/asynkron/protoactor-go v0.0.0-00010101000000-000000000000 | ||
) | ||
|
||
require ( | ||
github.com/Workiva/go-datastructures v1.1.1 // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
github.com/emirpasic/gods v1.18.1 // indirect | ||
github.com/go-logr/logr v1.2.4 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/lithammer/shortuuid/v4 v4.0.0 // indirect | ||
github.com/lmittmann/tint v1.0.3 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect | ||
github.com/orcaman/concurrent-map v1.0.0 // indirect | ||
github.com/prometheus/client_golang v1.16.0 // indirect | ||
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/twmb/murmur3 v1.1.6 // indirect | ||
go.opentelemetry.io/otel v1.16.0 // indirect | ||
go.opentelemetry.io/otel/exporters/prometheus v0.39.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.16.0 // indirect | ||
go.opentelemetry.io/otel/sdk v1.16.0 // indirect | ||
go.opentelemetry.io/otel/sdk/metric v0.39.0 // indirect | ||
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/sys v0.12.0 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
console "github.com/asynkron/goconsole" | ||
"github.com/asynkron/protoactor-go/actor" | ||
"github.com/lmittmann/tint" | ||
"log/slog" | ||
"os" | ||
"time" | ||
) | ||
|
||
type ( | ||
hello struct{ Who string } | ||
helloActor struct{} | ||
) | ||
|
||
func (state *helloActor) Receive(context actor.Context) { | ||
switch msg := context.Message().(type) { | ||
case *hello: | ||
context.Logger().Info("Hello ", slog.String("who", msg.Who)) | ||
} | ||
} | ||
|
||
func jsonLogging(system *actor.ActorSystem) *slog.Logger { | ||
return slog.New(slog.NewJSONHandler(os.Stdout, nil)). | ||
With("lib", "Proto.Actor"). | ||
With("system", system.ID) | ||
} | ||
|
||
func consoleLogging(system *actor.ActorSystem) *slog.Logger { | ||
return slog.Default(). | ||
With("lib", "Proto.Actor"). | ||
With("system", system.ID) | ||
} | ||
|
||
func coloredConsoleLogging(system *actor.ActorSystem) *slog.Logger { | ||
return slog.New(tint.NewHandler(os.Stdout, &tint.Options{ | ||
Level: slog.LevelDebug, | ||
TimeFormat: time.Kitchen, | ||
})).With("lib", "Proto.Actor"). | ||
With("system", system.ID) | ||
} | ||
|
||
func main() { | ||
|
||
system := actor.NewActorSystem(actor.WithLoggerFactory(jsonLogging)) | ||
|
||
props := actor.PropsFromProducer(func() actor.Actor { return &helloActor{} }) | ||
|
||
pid := system.Root.Spawn(props) | ||
system.Root.Send(pid, &hello{Who: "Roger"}) | ||
_, _ = console.ReadLine() | ||
} |