Table of Contents

Log analysis on WeChat Mini Programs

This article introduces the complete process of log collection and analysis in the AR environment of WeChat Mini Programs.

Using WeChat Mini Program vConsole

Since WeChat Mini Program AR can only run and debug on real devices, using vConsole to observe real-time output is crucial for debugging. Basic usage can be referred to in the WeChat Mini Program official documentation.

How to enable vConsole in real-device debugging

In the AR interface, click the first button in the upper-right corner > click Development debugging in the bottom toolbar > click Enable debugging > click OK in the pop-up window to restart the mini-program.

Enable debugging

Takes effect after reopening

After this, the vConsole floating button will remain visible on the interface.

vConsole button

Click the vConsole button to view all currently running logs:

Mini-program logs

How to distinguish log sources

Log sources can generally be divided into:

  • WeChat Mini Program system logs: Usually triggered during page route jumps or component lifecycle changes, displayed in blue text in vConsole.

  • xr-frame logs: Printed by the official rendering framework, with log content starting with [xr-frame].

  • User-defined logs: Printed by developers through standard interfaces like console.log().

  • Mini Program framework error logs: Thrown by the WeChat underlying system, with content starting with MiniProgramError.

  • Mega Mini Program plugin logs: Printed internally by the Mega Mini Program plugin, with log content starting with a class name wrapped in square brackets (e.g., [MegaTracker]), currently mainly output when exceptions are caught.

  • Example 1:

    Mini Program log example 1

    The first part in blue is the system log, showing the page route and loading status.

    The second part starts with [xr-frame], displaying the lifecycle information of the rendering framework.

    The third part is the developer's custom output.

  • Example 2:

    Mini Program log example 2

    Logs starting with class names like [MegaTracker] and [EasyARSession(xrframe)] appear, indicating that the Mega plugin caught runtime exceptions.

  • Example 3:

    Mini Program log example 3

    MiniProgramError contains WAXRFrameRenderContext.js, indicating an issue with the configuration or usage of xr-frame-related interfaces or components.

  • Example 4:

    Mini Program log example 4

    This log indicates that an exception occurred during the runtime of the onCloudLocalization method in the Mega plugin, causing the Mini Program framework to throw an error.

Log format of the Mega mini-program plugin

The log exported by the dumpLog(signal) method is separated by |, and the content is as follows:

  • Timestamp: ISO 8601 standard format, representing the system time when the log was printed.
  • Log level: Includes Info, Warning, Error, FatalError.
  • Class name: Enclosed in square brackets.
  • Details: Specific log description.
  • Caller: Usually Unspecified (indicating a natural running process); if it is an exception caused by a user calling an interface, it will be displayed as User.
  • Running phase: Displayed as Unspecified means it does not require attention; displaying other fields indicates that the exception occurred during a specific running phase.

Mini-program log

How to record and forward logs

Introduce the log acquisition and export solution.

Vconsole export logs

Click the copy button on the right side of the log printing location to export.

Mega mini-program plugin dump log interface

By calling the dumpLog(signal) interface, you can control the log export process:

  • Pass true: Start recording.
  • Pass false: Stop recording and return the generated temporary file path (tempFilePath).

It is generally recommended to bind the recording logic to a UI button. When starting the recording, use the wx.showToast() method to prompt the start of recording. When the recording ends, use the wx.shareFileMessage() method to forward the recorded file via WeChat chat.

/**
 * Handle session recording logic
 * @param signal true to start recording, false to stop recording and forward
 */
dumpLog(signal: boolean): void {
  // Call the interface to get the path
  const logPath = session.dumpLog(signal);
  // When signal is true, the interface returns an empty string, indicating recording is in progress
  if (logPath.length == 0) {
      wx.showToast({
          title: 'Start recording logs',
          icon: 'success',
          duration: 2000
      });
      return;
  }
  // When signal is false, process the returned file path
  wx.shareFileMessage({
      filePath: logPath,
      success() {
          wx.showToast({
              title: 'Log forwarded successfully',
              icon: 'success',
              duration: 2000
          });
      },
      fail() {
          wx.showToast({
              title: 'Log forwarding failed',
              icon: 'error',
              duration: 2000
          });
      }
  })
}

This example demonstrates how to use the session.dumpLog() method in the xr-frame component to record and forward log files, along with corresponding Toast prompts.


Important

If you encounter positioning or tracking-related issues rather than program exceptions when using Mega, be sure to provide the screen recording file and session dump file from that time in addition to the logs. Pure log files can only provide indirect reference, while screen recordings and dump data are the core basis for troubleshooting.