From c9221b7b86f1fdb14cc7334984f8956d60f41439 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Thu, 15 Feb 2024 19:53:19 +1100 Subject: [PATCH] feat: add ftltest package Initially with a function to return a Context with a valid FTL logger. --- FTL.code-workspace | 4 ---- go-runtime/ftl/ftltest/ftltest.go | 14 ++++++++++++++ go-runtime/ftl/logging.go | 10 ++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 go-runtime/ftl/ftltest/ftltest.go diff --git a/FTL.code-workspace b/FTL.code-workspace index 948948d6a7..8761c384b1 100644 --- a/FTL.code-workspace +++ b/FTL.code-workspace @@ -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" diff --git a/go-runtime/ftl/ftltest/ftltest.go b/go-runtime/ftl/ftltest/ftltest.go new file mode 100644 index 0000000000..cdd48a6429 --- /dev/null +++ b/go-runtime/ftl/ftltest/ftltest.go @@ -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})) +} diff --git a/go-runtime/ftl/logging.go b/go-runtime/ftl/logging.go index e47730885b..6862acf081 100644 --- a/go-runtime/ftl/logging.go +++ b/go-runtime/ftl/logging.go @@ -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)