use zitadel/logging

This commit is contained in:
Tim Möhlmann 2023-08-24 19:08:14 +03:00
parent f30f0d3ead
commit 6f8f5226d7
7 changed files with 48 additions and 138 deletions

View file

@ -4,9 +4,12 @@ import (
"fmt"
"log"
"net/http"
"os"
"github.com/zitadel/logging"
"github.com/zitadel/oidc/v3/example/server/exampleop"
"github.com/zitadel/oidc/v3/example/server/storage"
"golang.org/x/exp/slog"
)
func main() {
@ -20,14 +23,24 @@ func main() {
// in this example it will be handled in-memory
storage := storage.NewStorage(storage.NewUserStore(issuer))
router := exampleop.SetupServer(issuer, storage)
// Using our wrapped logging handler,
// data set to the context gets printed
// as part of the log output.
// This helps us tie log output to requests.
logger := slog.New(logging.WrapHandler(
slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
AddSource: true,
Level: slog.LevelDebug,
}),
logging.HandlerWithCTXGroupName("ctx"),
))
router := exampleop.SetupServer(issuer, storage, logger)
server := &http.Server{
Addr: ":" + port,
Handler: router,
}
log.Printf("server listening on http://localhost:%s/", port)
log.Println("press ctrl+c to stop")
logger.Info("server listening, press ctrl+c to stop", "addr", fmt.Sprintf("http://localhost:%s/", port))
err := server.ListenAndServe()
if err != nil {
log.Fatal(err)