Palzin Track
Get 15% off with code PTRACKSIGNUP15 

Laravel Diary Logo

How to hook Google Console

tooling
Table of Contents

Logs

console.defaultLog = console.log.bind(console);
console.logs = [];
console.log = function(){
    // default &  console.log()
    console.defaultLog.apply(console, arguments);
    // new & array data
    console.logs.push(Array.from(arguments));
}

Error

console.defaultError = console.error.bind(console);
console.errors = [];
console.error = function(){
    // default &  console.error()
    console.defaultError.apply(console, arguments);
    // new & array data
    console.errors.push(Array.from(arguments));
}

Warn

console.defaultWarn = console.warn.bind(console);
console.warns = [];
console.warn = function(){
    // default &  console.warn()
    console.defaultWarn.apply(console, arguments);
    // new & array data
    console.warns.push(Array.from(arguments));
}

Debug

console.defaultDebug = console.debug.bind(console);
console.debugs = [];
console.debug = function(){
    // default &  console.debug()
    console.defaultDebug.apply(console, arguments);
    // new & array data
    console.debugs.push(Array.from(arguments));
}

console.logs contains all what was logged. You can clean it at any time by doing console.logs.length = 0;.

You can still do a standard, non storing, log by calling console.stdlog.

You can see practical example here in my other article about console logging

::Share it on::

Comments (0)

What are your thoughts on "How to hook Google Console"?

You need to create an account to comment on this post.

Related articles