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.

Import

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

Assert

Asserts that a condition is true, and logs an error if it’s not.

func Assert(condition bool, message string)
condition
bool
required

The boolean condition to assert.

message
string
required

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.

func Log(message string)
message
string
required

A message you want to log.

Logf

Generate a message using Go format specifiers and logs the message, with no particular logging level.

func Logf(message string, args ...any)
message
string
required

A message you want to log.

args
...any

Arguments that correspond to the format specifiers in the message.

Debug

Generate a log message with the “debug” logging level.

func Debug(message string)
message
string
required

A debug message you want to log.

Debugf

Generate a message using Go format specifiers and logs the message with the “debug” logging level.

func Debugf(message string, args ...any)
message
string
required

A debug message you want to log.

args
...any

Arguments that correspond to the format specifiers in the message.

Info

Generate a log message with the “info” logging level.

func Info(message string)
message
string
required

An informational message you want to log.

Infof

Generate a message using Go format specifiers and logs the message with the “info” logging level.

func Infof(message string, args ...any)
message
string
required

An informational message you want to log.

args
...any

Arguments that correspond to the format specifiers in the message.

Warn

Generate a log message with the “warning” logging level.

func Warn(message string)
message
string
required

A warning message you want to log.

Warnf

Generate a message using Go format specifiers and logs the message with the “warning” logging level.

func Warnf(message string, args ...any)
message
string
required

A warning message you want to log.

args
...any

Arguments that correspond to the format specifiers in the message.

Error

Generate a log message with the “error” logging level.

func Error(message string)
message
string
required

An error message you want to log.

Errorf

Generate a message using Go format specifiers and logs the message with the “error” logging level.

func Errorf(message string, args ...any)
message
string
required

An error message you want to log.

args
...any

Arguments that correspond to the format specifiers in the message.

Timing Functions

Time

Starts a new timer using the specified label.

func Time(label ...string)
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)
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)
label
string

An optional label for the timer.