Skip to content

Commit

Permalink
feat: add ftltest package
Browse files Browse the repository at this point in the history
Initially with a function to return a Context with a valid FTL logger.
  • Loading branch information
alecthomas committed Feb 15, 2024
1 parent 65cb954 commit c9221b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 0 additions & 4 deletions FTL.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
"path": "examples/go/time",
"name": "examples/go/time"
},
{
"path": "examples/go/httpingress",
"name": "examples/go/httpingress"
},
{
"path": "examples/kotlin",
"name": "examples/kotlin"
Expand Down
14 changes: 14 additions & 0 deletions go-runtime/ftl/ftltest/ftltest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Package ftltest contains test utilities for the ftl package.
package ftltest

import (
"context"
"os"

"github.com/TBD54566975/ftl/backend/common/log"
)

// Context suitable for use in testing FTL verbs.
func Context() context.Context {
return log.ContextWithLogger(context.Background(), log.Configure(os.Stderr, log.Config{Level: log.Trace}))
}
10 changes: 10 additions & 0 deletions go-runtime/ftl/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import (
// attributes.
type Logger = log.Logger

// Log levels.
const (
Trace = log.Trace
Debug = log.Debug
Info = log.Info
Warn = log.Warn
Error = log.Error
Default = log.Default
)

// LoggerFromContext retrieves the current logger from the Context.
func LoggerFromContext(ctx context.Context) *Logger {
return log.FromContext(ctx)
Expand Down

0 comments on commit c9221b7

Please sign in to comment.