Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement] Log function call order #5

Closed
dcondrey opened this issue Dec 4, 2015 · 0 comments
Closed

[enhancement] Log function call order #5

dcondrey opened this issue Dec 4, 2015 · 0 comments

Comments

@dcondrey
Copy link

dcondrey commented Dec 4, 2015

Occasionally I will add console messages at the beginning of each function usually when beginning to review code I'm not familiar with.

Add a check for url parameter to enable or disable any logging.

// example
window.log = function f() {
    log.history = log.history || [];
    log.history.push(arguments);
    if (this.console) {
        var args = arguments,
            newarr;
        args.callee = args.callee.caller;
        newarr = [].slice.call(args);
        if (typeof console.log === 'object') log.apply.call(console.log, console, newarr);
        else console.log.apply(console, newarr);
    }
};
options={
    'debug': window.location.href.indexOf('?debug=true') > -1
}
options.log = options.debug ? function () {
    console && console.log.apply(console, arguments);
} : function () {};

Add a parameter to output a log message for every function call. Something like console.log([class] method);

// example
function augment(withFn) {
    var name, fn;
    for (name in window) {
        fn = window[name];
        if (typeof fn === 'function') {
            window[name] = (function(name, fn) {
                var args = arguments;
                return function() {
                    withFn.apply(this, args);
                    return fn.apply(this, arguments);

                }
            })(name, fn);
        }
    }
}

augment(function(name, fn) {
    console.log([class]: fn);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant