Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/HenrikJoreteg/andlog
Super-simple, client-side CommonJS logging thingy
https://github.com/HenrikJoreteg/andlog
Last synced: 4 months ago
JSON representation
Super-simple, client-side CommonJS logging thingy
- Host: GitHub
- URL: https://github.com/HenrikJoreteg/andlog
- Owner: HenrikJoreteg
- Created: 2012-01-23T17:20:05.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2019-11-01T13:38:11.000Z (over 5 years ago)
- Last Synced: 2024-09-26T06:59:07.601Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 98
- Watchers: 3
- Forks: 15
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# &log
Super simple, but solves these pain points:
- Lets you leave log statements in production, client-side code.
- It won't log anything unless `localStorage.debug` is set.
- Uses native `console` rather than trying to wrap it in something (which makes the output ugly).
- Works with CommonJS.
- It's just a selective alias for the `window.console` so the normal API applies.## How to use it:
Step 1. include it:
```html
```
Step 2. Use the `console` in your code as usual:
```javascript
console.log("hello");
```Step 3. If you want to see log output set a value called `debug` in `localStorage` by doing typing this in console:
```javascript
localStorage.debug = true
```If you'd like to use a custom debug key then set `localStorage.andlogKey = 'something-else'` and then set `localStorage['something-else'] = true` to enable logging.
Step 4. Refresh the page, you should now see logs.
Step 5. To turn off console, just delete the localStorage flag:
```javascript
delete localStorage.debug
```Step 6. Feel free to deploy to production with console stuff in there.
## CommonJS Version
If you're using this on the client but your project is in node.js you can install this with: [browserify](https://github.com/substack/node-browserify/) and npm.
```javascript
var logger = require('andlog');logger.log('hello');
```This is identical to:
```javascript
console.log('hello');
```You *could* even get fancy and call it `console`. However by doing this you take the risk that you'll forget to `require` it and it'll still work and you'll ship it to production. However, obviously this would work as well:
```javascript
var console = require('andlog');console.log('hello');
```## Releases
- `1.0.2` bug fix to make sure `ls` is always defined.
## License
MIT
If you like this, follow [@HenrikJoreteg](http://twitter.com/henrikjoreteg) on the twitterwebz.