From 0574b7da544172d9346337bb36f92130360b5a24 Mon Sep 17 00:00:00 2001 From: Lorenzo Venerandi Date: Fri, 6 Dec 2024 12:55:15 +0100 Subject: [PATCH] switching to local logging (?) --- bindings.wadge.go | 2 +- go.mod | 3 --- go.sum | 6 ------ messaging.go | 7 +++---- wasmcloud.lock | 9 ++++++++ wit/deps/wasi-logging-0.1.0-draft/package.wit | 21 +++++++++++++++++++ wit/world.wit | 1 + 7 files changed, 35 insertions(+), 14 deletions(-) diff --git a/bindings.wadge.go b/bindings.wadge.go index 552814d..40541b6 100644 --- a/bindings.wadge.go +++ b/bindings.wadge.go @@ -17,7 +17,7 @@ const _ string = runtime.Compiler var _ unsafe.Pointer -//go:linkname wasmimport_Log go.wasmcloud.dev/component/gen/wasi/logging/logging.wasmimport_Log +//go:linkname wasmimport_Log gitea.rebus.ninja/lore/go-nats-client/gen/wasi/logging/logging.wasmimport_Log func wasmimport_Log(level0 uint32, context0 *uint8, context1 uint32, message0 *uint8, message1 uint32) { var __p runtime.Pinner defer __p.Unpin() diff --git a/go.mod b/go.mod index 9d24f2a..52811b5 100644 --- a/go.mod +++ b/go.mod @@ -14,14 +14,11 @@ require ( github.com/klauspost/compress v1.17.11 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/regclient/regclient v0.7.2 // indirect - github.com/samber/lo v1.47.0 // indirect - github.com/samber/slog-common v0.17.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/ulikunitz/xz v0.5.12 // indirect github.com/urfave/cli/v3 v3.0.0-alpha9.2 // indirect golang.org/x/mod v0.21.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.26.0 // indirect - golang.org/x/text v0.18.0 // indirect golang.org/x/tools v0.26.0 // indirect ) diff --git a/go.sum b/go.sum index a7d7b2d..132fb73 100644 --- a/go.sum +++ b/go.sum @@ -17,10 +17,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/regclient/regclient v0.7.2 h1:vcldDAwBMLtighYVMeb6qNt5+0hKg3AN2IkCc0JIJNM= github.com/regclient/regclient v0.7.2/go.mod h1:QlA7W9/pvmbblOXM4d49JgfuOTwVXcUMKt3bFuOSVIQ= -github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= -github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= -github.com/samber/slog-common v0.17.1 h1:jTqqLBgoJshpoxlPSGiypyOanjH6tY+i9bwyYmIbjhI= -github.com/samber/slog-common v0.17.1/go.mod h1:mZSJhinB4aqHziR0SKPqpVZjJ0JO35JfH+dDIWqaCBk= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= @@ -44,8 +40,6 @@ golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= -golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/messaging.go b/messaging.go index e9d28b9..4a18230 100644 --- a/messaging.go +++ b/messaging.go @@ -4,7 +4,7 @@ import ( "github.com/bytecodealliance/wasm-tools-go/cm" "gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/consumer" "gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types" - "go.wasmcloud.dev/component/log/wasilog" + logger "gitea.rebus.ninja/lore/go-nats-client/gen/wasi/logging/logging" ) type messagingConsumerAdapter struct { @@ -17,9 +17,8 @@ var messagingConsumer = &messagingConsumerAdapter{ } func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] { - logger := wasilog.ContextLogger("handleMessage") - logger.Info("Received message", "subject", msg.Subject) + logger.Log(logger.LevelInfo,"MessageHandler", "Received message on subject" + msg.Subject) reply := types.BrokerMessage{ Subject: msg.Subject + ".reply", @@ -28,7 +27,7 @@ func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] } res := messagingConsumer.Publish(reply) if res.IsErr() { - logger.Error("Failed to send reply", "error", *res.Err()) + logger.Log(logger.LevelError, "MessageHandler", "Failed to send reply, error: " + *res.Err()) return res } diff --git a/wasmcloud.lock b/wasmcloud.lock index 442ef1b..fcf8406 100644 --- a/wasmcloud.lock +++ b/wasmcloud.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 1 +[[packages]] +name = "wasi:logging" +registry = "wasi.dev" + +[[packages.versions]] +requirement = "=0.1.0-draft" +version = "0.1.0-draft" +digest = "sha256:09621a45b12b0a9cddc798517f778aac0e5ae4bd234077b3d70758d6cf625580" + [[packages]] name = "wasmcloud:component-go" registry = "wasmcloud.com" diff --git a/wit/deps/wasi-logging-0.1.0-draft/package.wit b/wit/deps/wasi-logging-0.1.0-draft/package.wit index 70349a7..164cb5b 100644 --- a/wit/deps/wasi-logging-0.1.0-draft/package.wit +++ b/wit/deps/wasi-logging-0.1.0-draft/package.wit @@ -1,15 +1,36 @@ package wasi:logging@0.1.0-draft; +/// WASI Logging is a logging API intended to let users emit log messages with +/// simple priority levels and context values. interface logging { + /// A log level, describing a kind of message. enum level { + /// Describes messages about the values of variables and the flow of + /// control within a program. trace, + /// Describes messages likely to be of interest to someone debugging a + /// program. debug, + /// Describes messages likely to be of interest to someone monitoring a + /// program. info, + /// Describes messages indicating hazardous situations. warn, + /// Describes messages indicating serious errors. error, + /// Describes messages indicating fatal errors. critical, } + /// Emit a log message. + /// + /// A log message has a `level` describing what kind of message is being + /// sent, a context, which is an uninterpreted string meant to help + /// consumers group similar messages, and a string containing the message + /// text. log: func(level: level, context: string, message: string); } +world imports { + import logging; +} diff --git a/wit/world.wit b/wit/world.wit index f1bcb6a..0162b1c 100644 --- a/wit/world.wit +++ b/wit/world.wit @@ -5,4 +5,5 @@ world hello { export wasmcloud:messaging/handler@0.2.0; import wasmcloud:messaging/consumer@0.2.0; + import wasi:logging/logging@0.1.0-draft; }