mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
merge message formater for logger
This commit is contained in:
+6
-13
@@ -24,9 +24,11 @@
|
||||
****************************************************************************/
|
||||
|
||||
// for cc.DebugMode.INFO_FOR_WEB_PAGE
|
||||
var logList;
|
||||
|
||||
var Enum = require('./cocos2d/core/platform/CCEnum');
|
||||
var getTypedFormatter = require('./DebugInfos').getTypedFormatter;
|
||||
|
||||
var logList;
|
||||
|
||||
/**
|
||||
* !#en Enum for debug modes.
|
||||
@@ -330,17 +332,8 @@ cc._throw = CC_EDITOR ? Editor.error : function (error) {
|
||||
};
|
||||
|
||||
function genLogFunc(func, type) {
|
||||
return function (id) {
|
||||
'use strict';
|
||||
var msg = cc._LogInfos.raw(id, type);
|
||||
if (arguments.length === 1) {
|
||||
func(msg);
|
||||
}
|
||||
else if (arguments.length === 2) {
|
||||
func(CC_DEBUG ? cc.js.formatStr(msg, arguments[1]) : msg + ' Arguments: ' + arguments[1]);
|
||||
}
|
||||
else {
|
||||
func(cc._LogInfos.format(msg, cc.js.shiftArguments.apply(null, arguments)));
|
||||
}
|
||||
var formatter = getTypedFormatter(type);
|
||||
return function () {
|
||||
func(formatter.apply(null, arguments));
|
||||
};
|
||||
}
|
||||
|
||||
+22
-26
@@ -1,5 +1,7 @@
|
||||
var logs;
|
||||
|
||||
if (CC_DEBUG) {
|
||||
var logs = {
|
||||
logs = {
|
||||
// Common
|
||||
"0100": "%s not yet implemented.",
|
||||
//ActionManager: 1000
|
||||
@@ -698,38 +700,32 @@ if (CC_DEBUG) {
|
||||
// AudioEngine: 8400
|
||||
"8400": "Wrong type arguments, 'filePath' must be a String.", // cc.audioEngine.play
|
||||
};
|
||||
cc._LogInfos = logs;
|
||||
}
|
||||
else {
|
||||
logs = {};
|
||||
}
|
||||
|
||||
var errorMapUrl = 'https://github.com/cocos-creator/engine/blob/master/EngineErrorMap.md';
|
||||
const ERROR_MAP_URL = 'https://github.com/cocos-creator/engine/blob/master/EngineErrorMap.md';
|
||||
|
||||
function raw (id, type) {
|
||||
return CC_DEBUG ? cc._LogInfos[id] : `${type} ${id}, please go to ${errorMapUrl}#${id} to see details.`;
|
||||
}
|
||||
|
||||
function format (msg, argsArray) {
|
||||
return CC_DEBUG ? cc.js.formatStr.apply(null, [msg].concat(argsArray)) : msg + ' Arguments: ' + argsArray.join(', ');
|
||||
}
|
||||
|
||||
cc._LogInfos.e = function () {
|
||||
var msg = raw(arguments[0], 'ERROR');
|
||||
function getTypedFormatter (type) {
|
||||
return function () {
|
||||
var id = arguments[0];
|
||||
var msg = CC_DEBUG ? (logs[id] || 'unknown id') : `${type} ${id}, please go to ${ERROR_MAP_URL}#${id} to see details.`;
|
||||
if (arguments.length === 1) {
|
||||
return msg;
|
||||
}
|
||||
else if (arguments.length === 2) {
|
||||
return CC_DEBUG ? cc.js.formatStr(msg, arguments[1]) :
|
||||
msg + ' Arguments: ' + arguments[1];
|
||||
}
|
||||
else {
|
||||
return format(msg, cc.js.shiftArguments.apply(null, arguments));
|
||||
var argsArray = cc.js.shiftArguments.apply(null, arguments);
|
||||
return CC_DEBUG ? cc.js.formatStr.apply(null, [msg].concat(argsArray)) :
|
||||
msg + ' Arguments: ' + argsArray.join(', ');
|
||||
}
|
||||
};
|
||||
cc._LogInfos.raw = raw;
|
||||
cc._LogInfos.format = format;
|
||||
}
|
||||
|
||||
// module.exports = false;
|
||||
|
||||
// // Only Node.JS has a process variable that is of [[Class]] process
|
||||
// try {
|
||||
// module.exports = Object.prototype.toString.call(global.process) === '[object process]';
|
||||
// module.exports = logs;
|
||||
// } catch (e) {
|
||||
|
||||
// cc._LogInfos = logs;
|
||||
// }
|
||||
logs.e = getTypedFormatter('ERROR');
|
||||
logs.getTypedFormatter = getTypedFormatter;
|
||||
module.exports = cc._LogInfos = logs;
|
||||
|
||||
@@ -156,11 +156,9 @@ if (CC_DEV) {
|
||||
}
|
||||
|
||||
// output all info before initialized
|
||||
require('./DebugInfos');
|
||||
require('./CCDebugger');
|
||||
cc._initDebugSetting(cc.DebugMode.INFO);
|
||||
if (CC_DEBUG) {
|
||||
require('./DebugInfos');
|
||||
}
|
||||
|
||||
// polyfills
|
||||
/* require('./polyfill/bind'); */
|
||||
|
||||
+1
-5
@@ -76,13 +76,9 @@ require('../cocos2d/core/utils/find');
|
||||
require('../cocos2d/core/utils/mutable-forward-iterator');
|
||||
require('../cocos2d/core/event');
|
||||
require('../cocos2d/core/event-manager/CCEvent');
|
||||
require('../DebugInfos');
|
||||
require('../CCDebugger');
|
||||
|
||||
if (CC_DEBUG) {
|
||||
//Debug Info ID map
|
||||
require('../DebugInfos');
|
||||
}
|
||||
|
||||
// Mark memory model
|
||||
var macro = require('../cocos2d/core/platform/CCMacro');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user