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

It is really necessary to create and destroy methods? #19

Closed
sporto opened this issue Jun 21, 2013 · 3 comments
Closed

It is really necessary to create and destroy methods? #19

sporto opened this issue Jun 21, 2013 · 3 comments

Comments

@sporto
Copy link

sporto commented Jun 21, 2013

Hi

I notice that you create and destroy the methods on the fly. Or something like.
The thing is that doing this prevents me from being able to do something like this:

APP.logger.log = log.info.bind(log);

Meaning I am able to abstract your library just in case we need to switch it later.

This works, buts looks unnecessary:

function info(msg) {
    log.info(msg);  
}

APP.logger.log = info;

Thanks

@pimterry
Copy link
Owner

Hmmm. The core problem isn't that we're creating and destroying methods, it's actually that we're not creating any methods; all that happens is log.info gets assigned to a bound version of console.info, when you call setLevel, or a single noop method that gets assigned to it instead (see loglevel.js lines 124-126)

This can't stop happening; doing that rather than wrapping the function in a method that looks at the level and then calls the appropriate method is what stops it from clobbering the stacktraces. If you wrap the methods, then chrome and firefox shows the message as coming from inside loglevel, rather than from whichever line you actually called it from (which is extremely annoying).

I do see you use case though, that makes sense. Any other suggestions for methods to fix this?

@sporto
Copy link
Author

sporto commented Jun 22, 2013

I haven't thought about the stacktraces consideration at all, that is definitely important. I don't have any suggestions for the moment. Will have another look later on.

@pimterry
Copy link
Owner

For now I'm going to close this. Do feel free to shout (either @sporto or anybody else) if you disagree, I'm very happy to reopen it if anybody can think of any other options that do support this use case.

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

2 participants