How to turn-off Console logs?
Traditional browsers doesn't support console object. This is one way to turn off console logs for your web application.
How to switch off console object in Production?
Call this util method when Ext application is ready.
i,e inside init() or Launch() of Ext.app.Application class
Example:
init: function(app) {
handleConsoleFn(false, false);
}
/*
* Call once at begining to ensure your app can safely call console.log()
* and console.dir(),even on legacy browsers that don't support it.You may not get useful logging on those browsers,
* but at least you won't generate errors.
* @params alertFallback if 'true', all logs becomes alerts in Legacy browsers like IE, if necessary (keep 'false' in production)
* @params debugModeON if 'true', console object will be enabled, (keep 'false' in production)
*/
handleConsoleFn: function(alertFallback, debugModeON) {
var me = this;
if (typeof console === "undefined") {
console = {}; /* define it if object doesn't exist */
}
/* condition check for console.log object */
if (typeof console.log === "undefined") {
if (alertFallback) {
console.log = function(msg) {
alert("CONSOLE LOG:" + msg);
};
} else {
console.log = function() {};
}
} else {
/* case: debugModeON = true */
if (!debugModeON) {
console = console || {};
console.log = function() {};
}
}
/* condition check for console.dir object */
if (typeof console.dir === "undefined") {
if (alertFallback) {
/*Note: This could be improved like List all the object properties of console at one time.*/
console.dir = function(msg) {
alert("CONSOLE DIR:" + msg);
};
} else {
console.dir = function() {};
}
} else {
if (!debugModeON) {
console = console || {};
console.dir = function() {};
}
}
}
How to use Ext.Logger ?For development, We can customize Ext.Logger mechanism as below
/**
* Fancy Ext.Logger.warn(), error()
* By including this file we'll force override of the Ext.Logger.warn() behavior.
eg:
Ext.Logger.error(errMsg);
Ext.Logger.warn('Warning msg');
*/
Ext.define('Master.util.Log', {
singleton: true,
/**
* Logs color-coded console message; intended for development only
* to be used in betwee debug directives.
* @param {String} text to log
*/
warn: function(text) {
console.log('%cWARN: %s', 'background: #222; color: orange', text);
},
error: function(text) {
console.log('%cERROR: %s', 'background: #d9e6ee; color: red', text);
}
}, function() {
Ext.Logger.warn = Master.util.Log.warn;
Ext.Logger.error = Master.util.Log.error;
});
0nordluMlenda Brenda Anderson https://wakelet.com/wake/VWIctDd7q499iRFZMF3T4
ReplyDeletertherynmensio
trantorsupp_so Dana Jones Adobe Media Encoder
ReplyDeleteAutodesk Maya
WinZip
nyatilimna