I created a wrapper for console logging. I have been unable to get it to display the logged line number that the wrapper function is called from. I have looked at other posts to handle this but I cannot seem to get what they mentioned. They were basically binding the console.log to the external function but I need to do other work inside before its used.
Is it possible with my setup?
var logger = (function (window, console) {
// logger object
function logger() {
// use to initialize the logger
function init() {
fixConsole();
}
// fix missing console
function fixConsole() {
var logmethod;
var noop = function () { };
var logmethods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
];
var length = logmethods.length;
console = (window.console = window.console || {});
while (length--) {
logmethod = logmethods[length];
// Only stub undefined methods.
if (!console[logmethod]) {
console[logmethod] = noop;
}
}
}
// initializing the logger
init();
}
// logging methods
logger.prototype = {
info: function (msg, title) {
if (title)
console.log(title + ": " + msg);
else
console.log(msg);
}
}
// create logger
function _create() {
// create logger
var log = new logger();
// return logger
return log;
}
// exposed functions
return {
create: _create
}
})(window, console);
var log = logger.create();
log.info('Hello, I am trying to get the logger to log under the line number info is used on.');
log.info('For instance I want line number 75 to show.');
<h1> Press F12 and look at the console to see</h1>