Write Log Messages in Studio Two

Write log messages from your site's code to record what it does while it runs. Each message becomes an entry on the Logs page in the site dashboard, with a severity level and any extra data you attach.

Important: console.log() and the other console methods don't write to the Logs page in the site dashboard. Code that runs in the browser still prints console output to the browser's developer tools, but that output isn't saved as a log entry. To write log entries, use the monitoring client from @wix/essentials, as shown in this article.

You can write log entries from backend code, such as HTTP endpoints, event handlers, and service plugins, and from site extensions that run in the visitor's browser. Code in dashboard pages can't write log entries. For more about what gets logged, see About Logs in Studio Two.

Step 1 | Get the monitoring client

The monitoring client writes your log entries. Get it inside the function that runs your code. If you call getMonitoringClient() at the top level of a file, it throws Error: Wix context is not available. In backend code, Wix links each entry to the request that produced it.

To get the monitoring client:

  1. Import monitoring from @wix/essentials:

    Copy
  2. Inside your function, call getMonitoringClient():

    Copy

Step 2 | Write a log entry

Each call to the monitoring client writes one entry. Log a message to record what your code does, or log an error that your code caught.

Log a message

Call captureMessage() on the monitoring client with the text you want to log. To set the entry's severity, specify a level. Without a level, the entry is INFO.

Copy

Log a caught error

Call captureException() on the monitoring client with an error your code caught. The entry is ERROR by default. To set a different severity, specify a level. The entry's message is the error's name and message, such as Error: Payment failed. The entry doesn't include the error's stack trace.

Copy

When backend code throws an error that your code doesn't catch, Wix logs it as an ERROR entry automatically. Errors in code that runs in the browser aren't logged unless you catch them and call captureException().

Step 3 | (Optional) Attach tags and contexts

Attach data to an entry so you can tell entries apart when you read them. Both captureMessage() and captureException() accept these options:

  • tags: Flat key-value pairs with string, number, or boolean values, such as a feature name.
  • contexts: Named groups of related values, such as the details of an order.
Copy

Tags and contexts appear in the entry's details on the Logs page. Search on the Logs page doesn't match tags or contexts. For how they appear in an entry, see Log Entry Structure in Studio Two.

Caution: Don't log passwords, API keys, tokens, or visitors' personal data. Collaborators who can view your site's logs can read every entry, and forwarded entries leave Wix.

Step 4 | Check your log entries

To check your log entries:

  1. Run the code. To test backend code, preview your site or open the live site. To test code that runs in the browser, open the live site. Then do what makes your code run, such as opening the page that loads it or clicking a button that calls your HTTP endpoint.
  2. In the site dashboard, open Developer Tools > Logs.

Your entries appear in a few seconds. On the Logs page, you can filter entries by severity, search them, and open an entry's full details. For more information, see View Logs in Studio Two.

Example

To add an HTTP endpoint file and call it from a frontend extension, follow the steps in Add an HTTP Endpoint Extension in Studio Two.

The following HTTP endpoint logs each order it receives. If sending the order to a fulfillment service fails, it logs the error and responds with status 502:

Copy

See also

Last updated: 2 November 2026

Did this help?