Files
wazero/internal/assemblyscript/logging/logging.go
Crypt Keeper 282ffc5ced logging: adds memory scope (#1076)
This allows you to specify the memory scope amongst existing logging scopes, both in API and the CLI.

e.g for the CLI.
```bash
$ wazero run --hostlogging=memory,filesystem --mount=.:/:ro cat.wasm
```

e.g. for Go
```go
loggingCtx := context.WithValue(testCtx, experimental.FunctionListenerFactoryKey{},
	logging.NewHostLoggingListenerFactory(&log, logging.LogScopeMemory|logging.LogScopeFilesystem))
```

This is helpful for emscripten and gojs which have memory reset
callbacks. This will be much more interesting once #1075 is implemented.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-29 10:58:59 +02:00

33 lines
767 B
Go

package logging
import (
"github.com/tetratelabs/wazero/api"
. "github.com/tetratelabs/wazero/internal/assemblyscript"
"github.com/tetratelabs/wazero/internal/logging"
)
func isExitFunction(fnd api.FunctionDefinition) bool {
return fnd.ExportNames()[0] == AbortName
}
func isRandomFunction(fnd api.FunctionDefinition) bool {
return fnd.ExportNames()[0] == SeedName
}
// IsInLogScope returns true if the current function is in any of the scopes.
func IsInLogScope(fnd api.FunctionDefinition, scopes logging.LogScopes) bool {
if scopes.IsEnabled(logging.LogScopeExit) {
if isExitFunction(fnd) {
return true
}
}
if scopes.IsEnabled(logging.LogScopeRandom) {
if isRandomFunction(fnd) {
return true
}
}
return scopes == logging.LogScopeAll
}