pimterry / loglevel

:ledger: Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods
MIT License
2.62k stars 157 forks source link

Add ES6/browserify/vuejs docs to README? #100

Closed OmgImAlexis closed 7 years ago

OmgImAlexis commented 7 years ago

Since more and more people are starting to use Vuejs it may be an idea to add something to the docs to let them know how to get this library working.

import * as log from 'loglevel';
window.log = log.noConflict();
pimterry commented 7 years ago

I don't know vue. I'm surprised by the above though - why do you need to do that, why don't you just import log and then use it like any other library?

OmgImAlexis commented 7 years ago

You need to import all the functions otherwise none of the log.* functions works. For example log.info() only works after importing info from loglevel.

You also need window.log to use it within all of your .vue files otherwise it'll only work in the single file/component that it's imported into. If the user wanted they could just import it and bind log.noConlict() to the Vue method field but that would limit log to only be usable for that single component.

mibanez commented 7 years ago

Still not working for me (i'm using vue-cli). Seems to be that loglevel has not access to console and every log method end up being the default method noop (function() {})

OmgImAlexis commented 7 years ago

@mibanez did you use import * as log from 'loglevel';? If you just import loglevel itself then nothing it set, that's why you end up with noop.

julestruong commented 7 years ago

@OmgImAlexis not working either for me, did you actually test your code ? :/

OmgImAlexis commented 7 years ago

Yes and I use it for multiple projects.

julestruong commented 7 years ago

@OmgImAlexis worked , sorry

pimterry commented 7 years ago

Glad to hear that all worked out. I'm not totally sure I'm following the above as a non-vue user. Are there some basic instructions for this vue setup that should be in the readme? If any of you want to put together a PR to add a short snippet for this (under Setting it up), I'd be happy to include it.

OmgImAlexis commented 7 years ago

@pimterry just including something like this would work; and it's for ES6 not vue specifically.

In ES6 make sure to import the whole package. The last line only applies while using ES6 in the browser as allows the use of log anywhere in your app.

import * as log from 'loglevel';
window.log = log.noConflict();