# Real Time Log
# background
In order to help Mini Program developers quickly troubleshoot Mini Program vulnerabilities and locate problems, we have introduced a real-time log function. Developers can print the log through the provided interface, the log aggregation and real-time reporting to the Mini Program background. Developers can analyze from We “Performance Quality ->Real Time Log ->Mini Program Log "to the Mini Program side log query page, or from the" Performance Quality->Real Time Log ->Plugin Log”Go to the Plug-In Log Query page to view the log information printed by the developer.
# How to use
# Mini Program/Small Mini game End
From the base library2.7.1
At the beginning, the Mini Program side can use real-time logs, and the small game side can start from the base library.2.14.4
Start supporting.
1, call the relevant interface. The interface for logging iswx.getRealtimeLogManager
, for compatibility with older versions, it is recommended to use the following code encapsulation, for examplelog.js
Inside the file:
var log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null
module.exports = {
debug() {
if (!log) return
log.debug.apply(log, arguments)
},
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) { // Starting with Base Library 2.7.3 Support
if (!log || !log.setFilterMsg) return
if (typeof msg !== 'string') return
log.setFilterMsg(msg)
},
addFilterMsg(msg) { // Support from Base Library 2.8.1
if (!log || !log.addFilterMsg) return
if (typeof msg !== 'string') return
log.addFilterMsg(msg)
}
}
- Print the log at a specific location on the page:
var log = Require('./log.js') // Refer to the log.js file above
log.info('hello test hahaha') // Log will be associated with the current open page, it is recommended to play in the life cycle of the page onHide, onShow, etc.
log.warn('warn')
log.error('error')
log.setFilterMsg('filterkeyword')
log.addFilterMsg('addfilterkeyword')
Complete examples can be found in code snippets:https://developers.weixin.qq.com/s/aFYw1BmC7eak
# Plug-in end
From the base library2.16.0
Started to support, the plug-in side also supports real-time logging. In order to make the logs more structured for more complex analysis later on, the plug-in side adopted a newly designed format.
1, call the relevant interface wx.getRealtimeLogManager
, Get Live Log Manager Instance:
const logManager = wx.getRealtimeLogManager()
2, in the logic that needs to hit the log, get the log instance:
// Tag names can be any character string, and one tag name corresponds to a set of logsThe same tag name is allowed to be reused, and logs with the same tag name are aggregated under one tag in the background.
// Tags classify logs, so developers are advised to label them logically
const logger = logManager.tag('plugin-onUserTapSth')
- Print the log in the right place:
logger.info('key1', 'value1') // Each log is one. key-value Right, key. Must be a character string, value It could be a character string./numerical value/object/Serializable types such as arrays
logger.error('key2', {str: 'value2'})
logger.warn('key3', 'value3')
logger.setFilterMsg ('filterkeyword') // And Small Programs/Small game interface is consistent
logger.setFilterMsg ('addfilterkeyword') // And Small Programs/Small game interface is consistent
# How to view logs
Login to We Analytics, from “Performance Quality ->Real Time Log”Go to the log query page. Developers can set the time, WeChat ID/Filters such as OpenID, page links, FilterMsg content (setFilterMsg is supported by base library 2.7.3 and above) query the log information of a specified user. If it is a live log reported by the plug-in, it can be downloaded from the “Mini Program plug-in ->Real Time Log”Go to the log query page to query.
# Note
Due to background resource limitations, the "live log" usage rules are as follows:
- In order to locate the problem easily, the log is divided by page, a page, in a certain period of time (the shortest is 5 seconds, the longest is the page from the display to hidden time interval) to play the log, will be aggregated intoA journalReport, and in the Mini Program management background can be based on the page path search outThis log。
- Each Mini Program account, we analyze the basic version of the daily limit of 5000 logs, we analyze the professional version of 50,000, and support the purchase of configuration upgrades or the purchase of additional reported expansion packages. The log is configured according to the version and will be retained for 7 days/14 days/30 days, it is recommended to locate the problem in time.
- A journalThe upper limit is 5KB, contains a maximum of 200 print log function calls (info, warn, error calls are counted), so be careful to play log, avoid the call inside the loop to play log interface, avoid direct rewrite console.log way to play log.
- See the log inside the feedback, you can search the log according to OpenID.
- setFilterMsg和addFilterMsg Filter fields like log tags can be set. If you need to add multiple closed keys, it is recommended to use addFilterMsg. For example addFilterMsg('scene1' ), addFilterMsg('Scene2' ),addFilterMsg('Scene3' ), set up in the Mini Program management background can be randomly combined with three keywords for retrieval, such as: “scene1 Scene 2 scene3”、“scene1 Scene 2", “scene1 Scene3 or "scene2," etc. (separated by spaces, so addFilterMsg cannot have spaces). The above retrieval methods can retrieve the log, the more retrieval conditions the more accurate.
- At present, in order to facilitate log analysis, the plug-in side real-time log only supports key-value Format.
- Live logs are currently only supported inMobile phoneTesting. The tool-side interface can be called, but it is not reported to the background.
- Development version, experience version of the real-time log, do not count into the relevant quota, that is, there is no upper limit.