browserify support, bump ver to 1.1.0
This commit is contained in:
parent
cb703ef474
commit
414f33563d
6 changed files with 117 additions and 13 deletions
|
@ -6,9 +6,10 @@ Known issues:
|
|||
bug](https://github.com/TooTallNate/node-gyp/issues/65).
|
||||
|
||||
|
||||
## bunyan 1.0.2 (not yet released)
|
||||
## bunyan 1.1.0 (not yet released)
|
||||
|
||||
(nothing yet)
|
||||
- [issue #162] Preliminary support for [browserify](http://browserify.org/).
|
||||
See [the section in the README](../README.md#browserify).
|
||||
|
||||
|
||||
## bunyan 1.0.1
|
||||
|
|
63
README.md
63
README.md
|
@ -62,6 +62,8 @@ facilities in node 0.12 to which bunyan can switch.
|
|||
- lightweight specialization of Logger instances with [`log.child`](#logchild)
|
||||
- custom rendering of logged objects with ["serializers"](#serializers)
|
||||
- [Runtime log snooping via Dtrace support](#runtime-log-snooping-via-dtrace)
|
||||
- Support for [browserify](http://browserify.org/). See [Browserify
|
||||
section](#browserify) below.
|
||||
|
||||
|
||||
# Introduction
|
||||
|
@ -939,6 +941,67 @@ Output of the above might be:
|
|||
node`_start+0x83
|
||||
|
||||
|
||||
# Browserify
|
||||
|
||||
XXX explain
|
||||
|
||||
As the [Browserify](http://browserify.org/) site says it "lets you
|
||||
`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
|
||||
all its node.js dependencies into a single file that is runnable in the
|
||||
browser via:
|
||||
|
||||
<script src="foo.browser.js"></script>
|
||||
|
||||
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
|
||||
raw log records to `console.log/info/warn/error`.
|
||||
|
||||
Here is a quick example showing you how you can get this working for your
|
||||
script.
|
||||
|
||||
1. Get browserify and bunyan installed in your module:
|
||||
|
||||
|
||||
$ npm install browserify bunyan
|
||||
|
||||
2. An example script using Bunyan, "foo.js":
|
||||
|
||||
var bunyan = require('bunyan');
|
||||
var log = bunyan.createLogger({name: 'play', level: 'debug'});
|
||||
log.trace('this one does not emit');
|
||||
log.debug('hi on debug'); // console.log
|
||||
log.info('hi on info'); // console.info
|
||||
log.warn('hi on warn'); // console.warn
|
||||
log.error('hi on error'); // console.error
|
||||
|
||||
3. Build this into a bundle to run in the browser, "foo.browser.js":
|
||||
|
||||
$ ./node_modules/.bin/browserify foo.js -o foo.browser.js
|
||||
|
||||
4. Put that into an HTML file, "foo.html":
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<script src="foo.browser.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div>hi</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
5. Open that in your browser and open your browser console:
|
||||
|
||||
$ open foo.html
|
||||
|
||||
|
||||
Here is what it looks like in Firefox's console: ![Bunyan + Browserify in the
|
||||
Firefox console](./docs/img/bunyan.browserify.png)
|
||||
|
||||
|
||||
|
||||
# Versioning
|
||||
|
||||
The scheme I follow is most succintly described by the bootstrap guys
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
* vim: expandtab:ts=4:sw=4
|
||||
*/
|
||||
|
||||
var VERSION = '1.0.2';
|
||||
var VERSION = '1.1.0';
|
||||
|
||||
var p = console.log;
|
||||
var util = require('util');
|
||||
|
|
BIN
docs/img/bunyan.browserify.png
Normal file
BIN
docs/img/bunyan.browserify.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 194 KiB |
|
@ -8,7 +8,7 @@
|
|||
* vim: expandtab:ts=4:sw=4
|
||||
*/
|
||||
|
||||
var VERSION = '1.0.2';
|
||||
var VERSION = '1.1.0';
|
||||
|
||||
// Bunyan log format version. This becomes the 'v' field on all log records.
|
||||
// `0` is until I release a version '1.0.0' of node-bunyan. Thereafter,
|
||||
|
@ -31,7 +31,8 @@ var fs = require('fs');
|
|||
var util = require('util');
|
||||
var assert = require('assert');
|
||||
try {
|
||||
var dtrace = require('dtrace-provider');
|
||||
/* Use `+ ''` to hide this import from browserify. */
|
||||
var dtrace = require('dtrace-provider' + '');
|
||||
} catch (e) {
|
||||
dtrace = null;
|
||||
}
|
||||
|
@ -39,11 +40,21 @@ var EventEmitter = require('events').EventEmitter;
|
|||
|
||||
// The 'mv' module is required for rotating-file stream support.
|
||||
try {
|
||||
var mv = require('mv');
|
||||
/* Use `+ ''` to hide this import from browserify. */
|
||||
var mv = require('mv' + '');
|
||||
} catch (e) {
|
||||
mv = null;
|
||||
}
|
||||
|
||||
// Are we in the browser (e.g. running via browserify)?
|
||||
var browser;
|
||||
try {
|
||||
window
|
||||
browser = true;
|
||||
} catch (e) {
|
||||
browser = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---- Internal support stuff
|
||||
|
@ -154,6 +165,19 @@ function _warn(msg, file, line) {
|
|||
var _warned = {};
|
||||
|
||||
|
||||
function ConsoleRawStream() {}
|
||||
ConsoleRawStream.prototype.write = function (rec) {
|
||||
if (rec.level < INFO) {
|
||||
console.log(rec);
|
||||
} else if (rec.level < WARN) {
|
||||
console.info(rec);
|
||||
} else if (rec.level < ERROR) {
|
||||
console.warn(rec);
|
||||
} else {
|
||||
console.error(rec);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//---- Levels
|
||||
|
||||
|
@ -356,6 +380,21 @@ function Logger(options, _childOptions, _childSimple) {
|
|||
} else if (parent && options.level) {
|
||||
this.level(options.level);
|
||||
} else if (!parent) {
|
||||
if (browser) {
|
||||
/*
|
||||
* In the browser we'll be emitting to console.log by default.
|
||||
* Any console.log worth its salt these days can nicely render
|
||||
* and introspect objects (e.g. the Firefox and Chrome console)
|
||||
* so let's emit the raw log record. Are there browsers for which
|
||||
* that breaks things?
|
||||
*/
|
||||
self.addStream({
|
||||
type: 'raw',
|
||||
stream: new ConsoleRawStream(),
|
||||
closeOnExit: false,
|
||||
level: (options.level ? resolveLevel(options.level) : INFO)
|
||||
});
|
||||
} else {
|
||||
self.addStream({
|
||||
type: 'stream',
|
||||
stream: process.stdout,
|
||||
|
@ -363,6 +402,7 @@ function Logger(options, _childOptions, _childSimple) {
|
|||
level: (options.level ? resolveLevel(options.level) : INFO)
|
||||
});
|
||||
}
|
||||
}
|
||||
if (options.serializers) {
|
||||
self.addSerializers(options.serializers);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "bunyan",
|
||||
"version": "1.0.2",
|
||||
"version": "1.1.0",
|
||||
"description": "a JSON logging library for node.js services",
|
||||
"author": "Trent Mick <trentm@gmail.com> (http://trentm.com)",
|
||||
"main": "./lib/bunyan.js",
|
||||
|
|
Loading…
Reference in a new issue