Skip to content

Commit

Permalink
Remove logger keys
Browse files Browse the repository at this point in the history
  • Loading branch information
traut committed Jun 23, 2024
1 parent 39d6f93 commit 184cf4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
4 changes: 0 additions & 4 deletions cmd/render.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"context"
"fmt"
"log/slog"
"os"
Expand Down Expand Up @@ -51,9 +50,6 @@ var renderCmd = &cobra.Command{
ctx := cmd.Context()
logger := slog.Default()

ctx = context.WithValue(ctx, "logger", *logger)
ctx = context.WithValue(ctx, "document", target)

var diags diagnostics.Diag
eng := engine.New(
engine.WithLogger(logger),
Expand Down
30 changes: 6 additions & 24 deletions eval/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ type Document struct {
}

func (doc *Document) FetchData(ctx context.Context) (plugin.Data, diagnostics.Diag) {
var logger slog.Logger
loggerVal := ctx.Value("logger")
if loggerVal != nil {
logger = loggerVal.(slog.Logger)
} else {
logger = *slog.Default()
}
logger.DebugContext(ctx, "Fetching data for the document template", "document", ctx.Value("document"))
logger := *slog.Default()
logger.DebugContext(ctx, "Fetching data for the document template")
result := make(plugin.MapData)
diags := diagnostics.Diag{}
for _, block := range doc.DataBlocks {
Expand Down Expand Up @@ -58,14 +52,8 @@ func (doc *Document) FetchData(ctx context.Context) (plugin.Data, diagnostics.Di
}

func (doc *Document) RenderContent(ctx context.Context, docDataCtx plugin.MapData) (plugin.Content, plugin.Data, diagnostics.Diag) {
var logger slog.Logger
loggerVal := ctx.Value("logger")
if loggerVal != nil {
logger = loggerVal.(slog.Logger)
} else {
logger = *slog.Default()
}
logger.DebugContext(ctx, "Rendering content for the document template", "document", ctx.Value("document"))
logger := *slog.Default()
logger.DebugContext(ctx, "Fetching data for the document template")
data, diags := doc.FetchData(ctx)
if diags.HasErrors() {
return nil, nil, diags
Expand Down Expand Up @@ -123,14 +111,8 @@ func (doc *Document) RenderContent(ctx context.Context, docDataCtx plugin.MapDat
}

func (doc *Document) Publish(ctx context.Context, content plugin.Content, data plugin.Data) diagnostics.Diag {
var logger slog.Logger
loggerVal := ctx.Value("logger")
if loggerVal != nil {
logger = loggerVal.(slog.Logger)
} else {
logger = *slog.Default()
}
logger.DebugContext(ctx, "Publishing the document content", "document", ctx.Value("document"))
logger := *slog.Default()
logger.DebugContext(ctx, "Fetching data for the document template")
docData := plugin.MapData{
definitions.BlockKindContent: content.AsData(),
}
Expand Down

0 comments on commit 184cf4f

Please sign in to comment.