clean up README sectioN
This commit is contained in:
parent
9e6a199ca5
commit
f5e5d577f0
1 changed files with 53 additions and 49 deletions
38
README.md
38
README.md
|
@ -943,15 +943,13 @@ Output of the above might be:
|
||||||
|
|
||||||
# Browserify
|
# Browserify
|
||||||
|
|
||||||
XXX explain
|
|
||||||
|
|
||||||
As the [Browserify](http://browserify.org/) site says it "lets you
|
As the [Browserify](http://browserify.org/) site says it "lets you
|
||||||
`require('modules')` in the browser by bundling up all of your dependencies."
|
`require('modules')` in the browser by bundling up all of your dependencies."
|
||||||
It is a build tool to run on your node.js script to bundle up your script and
|
It is a build tool to run on your node.js script to bundle up your script and
|
||||||
all its node.js dependencies into a single file that is runnable in the
|
all its node.js dependencies into a single file that is runnable in the
|
||||||
browser via:
|
browser via:
|
||||||
|
|
||||||
<script src="foo.browser.js"></script>
|
<script src="play.browser.js"></script>
|
||||||
|
|
||||||
As of version 1.1.0, node-bunyan supports being run via Browserify. The
|
As of version 1.1.0, node-bunyan supports being run via Browserify. The
|
||||||
default [stream](#streams) when running in the browser is one that emits
|
default [stream](#streams) when running in the browser is one that emits
|
||||||
|
@ -965,8 +963,9 @@ script.
|
||||||
|
|
||||||
$ npm install browserify bunyan
|
$ npm install browserify bunyan
|
||||||
|
|
||||||
2. An example script using Bunyan, "foo.js":
|
2. An example script using Bunyan, "play.js":
|
||||||
|
|
||||||
|
```javascript
|
||||||
var bunyan = require('bunyan');
|
var bunyan = require('bunyan');
|
||||||
var log = bunyan.createLogger({name: 'play', level: 'debug'});
|
var log = bunyan.createLogger({name: 'play', level: 'debug'});
|
||||||
log.trace('this one does not emit');
|
log.trace('this one does not emit');
|
||||||
|
@ -974,37 +973,41 @@ script.
|
||||||
log.info('hi on info'); // console.info
|
log.info('hi on info'); // console.info
|
||||||
log.warn('hi on warn'); // console.warn
|
log.warn('hi on warn'); // console.warn
|
||||||
log.error('hi on error'); // console.error
|
log.error('hi on error'); // console.error
|
||||||
|
```
|
||||||
|
|
||||||
3. Build this into a bundle to run in the browser, "foo.browser.js":
|
3. Build this into a bundle to run in the browser, "play.browser.js":
|
||||||
|
|
||||||
$ ./node_modules/.bin/browserify foo.js -o foo.browser.js
|
$ ./node_modules/.bin/browserify play.js -o play.browser.js
|
||||||
|
|
||||||
4. Put that into an HTML file, "foo.html":
|
4. Put that into an HTML file, "play.html":
|
||||||
|
|
||||||
|
```html
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<script src="foo.browser.js"></script>
|
<script src="play.browser.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div>hi</div>
|
<div>hi</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
```
|
||||||
|
|
||||||
5. Open that in your browser and open your browser console:
|
5. Open that in your browser and open your browser console:
|
||||||
|
|
||||||
$ open foo.html
|
$ open play.html
|
||||||
|
|
||||||
|
|
||||||
Here is what it looks like in Firefox's console: ![Bunyan + Browserify in the
|
Here is what it looks like in Firefox's console: ![Bunyan + Browserify in the
|
||||||
Firefox console](./docs/img/bunyan.browserify.png)
|
Firefox console](./docs/img/bunyan.browserify.png)
|
||||||
|
|
||||||
For some the raw log records might not be desired, to have a rendered log line
|
For some, the raw log records might not be desired. To have a rendered log line
|
||||||
you'll want to add your own stream, starting with something like this:
|
you'll want to add your own stream, starting with something like this:
|
||||||
|
|
||||||
function MyRawStream() {}
|
```javascript
|
||||||
MyRawStream.prototype.write = function (rec) {
|
function MyRawStream() {}
|
||||||
|
MyRawStream.prototype.write = function (rec) {
|
||||||
var nameFromLevel = {
|
var nameFromLevel = {
|
||||||
TRACE: 'TRACE'
|
TRACE: 'TRACE'
|
||||||
DEBUG: 'DEBUG',
|
DEBUG: 'DEBUG',
|
||||||
|
@ -1014,10 +1017,10 @@ you'll want to add your own stream, starting with something like this:
|
||||||
FATAL: 'FATAL'
|
FATAL: 'FATAL'
|
||||||
};
|
};
|
||||||
console.log('[%s] %s: %s', rec.time, nameFromLevel[rec.level], rec.msg);
|
console.log('[%s] %s: %s', rec.time, nameFromLevel[rec.level], rec.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
var log = bunyan.createLogger({
|
var log = bunyan.createLogger({
|
||||||
name: 'foo',
|
name: 'play',
|
||||||
streams: [
|
streams: [
|
||||||
{
|
{
|
||||||
level: 'info',
|
level: 'info',
|
||||||
|
@ -1025,9 +1028,10 @@ you'll want to add your own stream, starting with something like this:
|
||||||
type: 'raw'
|
type: 'raw'
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info('hi on info');
|
log.info('hi on info');
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue