提交 c1e7452a 编写于 作者: Q qiang

Merge branch 'dev' into alpha

function typof (v) { function typof (v) {
var s = Object.prototype.toString.call(v) var s = Object.prototype.toString.call(v)
return s.substring(8, s.length - 1) return s.substring(8, s.length - 1)
} }
function isDebugMode () { function isDebugMode () {
/* eslint-disable no-undef */ /* eslint-disable no-undef */
return typeof __channelId__ === 'string' && __channelId__ return typeof __channelId__ === 'string' && __channelId__
} }
export default function formatLog () { export function log (type) {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key] = arguments[_key] args[_key - 1] = arguments[_key]
} }
var type = args.shift() console[type].apply(console, args)
}
export default function formatLog () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key]
}
var type = args.shift()
if (isDebugMode()) { if (isDebugMode()) {
args.push(args.pop().replace('at ', 'uni-app:///')) args.push(args.pop().replace('at ', 'uni-app:///'))
return console[type]['apply'](console, args) return console[type]['apply'](console, args)
} }
var msgs = args.map(function (v) { var msgs = args.map(function (v) {
var type = Object.prototype.toString.call(v).toLowerCase() var type = Object.prototype.toString.call(v).toLowerCase()
if (type === '[object object]' || type === '[object array]') { if (type === '[object object]' || type === '[object array]') {
try { try {
v = '---BEGIN:JSON---' + JSON.stringify(v) + '---END:JSON---' v = '---BEGIN:JSON---' + JSON.stringify(v) + '---END:JSON---'
} catch (e) { } catch (e) {
v = '[object object]' v = '[object object]'
} }
} else { } else {
if (v === null) { if (v === null) {
v = '---NULL---' v = '---NULL---'
} else if (v === undefined) { } else if (v === undefined) {
v = '---UNDEFINED---' v = '---UNDEFINED---'
} else { } else {
var vType = typof(v).toUpperCase() var vType = typof(v).toUpperCase()
if (vType === 'NUMBER' || vType === 'BOOLEAN') { if (vType === 'NUMBER' || vType === 'BOOLEAN') {
v = '---BEGIN:' + vType + '---' + v + '---END:' + vType + '---' v = '---BEGIN:' + vType + '---' + v + '---END:' + vType + '---'
} else { } else {
v = String(v) v = String(v)
} }
} }
} }
return v return v
}) })
var msg = '' var msg = ''
if (msgs.length > 1) { if (msgs.length > 1) {
var lastMsg = msgs.pop() var lastMsg = msgs.pop()
msg = msgs.join('---COMMA---') msg = msgs.join('---COMMA---')
if (lastMsg.indexOf(' at ') === 0) { if (lastMsg.indexOf(' at ') === 0) {
msg += lastMsg msg += lastMsg
} else { } else {
msg += '---COMMA---' + lastMsg msg += '---COMMA---' + lastMsg
} }
} else { } else {
msg = msgs[0] msg = msgs[0]
} }
console[type](msg) console[type](msg)
} }
...@@ -34,7 +34,7 @@ const uniCloudPath = path.resolve(__dirname, '../../packages/uni-cloud/dist/inde ...@@ -34,7 +34,7 @@ const uniCloudPath = path.resolve(__dirname, '../../packages/uni-cloud/dist/inde
function getProvides () { function getProvides () {
return { return {
'__f__': [path.resolve(__dirname, '../format-log.js'), 'default'], '__f__': [path.resolve(__dirname, '../format-log.js'), 'log'],
'uniCloud': [uniCloudPath, 'default'], 'uniCloud': [uniCloudPath, 'default'],
'wx.nextTick': [runtimePath, 'nextTick'], 'wx.nextTick': [runtimePath, 'nextTick'],
'Page': [runtimePath, 'Page'], 'Page': [runtimePath, 'Page'],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册