switching to local logging (?)

This commit is contained in:
Lorenzo Venerandi 2024-12-06 12:55:15 +01:00
parent 5746ad66eb
commit 0574b7da54
7 changed files with 35 additions and 14 deletions

View File

@ -17,7 +17,7 @@ const _ string = runtime.Compiler
var _ unsafe.Pointer 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) { func wasmimport_Log(level0 uint32, context0 *uint8, context1 uint32, message0 *uint8, message1 uint32) {
var __p runtime.Pinner var __p runtime.Pinner
defer __p.Unpin() defer __p.Unpin()

3
go.mod
View File

@ -14,14 +14,11 @@ require (
github.com/klauspost/compress v1.17.11 // indirect github.com/klauspost/compress v1.17.11 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/regclient/regclient v0.7.2 // 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/sirupsen/logrus v1.9.3 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect github.com/ulikunitz/xz v0.5.12 // indirect
github.com/urfave/cli/v3 v3.0.0-alpha9.2 // indirect github.com/urfave/cli/v3 v3.0.0-alpha9.2 // indirect
golang.org/x/mod v0.21.0 // indirect golang.org/x/mod v0.21.0 // indirect
golang.org/x/sync v0.8.0 // indirect golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.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 golang.org/x/tools v0.26.0 // indirect
) )

6
go.sum
View File

@ -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/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 h1:vcldDAwBMLtighYVMeb6qNt5+0hKg3AN2IkCc0JIJNM=
github.com/regclient/regclient v0.7.2/go.mod h1:QlA7W9/pvmbblOXM4d49JgfuOTwVXcUMKt3bFuOSVIQ= 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 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= 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.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 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= 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= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -4,7 +4,7 @@ import (
"github.com/bytecodealliance/wasm-tools-go/cm" "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/consumer"
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types" "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 { type messagingConsumerAdapter struct {
@ -17,9 +17,8 @@ var messagingConsumer = &messagingConsumerAdapter{
} }
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] { 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{ reply := types.BrokerMessage{
Subject: msg.Subject + ".reply", Subject: msg.Subject + ".reply",
@ -28,7 +27,7 @@ func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string]
} }
res := messagingConsumer.Publish(reply) res := messagingConsumer.Publish(reply)
if res.IsErr() { 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 return res
} }

View File

@ -2,6 +2,15 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 1 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]] [[packages]]
name = "wasmcloud:component-go" name = "wasmcloud:component-go"
registry = "wasmcloud.com" registry = "wasmcloud.com"

View File

@ -1,15 +1,36 @@
package wasi:logging@0.1.0-draft; 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 { interface logging {
/// A log level, describing a kind of message.
enum level { enum level {
/// Describes messages about the values of variables and the flow of
/// control within a program.
trace, trace,
/// Describes messages likely to be of interest to someone debugging a
/// program.
debug, debug,
/// Describes messages likely to be of interest to someone monitoring a
/// program.
info, info,
/// Describes messages indicating hazardous situations.
warn, warn,
/// Describes messages indicating serious errors.
error, error,
/// Describes messages indicating fatal errors.
critical, 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); log: func(level: level, context: string, message: string);
} }
world imports {
import logging;
}

View File

@ -5,4 +5,5 @@ world hello {
export wasmcloud:messaging/handler@0.2.0; export wasmcloud:messaging/handler@0.2.0;
import wasmcloud:messaging/consumer@0.2.0; import wasmcloud:messaging/consumer@0.2.0;
import wasi:logging/logging@0.1.0-draft;
} }