Realtime log


In order to help Mini Program developers quickly troubleshoot Mini Program vulnerabilities and locate problems, we have introduced real-time logging. Starting with the base library 2.7.1, developers can print logs through the interface provided, which are aggregated and reported in real time to the Mini Program background. Developers can manage backend from Mini Program “Development ->Development Management ->Operations Center ->Realtime log” Go to the log query page to see the log information printed by the developer.

How to use

  1. Call the related interface. The interface for logging iswx.getRealtimeLogManagerTo be compatible with older versions, it is recommended to use the following code to encapsulate it, for example, inlog.jsInside the file:
where log = wx.getRealtimeLogManager  wx.getRealtimeLogManager() : null

module.exports = {
  info() {
    if (!log) return, arguments)
  warn() {
    if (!log) return
    log.warn.apply(log, arguments)
  error() {
    if (!log) return
    log.error.apply(log, arguments)
  setFilterMsg(MSG) { // Support starting with base library 2.7.3
    if (!log || !log.setFilterMsg) return
    if (typeof msg !== 'string') return
  addFilterMsg(MSG) { // Support starting with base library 2.8.1
    if (!log || !log.addFilterMsg) return
    if (typeof msg !== 'string') return
  1. Print the log at a specific location on the page:
where log = require('./log.js') // Reference to the log.js file above'hello test I'm not going to do that. // Log will be associated with the current open page, recommended in the page onHide, onShow and other lifecycle inside hit

The full example may refer to the code snippet:

How to view logs

Login Mini Program management background, from “Development ->Development Management ->Operations Center ->Realtime log” Go to the log query page. Developers can set the time, WeChat ID/OpenID, page links, FilterMsg content (base library 2.7.3 and above supports setFilter Msg) and other filter conditions query log information for specified users.



Due to background resource limitations, the Live Log usage rules are as follows:

  1. In order to locate the problem conveniently, the log is divided by page, a page, in the onShow to onHide (switch to other pages, the top right corner dot back) between the log, will be aggregated intoA log.Reported, and the Mini Program management background can be based on the page path search outThe log
  2. Each Mini Program account limit 10000000 logs per day, log will be retained for 7 days, it is recommended to locate problems in time.
  3. **A log.**Is capped at 5KB and contains up to 200 print-log function calls (info, warn, error calls count), So be careful to log, avoid calling the log interface inside the loop, avoid overwriting console.log directly.
  4. Feedback inside the log, according to OpenID search log.
  5. setFilterMsg和addFilterMsg You can set a filter field like log tag. To add more than one keyword, it is recommended to use addFilterMsg. For example addFilterMsg('scene1'), addFilterMsg('scene2'),addFilterMsg('Scene3 '), set up in the background of Mini Program management can be randomly combined three keywords for retrieval, such as: “scene1 scene2 scene3”、“scene1 scene2”、 “scene1 scene3” or "scene2," etc (separated by spaces, so addFilterMsg cannot take spaces). The log can be retrieved by several search methods above. The more search conditions, the more accurate.