reading the firebug console in javascript

后端 未结 5 583
春和景丽
春和景丽 2020-12-19 16:37

I\'m looking for a way to read the most recent command that was logged to the firebug console.

For example, I could have something that does

console.         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 17:23

    You could overwrite the console.log function to add whatever extra functionality you need.

    var oldLog = console.log;
    var lastLog;
    console.log = function () {
        // do whatever you need to do here: store the logs into a different variable, etc
        // eg:
        lastLog = arguments;
    
        // then call the regular log command
        oldLog.apply(console, arguments);
    };
    

    This won't be the most bulletproof solution, since console allows printf style syntax:

    console.log("%d + %d = %s", 1, 3, "four");
    

    ...but it's probably a start for you.

提交回复
热议问题