Comparing version 3.2.2 to 3.3.0
[English](./CHANGELOG.md) | 简体中文 | ||
#### V3.3.0 (2019-02-02) | ||
- 【特效】新增自动合并相同日志的能力。频繁输出相同日志时不再会被刷屏。 | ||
- 【修复】修复格式化日志(如 `console.log('[foo]', 'bar')`)无法显示到 Log 面板的问题。 | ||
#### V3.2.2 (2019-01-17) | ||
@@ -4,0 +10,0 @@ |
English | [简体中文](./CHANGELOG_CN.md) | ||
#### V3.3.0 (2019-02-02) | ||
- [FEATURE] Add the ability to collapse the same log. | ||
- [FIX] Fix issue which formatted log (like `console.log('[foo]', 'bar')`) will not display in Log tab. | ||
#### V3.2.2 (2019-01-17) | ||
@@ -4,0 +10,0 @@ |
@@ -87,2 +87,12 @@ [English](./tutorial.md) | 简体中文 | ||
### 其他方法 | ||
支持以下 `console` 方法: | ||
```javascript | ||
console.time('foo'); // 启动名为 foo 的计时器 | ||
console.timeEnd('foo'); // 停止 foo 计时器并输出经过的时间 | ||
``` | ||
### Object/Array 结构化展示 | ||
@@ -122,3 +132,9 @@ | ||
若编写自定义 log 面板插件,亦可通过上述格式将 log 输出到自定义面板: | ||
```javascript | ||
console.log('[myplugin]', 'bar'); // 'myplugin' 为自定义面板插件的 id | ||
``` | ||
## 内置插件 | ||
@@ -125,0 +141,0 @@ |
@@ -90,2 +90,12 @@ English | [简体中文](./tutorial_CN.md) | ||
### Other methods | ||
Supported `console` methods: | ||
```javascript | ||
console.time('foo'); // start a timer named "foo" | ||
console.timeEnd('foo'); // stop "foo" timer and print the elapsed time | ||
``` | ||
### Formatted object / array | ||
@@ -92,0 +102,0 @@ |
{ | ||
"name": "vconsole", | ||
"version": "3.2.2", | ||
"version": "3.3.0", | ||
"description": "A lightweight, extendable front-end developer tool for mobile web page.", | ||
@@ -23,6 +23,6 @@ "homepage": "https://github.com/Tencent/vConsole", | ||
"@babel/core": "^7.2.2", | ||
"@babel/preset-env": "^7.2.3", | ||
"@babel/plugin-proposal-class-properties": "^7.2.3", | ||
"@babel/plugin-proposal-class-properties": "^7.3.0", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.2.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.2.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.3.1", | ||
"@babel/preset-env": "^7.3.1", | ||
"babel-loader": "^8.0.4", | ||
@@ -33,3 +33,3 @@ "babel-plugin-add-module-exports": "^1.0.0", | ||
"html-loader": "^0.5.5", | ||
"jsdom": "^13.1.0", | ||
"jsdom": "^13.2.0", | ||
"json-loader": "^0.5.7", | ||
@@ -40,3 +40,3 @@ "less": "^3.9.0", | ||
"style-loader": "^0.23.1", | ||
"webpack": "^4.28.4", | ||
"webpack": "^4.29.0", | ||
"webpack-cli": "^3.2.1" | ||
@@ -43,0 +43,0 @@ }, |
@@ -211,3 +211,7 @@ /* | ||
let statckInfo = (stack && error.stack.toString()) || ''; | ||
that.printLog({logType: 'error', logs: [msg, statckInfo], noOrigin: true}); | ||
that.printLog({ | ||
logType: 'error', | ||
logs: [msg, statckInfo], | ||
noOrigin: true | ||
}); | ||
if (tool.isFunction(that.windowOnError)) { | ||
@@ -228,3 +232,2 @@ that.windowOnError.call(window, message, source, lineNo, colNo, error); | ||
content: $.render(tplItemCode, {content: cmd, type: 'input'}), | ||
noMeta: true, | ||
style: '' | ||
@@ -294,3 +297,2 @@ }); | ||
content: $content, | ||
noMeta: true, | ||
style: '' | ||
@@ -297,0 +299,0 @@ }); |
@@ -24,7 +24,15 @@ /* | ||
const DEFAULT_MAX_LOG_NUMBER = 1000; | ||
const ADDED_LOG_TAB_ID = []; | ||
let preLog = { | ||
// _id: string | ||
// logType: string | ||
// logText: string | ||
}; | ||
class VConsoleLogTab extends VConsolePlugin { | ||
static AddedLogID = []; | ||
constructor(...args) { | ||
super(...args); | ||
ADDED_LOG_TAB_ID.push(this.id); | ||
@@ -165,2 +173,7 @@ this.tplTabbox = ''; // MUST be overwrite in child class | ||
this.console = {}; | ||
const idx = ADDED_LOG_TAB_ID.indexOf(this.id); | ||
if (idx > -1) { | ||
ADDED_LOG_TAB_ID.splice(idx, 1); | ||
} | ||
} | ||
@@ -261,3 +274,3 @@ | ||
logType: method, | ||
logs: args | ||
logs: args, | ||
}); | ||
@@ -290,2 +303,3 @@ }; | ||
this.logNumber = 0; | ||
preLog = {}; | ||
} | ||
@@ -306,3 +320,4 @@ | ||
* @protected | ||
* @param string tabName auto|default|system | ||
* @param string _id random unique id | ||
* @param string tabName default|system | ||
* @param string logType log|info|debug|error|warn | ||
@@ -312,6 +327,4 @@ * @param array logs `logs` or `content` can't be empty | ||
* @param boolean noOrigin | ||
* @param boolean noMeta | ||
* @param int date | ||
* @param string style | ||
* @param string meta | ||
*/ | ||
@@ -330,13 +343,27 @@ printLog(item) { | ||
let pattern = /^\[(\w+)\]$/i; | ||
let targetTabName = ''; | ||
let targetTabID = ''; | ||
let isInAddedTab = false; | ||
if (tool.isString(logs[0])) { | ||
let match = logs[0].match(pattern); | ||
if (match !== null && match.length > 0) { | ||
targetTabName = match[1].toLowerCase(); | ||
targetTabID = match[1].toLowerCase(); | ||
isInAddedTab = ADDED_LOG_TAB_ID.indexOf(targetTabID) > -1; | ||
} | ||
} | ||
if (targetTabName) { | ||
shouldBeHere = (targetTabName == this.id); | ||
} else if (this.allowUnformattedLog == false) { | ||
if (targetTabID === this.id) { | ||
// target tab is current tab | ||
shouldBeHere = true; | ||
} else if (isInAddedTab === true) { | ||
// target tab is not current tab, but in added tab list | ||
// so throw this log to other tab | ||
shouldBeHere = false; | ||
} else { | ||
// target tab is not in added tab list | ||
if (this.id === 'default') { | ||
// show this log in default tab | ||
shouldBeHere = true; | ||
} else { | ||
shouldBeHere = false; | ||
} | ||
} | ||
@@ -352,2 +379,7 @@ | ||
// add id | ||
if (!item._id) { | ||
item._id = '__vc_' + Math.random().toString(36).substring(2, 8); | ||
} | ||
// save log date | ||
@@ -365,3 +397,3 @@ if (!item.date) { | ||
// remove `[xxx]` format | ||
if (tool.isString(logs[0])) { | ||
if (tool.isString(logs[0]) && isInAddedTab) { | ||
logs[0] = logs[0].replace(pattern, ''); | ||
@@ -373,13 +405,72 @@ if (logs[0] === '') { | ||
// use date as meta | ||
if (!item.meta) { | ||
let date = tool.getDate(item.date); | ||
item.meta = date.hour + ':' + date.minute + ':' + date.second; | ||
// make for previous log | ||
const curLog = { | ||
_id: item._id, | ||
logType: item.logType, | ||
logText: [], | ||
hasContent: !!item.content, | ||
count: 1, | ||
}; | ||
for (let i = 0; i < logs.length; i++) { | ||
if (tool.isFunction(logs[i])) { | ||
curLog.logText.push(logs[i].toString()); | ||
} else if (tool.isObject(logs[i]) || tool.isArray(logs[i])) { | ||
curLog.logText.push(tool.JSONStringify(logs[i])); | ||
} else { | ||
curLog.logText.push(logs[i]); | ||
} | ||
} | ||
curLog.logText = curLog.logText.join(' '); | ||
// check repeat | ||
if (!curLog.hasContent && preLog.logType === curLog.logType && preLog.logText === curLog.logText) { | ||
this.printRepeatLog(); | ||
} else { | ||
this.printNewLog(item, logs); | ||
// save previous log | ||
preLog = curLog; | ||
} | ||
// scroll to bottom if it is in the bottom before | ||
if (this.isInBottom) { | ||
this.autoScrollToBottom(); | ||
} | ||
// print log to origin console | ||
if (!item.noOrigin) { | ||
this.printOriginLog(item); | ||
} | ||
} | ||
/** | ||
* | ||
* @protected | ||
*/ | ||
printRepeatLog() { | ||
const $item = $.one('#' + preLog._id); | ||
let $repeat = $.one('.vc-item-repeat', $item); | ||
if (!$repeat) { | ||
$repeat = document.createElement('i'); | ||
$repeat.className = 'vc-item-repeat'; | ||
$item.insertBefore($repeat, $item.lastChild); | ||
} | ||
if (!preLog.count) { | ||
// preLog.count = 1; | ||
} | ||
preLog.count++; | ||
$repeat.innerHTML = preLog.count; | ||
return; | ||
} | ||
/** | ||
* | ||
* @protected | ||
*/ | ||
printNewLog(item, logs) { | ||
// create line | ||
let $line = $.render(tplItem, { | ||
_id: item._id, | ||
logType: item.logType, | ||
noMeta: !!item.noMeta, | ||
meta: item.meta, | ||
style: item.style || '' | ||
@@ -428,12 +519,2 @@ }); | ||
this.limitMaxLogs(); | ||
// scroll to bottom if it is in the bottom before | ||
if (this.isInBottom) { | ||
this.autoScrollToBottom(); | ||
} | ||
// print log to origin console | ||
if (!item.noOrigin) { | ||
this.printOriginLog(item); | ||
} | ||
} | ||
@@ -440,0 +521,0 @@ |
@@ -16,3 +16,2 @@ /* | ||
import * as tool from '../lib/tool.js'; | ||
import VConsoleLogTab from './log.js'; | ||
@@ -19,0 +18,0 @@ import tplTabbox from './tabbox_system.html'; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
441960
3438