Skip to content

Instantly share code, notes, and snippets.

@JJTech0130
Last active January 9, 2025 18:42
Show Gist options
  • Save JJTech0130/a87e1c96f93f2544069a1f2a6ce1080d to your computer and use it in GitHub Desktop.
Save JJTech0130/a87e1c96f93f2544069a1f2a6ce1080d to your computer and use it in GitHub Desktop.
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 fmt_console_log(strings, ...values) {
let str = '';
if (strings?.logString?.fragments != null) {
for (var fragment of strings?.logString?.fragments) {
str += fragment._unsafeValue;
}
} else {
strings.forEach((string, i) => {
if (values[i] !== undefined)
str += string + (values[i]._unsafeValue);
else
str += string;
});
}
console.log(str);
}
obj.error = fmt_console_log;
obj.warn = fmt_console_log;
obj.info = fmt_console_log;
obj.log = fmt_console_log;
obj.http = fmt_console_log;
obj.performance = fmt_console_log;
obj.verbose = fmt_console_log;
obj.debug = fmt_console_log;
obj.silly = fmt_console_log;
}
keys.forEach(function (key) {
var value = obj[key]; // get property value
// 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