While each Modus SDK offers similar capabilities, the APIs and usage may vary between languages.Modus Console APIs documentation is available on the following pages:
The Modus Console APIs allow you to capture information from your functions,
such as errors and other information that can help you debug your functions.
In addition to the Console APIs, you can also use any standard Go function that
emits output to stdout
or stderr
. The output from these functions are
available in the runtime logs.For example, you may use:
fmt.Println
to write to informational messages to the logs
fmt.Fprintf(os.Stderr, ...)
to write error messages to the logs
You may also return error
objects from your function, whose messages get
captured and returned in the GraphQL response.
To begin, import the console
package from the SDK:
import "github.com/hypermodeinc/modus/sdk/go/pkg/console"
Console APIs
The APIs in the console
package are below, organized by category.
Weβre constantly introducing new APIs through ongoing development with early
users. Please open an issue if
you have ideas on what would make Modus even more powerful for your next app!
Assertion Functions
Asserts that a condition is true, and logs an error if itβs not.
func Assert(condition bool, message string)
The boolean condition to assert.
An error message to log, if the assertion is false.
Logging Functions
For Go, typically you use these logging APIs when you need detailed control of
the logging level, or when you need to log multi-line messages as a single log
entry. Otherwise, you can use the standard Go functions from the fmt
package
to emit messages to stdout
or stderr
.
Generate a log message, with no particular logging level.
A message you want to log.
Generate a message using Go format specifiers and logs the message, with no
particular logging level.
func Logf(message string, args ...any)
A message you want to log.
Arguments that correspond to the format specifiers in the message.
Generate a log message with the βdebugβ logging level.
func Debug(message string)
A debug message you want to log.
Generate a message using Go format specifiers and logs the message with the
βdebugβ logging level.
func Debugf(message string, args ...any)
A debug message you want to log.
Arguments that correspond to the format specifiers in the message.
Generate a log message with the βinfoβ logging level.
func Info(message string)
An informational message you want to log.
Generate a message using Go format specifiers and logs the message with the
βinfoβ logging level.
func Infof(message string, args ...any)
An informational message you want to log.
Arguments that correspond to the format specifiers in the message.
Generate a log message with the βwarningβ logging level.
func Warn(message string)
A warning message you want to log.
Generate a message using Go format specifiers and logs the message with the
βwarningβ logging level.
func Warnf(message string, args ...any)
A warning message you want to log.
Arguments that correspond to the format specifiers in the message.
Generate a log message with the βerrorβ logging level.
func Error(message string)
An error message you want to log.
Generate a message using Go format specifiers and logs the message with the
βerrorβ logging level.
func Errorf(message string, args ...any)
An error message you want to log.
Arguments that correspond to the format specifiers in the message.
Timing Functions
Starts a new timer using the specified label.
func Time(label ...string)
An optional label for the timer.
TimeLog
Logs the current value of a timer previously started with console.Time
.
func TimeLog(label string)
An optional label for the timer.
TimeEnd
Logs the current value of a timer previously started with console.Time
, and
discards the timer.
func TimeEnd(label string)
An optional label for the timer.