Mini Program Log

Mini Program Log

In order to help Dongguan mini program developers quickly troubleshoot mini program vulnerabilities and locate problems, we have launched a real-time log function. Starting from basic library 2.7.1, developers can print logs through the provided interface, and the logs are aggregated and reported to the mini program backend in real time. Developers can enter the log query page from the mini-program management background "Development->Operation and Maintenance Center->Real-time Log" to view the log information printed by the developer.

How to use

1. Call related interfaces. The logging interface is wx.getRealtimeLogManager. To be compatible with older versions, it is recommended to encapsulate it using the following code, for example, in the log.js file:

 var log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : nullmodule.exports = {
  info() {
    if (!log) return
    log.info.apply(log, arguments)
  },
  warn() {
    if (!log) return
    log.warn.apply(log, arguments)
  },
  error() {
    if (!log) return
    log.error.apply(log, arguments)
  },
  setFilterMsg(msg) { // Supported since base library 2.7.3 if (!log || !log.setFilterMsg) return
    if (typeof msg !== 'string') return
    log.setFilterMsg(msg)
  },
  addFilterMsg(msg) { // Supported since base library 2.8.1 if (!log || !log.addFilterMsg) return
    if (typeof msg !== 'string') return
    log.addFilterMsg(msg)
  }}

2. Print logs at specific locations on the page:

 var log = require('./log.js') // reference the log.js file above log.info('hello test hahaha') // 
The log will be associated with the currently opened page. It is recommended to log.warn('warn') in the life cycle of the page such as onHide and onShow.
log.error('error')log.setFilterMsg('filterkeyword')log.setFilterMsg('addfilterkeyword')

For a complete example, please refer to the code snippet: https://developers.weixin.qq.com/s/i42NbKmp76bJ

How to view logs

Log in to the mini program management backend and enter the log query page from "Development->Operation and Maintenance Center->Real-time Log". Developers can query the log information of a specified user by setting filtering conditions such as time, WeChat account/OpenID, page link, FilterMsg content (basic library 2.7.3 and above supports setFilterMsg).

Precautions

Due to background resource limitations, the usage rules of "real-time log" are as follows:

  1. In order to facilitate problem location, logs are divided by page. For a certain page, the logs generated between onShow and onHide (switching to other pages, clicking the dot in the upper right corner to exit to the background) will be aggregated into one log report, and the log can be searched for according to the page path in the mini program management background.
  2. Each Mini Program account is limited to 5 million logs per day, and the logs will be retained for 7 days. It is recommended to locate any problems in a timely manner.
  3. The upper limit of a log is 5KB, and it contains at most 200 log printing function calls (info, warn, and error calls are all counted). Therefore, you should be cautious when logging, avoid calling the logging interface in a loop, and avoid directly rewriting the console.log method to log.
  4. The logs in the feedback can be searched by OpenID.
  5. setFilterMsg can set the filtered Msg. The purpose of this interface is to provide filtering capabilities for a certain scene. For example, if you use setFilterMsg('scene1'), you can enter scene1 on the MP to query the log. For example, if there is a problem with a certain monitoring during the online process, you can filter the specific user logs in this scenario according to FilterMsg. FilterMsg supports only uppercase and lowercase letters. If you need to add multiple keywords, it is recommended to use addFilterMsg instead of setFilterMsg.

<<:  Douyin Operation: Strategies for maintaining a Douyin account and increasing followers!

>>:  Event promotion: How to add 70,000+ new users in 5 days?

Recommend

BOE launches 110-inch "4K giant screen" to display 1:1 real-life images

[September 9 news] Yesterday, a message came from ...

Why is your customer acquisition cost so high?

Growth is the most basic pursuit of marketers, an...

Want to walk from Car 8 to Car 9? Unless you stop the train...

Audit expert: Zhou Hongzhi Senior Experimentalist...

Zhihu product operation analysis

From a vertical knowledge community loved by prof...

How does user operation build user tags?

Building user tags is actually a very simple task...

Every bite you eat is responsible for your brain

After the various fatty acids in food enter the h...

Why do dogs sniff each other's butts when they meet?

This article was reviewed by Zhao Xumao, a young ...

Kirin Society novel becomes combat class (completed)

Qilinshe VIP paid project course "Novel into...

Xiaohongshu keyword ranking strategy!

|Directory| 1. Xiaohongshu search ranking 2. The ...

How can advertisers use Xiaohongshu KOL to promote Xiaohongshu?

Xiaohongshu is known as the "overseas shoppi...

Tips for Protocol-Oriented Programming (POP) in Swift

1. Entrustment Model 1. Usage process The most co...