Created
November 7, 2023 02:23
-
-
Save JJTech0130/a87e1c96f93f2544069a1f2a6ce1080d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var objs = []; // we'll store the object references in this array | |
function walkTheObject( obj ) { | |
var keys = Object.keys( obj ); // get all own property names of the object | |
// Check if 'info' and 'error' keys are present (meaning it is probably the object we want) | |
if (keys.indexOf("info") > -1 && keys.indexOf("error") > -1) { | |
function test(strings, ...values) { | |
let str = ''; | |
strings.forEach((string, i) => { | |
if (values[i] !== undefined) | |
str += string + (values[i]._unsafeValue); | |
else | |
str += string; | |
//console.log(values[i]); | |
}); | |
//return str; | |
console.log(str); | |
} | |
// Replace all of the log handlers with ones that actually log to the console | |
// obj.error = function(t) { | |
// for (var a = [], s = 1; s < arguments.length; s++) | |
// a[s - 1] = arguments[s]; | |
// var c = e(n.log.apply(void 0, o([t], a)).level(i.LogLevel.Error)); | |
// return A.log(c), | |
// new r.LogError(c.logString) | |
// } | |
obj.error = test; | |
obj.warn = test; | |
obj.info = test; | |
obj.log = test; | |
//obj.log = function(n) { | |
// t && !t.shouldLoggerLogAtLevel(n.logLevel, this) || A.log(e(n)) | |
//}, | |
obj.http = test; | |
obj.performance = test; | |
obj.verbose = test; | |
obj.debug = test; | |
obj.silly = test; | |
} | |
keys.forEach( function ( key ) { | |
var value = obj[ key ]; // get property value | |
// if (key == "shouldLoggerLogAtLevel") { | |
// // Replace function to return true | |
// obj[key] = function () { | |
// console.log("feature"); | |
// return true; | |
// } | |
// } | |
// if (key == "info") { | |
// console.log("info"); | |
// // Replace to log arguments called with to console | |
// // Expand the arguments so that console.log prints them out | |
// obj[key] = function () { | |
// //console.log(arguments); | |
// // Parse the aruments into a string | |
// var args = Array.prototype.slice.call(arguments); | |
// var argsString = args.join(", "); | |
// console.log(argsString); | |
// } | |
// } | |
// if the property value is an object... | |
if ( value && typeof value === 'object' ) { | |
// if we don't have this reference... | |
if ( objs.indexOf( value ) < 0 ) { | |
objs.push( value ); // store the reference | |
walkTheObject( value); // traverse all its own properties | |
} | |
} | |
}); | |
} | |
walkTheObject( this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment