diff --git a/packages/vue-cli-plugin-uni/lib/format-log.js b/packages/vue-cli-plugin-uni/lib/format-log.js index fb6017e8e945b8617b0dfa2ab4f55676cbc06466..cc3c89bac6553f8eea96faba1d19064ce415e722 100644 --- a/packages/vue-cli-plugin-uni/lib/format-log.js +++ b/packages/vue-cli-plugin-uni/lib/format-log.js @@ -1,64 +1,71 @@ -function typof (v) { - var s = Object.prototype.toString.call(v) - return s.substring(8, s.length - 1) -} - +function typof (v) { + var s = Object.prototype.toString.call(v) + return s.substring(8, s.length - 1) +} + function isDebugMode () { - /* eslint-disable no-undef */ - return typeof __channelId__ === 'string' && __channelId__ -} - -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() + /* eslint-disable no-undef */ + return typeof __channelId__ === 'string' && __channelId__ +} + +export function log (type) { + for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key] + } + 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()) { - args.push(args.pop().replace('at ', 'uni-app:///')) - return console[type]['apply'](console, args) - } - - var msgs = args.map(function (v) { - var type = Object.prototype.toString.call(v).toLowerCase() - - if (type === '[object object]' || type === '[object array]') { - try { - v = '---BEGIN:JSON---' + JSON.stringify(v) + '---END:JSON---' - } catch (e) { - v = '[object object]' - } - } else { - if (v === null) { - v = '---NULL---' - } else if (v === undefined) { - v = '---UNDEFINED---' - } else { - var vType = typof(v).toUpperCase() - - if (vType === 'NUMBER' || vType === 'BOOLEAN') { - v = '---BEGIN:' + vType + '---' + v + '---END:' + vType + '---' - } else { - v = String(v) - } - } - } - - return v - }) - var msg = '' - - if (msgs.length > 1) { - var lastMsg = msgs.pop() - msg = msgs.join('---COMMA---') - - if (lastMsg.indexOf(' at ') === 0) { - msg += lastMsg - } else { - msg += '---COMMA---' + lastMsg - } - } else { - msg = msgs[0] - } - - console[type](msg) + args.push(args.pop().replace('at ', 'uni-app:///')) + return console[type]['apply'](console, args) + } + + var msgs = args.map(function (v) { + var type = Object.prototype.toString.call(v).toLowerCase() + + if (type === '[object object]' || type === '[object array]') { + try { + v = '---BEGIN:JSON---' + JSON.stringify(v) + '---END:JSON---' + } catch (e) { + v = '[object object]' + } + } else { + if (v === null) { + v = '---NULL---' + } else if (v === undefined) { + v = '---UNDEFINED---' + } else { + var vType = typof(v).toUpperCase() + + if (vType === 'NUMBER' || vType === 'BOOLEAN') { + v = '---BEGIN:' + vType + '---' + v + '---END:' + vType + '---' + } else { + v = String(v) + } + } + } + + return v + }) + var msg = '' + + if (msgs.length > 1) { + var lastMsg = msgs.pop() + msg = msgs.join('---COMMA---') + + if (lastMsg.indexOf(' at ') === 0) { + msg += lastMsg + } else { + msg += '---COMMA---' + lastMsg + } + } else { + msg = msgs[0] + } + + console[type](msg) } diff --git a/packages/vue-cli-plugin-uni/lib/h5/index.js b/packages/vue-cli-plugin-uni/lib/h5/index.js index 8015f8e1186df6162e30a34b6fce69630c009f33..eb32bab9a4d1176a343585e26a8d1c5061c60725 100644 --- a/packages/vue-cli-plugin-uni/lib/h5/index.js +++ b/packages/vue-cli-plugin-uni/lib/h5/index.js @@ -34,7 +34,7 @@ const uniCloudPath = path.resolve(__dirname, '../../packages/uni-cloud/dist/inde function getProvides () { return { - '__f__': [path.resolve(__dirname, '../format-log.js'), 'default'], + '__f__': [path.resolve(__dirname, '../format-log.js'), 'log'], 'uniCloud': [uniCloudPath, 'default'], 'wx.nextTick': [runtimePath, 'nextTick'], 'Page': [runtimePath, 'Page'],