Hướng dẫn | Tạo nhật ký để gỡ lỗi một trang

nội dung

This tutorial demonstrates how to generate logs from site code. We will then view the generated logs using Wix Logs.

In this tutorial, we will:

  1. Add a button to a site's home page.
  2. Create an event handler that generates a log whenever the button is clicked.
  3. View the generated log using Wix Logs.

Note: In this tutorial, logs are generated from page code. However, you can also generate logs from backend code.

Add a button to your site and create an event handler:

  1. Add a button labeled button1 to your site's home page, like this:
![](https://wixmp-833713b177cebf373f611808.wixmp.com/images/949a3dd03f5f11dd9dc3211af1b2c85f.png)
  1. In the site's home page code, add an event handler that runs whenever the button is clicked.
For the purposes of this tutorial, let's produce an error by defining `factor3` instead of `factor2.`
  1. Preview or publish your site.
**Note:** You can generate logs when previewing your site, but some log information is available only when your site is published.

Generate a log and view it using Wix Logs as follows:

  1. In a separate browser tab or window, open the Wix Logs page.
![](https://wixmp-833713b177cebf373f611808.wixmp.com/images/6f82b8af9105b4198ffe5babf7d6114d.png)
  1. In your live site's home page or in Preview mode, click the button you created.
The logs appear in the Wix Logs page:
![](https://wixmp-833713b177cebf373f611808.wixmp.com/images/dbf2dc66af923e4d2c64564f8332de90.png)
  1. Click View for the log with the error to see its full details on the right:
![](https://wixmp-833713b177cebf373f611808.wixmp.com/images/123b0719f98d5699cf242c68c1813b02.png)
Check out the `jsonPayload` to see an explanation for the error.
Tóm tắt
Hướng dẫn này trình bày cách tạo nhật ký từ mã trang web và xem nhật ký đã tạo bằng Wix Logs. Các bước bao gồm: 1. Thêm một nút vào trang chính của trang web. 2. Tạo một trình xử lý sự kiện để tạo nhật ký mỗi khi nút được nhấn. 3. Xem nhật ký đã tạo bằng Wix Logs. Đầu tiên, người dùng cần thêm nút có nhãn 'button1' vào trang chính và định nghĩa một trình xử lý sự kiện để tạo lỗi. Sau đó, người dùng có thể xem nhật ký bằng cách mở trang Wix Logs trong một tab trình duyệt khác và nhấn nút đã tạo. Nhật ký sẽ hiển thị trên trang Wix Logs, nơi người dùng có thể nhấp vào 'View' để xem chi tiết lỗi và kiểm tra 'jsonPayload' để hiểu rõ hơn về lỗi đó.