Console APIs
Capture errors and debugging information in your functions
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:
- AssemblyScript Console APIs
- Go Console APIs (this page)
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 logsfmt.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.
Import
To begin, import the console
package from the SDK:
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
Assert
Asserts that a condition is true, and logs an error if it’s not.
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
.
Log
Generate a log message, with no particular logging level.
A message you want to log.
Logf
Generate a message using Go format specifiers and logs the message, with no particular logging level.
A message you want to log.
Arguments that correspond to the format specifiers in the message.
Debug
Generate a log message with the “debug” logging level.
A debug message you want to log.
Debugf
Generate a message using Go format specifiers and logs the message with the “debug” logging level.
A debug message you want to log.
Arguments that correspond to the format specifiers in the message.
Info
Generate a log message with the “info” logging level.
An informational message you want to log.
Infof
Generate a message using Go format specifiers and logs the message with the “info” logging level.
An informational message you want to log.
Arguments that correspond to the format specifiers in the message.
Warn
Generate a log message with the “warning” logging level.
A warning message you want to log.
Warnf
Generate a message using Go format specifiers and logs the message with the “warning” logging level.
A warning message you want to log.
Arguments that correspond to the format specifiers in the message.
Error
Generate a log message with the “error” logging level.
An error message you want to log.
Errorf
Generate a message using Go format specifiers and logs the message with the “error” logging level.
An error message you want to log.
Arguments that correspond to the format specifiers in the message.
Timing Functions
Time
Starts a new timer using the specified label.
An optional label for the timer.
TimeLog
Logs the current value of a timer previously started with console.Time
.
An optional label for the timer.
TimeEnd
Logs the current value of a timer previously started with console.Time
, and
discards the timer.
An optional label for the timer.
Was this page helpful?