Skip to content
Newer
Older
100644 74 lines (45 sloc) 1.82 KB
45e304b @HenrikJoreteg adding stuff
authored
1 # &log
2
3 Super simple, but solves these pain points:
73190b1 @HenrikJoreteg fixing readme
authored
4
45e304b @HenrikJoreteg adding stuff
authored
5 - Lets you leave log statements in production, client-side code.
6 - It won't log anything unless `localStorage.debug` is set.
7 - Uses native `console` rather than trying to wrap it in something (which makes the output ugly).
6fecf0b @HenrikJoreteg now works without CommonJS
authored
8 - Works with CommonJS.
4262ae8 @HenrikJoreteg updating readme
authored
9 - It's just a selective alias for the `window.console` so the normal API applies.
45e304b @HenrikJoreteg adding stuff
authored
10
11 ## How to use it:
12
2fe3663 @HenrikJoreteg improving readme
authored
13
8719615 @HenrikJoreteg fix numbering in readme
authored
14 Step 1. include it:
6fecf0b @HenrikJoreteg now works without CommonJS
authored
15
16 ```html
2fe3663 @HenrikJoreteg improving readme
authored
17 <script src="andlog.js"></script>
6fecf0b @HenrikJoreteg now works without CommonJS
authored
18 ```
19
8719615 @HenrikJoreteg fix numbering in readme
authored
20 Step 2. Use the `console` in your code as usual:
6fecf0b @HenrikJoreteg now works without CommonJS
authored
21
22 ```javascript
23 console.log("hello");
24 ```
25
8719615 @HenrikJoreteg fix numbering in readme
authored
26 Step 3. If you want to see log output set a value called `debug` in `localStorage` by doing typing this in console:
6fecf0b @HenrikJoreteg now works without CommonJS
authored
27
28 ```javascript
29 localStorage.debug = true
30 ```
31
a9d0cb8 @HenrikJoreteg renaming debug key setting to 'andlogKey'
authored
32 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.
4ca9d0b Add information about custom debug key
Lloyd Watkin authored
33
8719615 @HenrikJoreteg fix numbering in readme
authored
34 Step 4. Refresh the page, you should now see logs.
6fecf0b @HenrikJoreteg now works without CommonJS
authored
35
8719615 @HenrikJoreteg fix numbering in readme
authored
36 Step 5. To turn off console, just delete the localStorage flag:
6fecf0b @HenrikJoreteg now works without CommonJS
authored
37
38 ```javascript
39 delete localStorage.debug
40 ```
8719615 @HenrikJoreteg fix numbering in readme
authored
41
42 Step 6. Feel free to deploy to production with console stuff in there.
6fecf0b @HenrikJoreteg now works without CommonJS
authored
43
44
45 ## CommonJS Version
46
a327681 @latentflip Fix docs to not refer to &log but andlog as that's the npm name. Also…
latentflip authored
47 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.
2fe3663 @HenrikJoreteg improving readme
authored
48
45e304b @HenrikJoreteg adding stuff
authored
49 ```javascript
a327681 @latentflip Fix docs to not refer to &log but andlog as that's the npm name. Also…
latentflip authored
50 var logger = require('andlog');
45e304b @HenrikJoreteg adding stuff
authored
51
52 logger.log('hello');
53 ```
54
55 This is identical to:
73190b1 @HenrikJoreteg fixing readme
authored
56
45e304b @HenrikJoreteg adding stuff
authored
57 ```javascript
58 console.log('hello');
59 ```
60
4262ae8 @HenrikJoreteg updating readme
authored
61 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:
62
63 ```javascript
a327681 @latentflip Fix docs to not refer to &log but andlog as that's the npm name. Also…
latentflip authored
64 var console = require('andlog');
4262ae8 @HenrikJoreteg updating readme
authored
65
66 console.log('hello');
67 ```
68
45e304b @HenrikJoreteg adding stuff
authored
69 ## License
73190b1 @HenrikJoreteg fixing readme
authored
70
2fe3663 @HenrikJoreteg improving readme
authored
71 MIT
72
a327681 @latentflip Fix docs to not refer to &log but andlog as that's the npm name. Also…
latentflip authored
73 If you like this, follow [@HenrikJoreteg](http://twitter.com/henrikjoreteg) on the twitterwebz.
Something went wrong with that request. Please try again.