[issue #12] Add `bunyan.createLogger(OPTIONS)` form, as is more typical in node.js APIs.

This'll eventually become the preferred form.
master
Trent Mick 2012-04-27 16:20:57 -07:00
parent 6e0d1ecbc2
commit c7d5f8b240
6 changed files with 59 additions and 6 deletions

View File

@ -1,8 +1,9 @@
# bunyan Changelog
## bunyan 0.6.10 (not yet released)
## bunyan 0.7.0 (not yet released)
(nothing yet)
- [issue #12] Add `bunyan.createLogger(OPTIONS)` form, as is more typical in
node.js APIs. This'll eventually become the preferred form.
## bunyan 0.6.9

View File

@ -37,6 +37,12 @@ to log4j logger "name", but Bunyan doesn't do hierarchical logger names.
var log = new Logger({name: "myapp"});
log.info("hi");
Alternatively, bunyan 0.7.0 and up supports a more node.js-land typical
style (which might become the preferred form over time):
var bunyan = require('bunyan');
var log = bunyan.createLogger({name: "myapp"});
**Log records are JSON.** "hostname", "time" and "v" (the Bunyan log
format version) are added for you.

View File

@ -5,7 +5,7 @@
// See <https://github.com/trentm/node-bunyan>.
//
var VERSION = "0.6.10";
var VERSION = "0.7.0";
var util = require('util');
var pathlib = require('path');

View File

@ -4,7 +4,7 @@
* The bunyan logging library for node.js.
*/
var VERSION = "0.6.10";
var VERSION = "0.7.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,
@ -955,3 +955,7 @@ module.exports.FATAL = FATAL;
module.exports.VERSION = VERSION;
module.exports.LOG_VERSION = LOG_VERSION;
module.exports.createLogger = function createLogger(options) {
return new Logger(options);
};

View File

@ -1,6 +1,6 @@
{
"name": "bunyan",
"version": "0.6.10",
"version": "0.7.0",
"description": "a JSON Logger library for node.js servers",
"author": "Trent Mick <trentm@gmail.com> (http://trentm.com)",
"main": "./lib/bunyan.js",

View File

@ -5,7 +5,9 @@
*/
var test = require('tap').test;
var Logger = require('../lib/bunyan');
var bunyan = require('../lib/bunyan'),
Logger = bunyan;
test('ensure Logger creation options', function (t) {
@ -48,6 +50,46 @@ test('ensure Logger creation options', function (t) {
});
test('ensure Logger creation options (createLogger)', function (t) {
t.throws(function () { bunyan.createLogger(); },
{name: 'TypeError', message: 'options (object) is required'},
'no options should throw');
t.throws(function () { bunyan.createLogger({}); },
{name: 'TypeError', message: 'options.name (string) is required'},
'no options.name should throw');
t.doesNotThrow(function () { bunyan.createLogger({name: 'foo'}); },
'just options.name should be sufficient');
var options = {name: 'foo', stream: process.stdout, streams: []};
t.throws(function () { bunyan.createLogger(options); },
'cannot use "stream" and "streams"');
options = {name: 'foo', level: 'info', streams: []};
t.throws(function () { bunyan.createLogger(options); },
'cannot use "level" and "streams"');
// https://github.com/trentm/node-bunyan/issues/3
options = {name: 'foo', streams: {}};
t.throws(function () { bunyan.createLogger(options); },
{name: 'TypeError', message: 'invalid options.streams: must be an array'},
'"streams" must be an array');
options = {name: 'foo', serializers: 'a string'};
t.throws(function () { bunyan.createLogger(options); },
{name: 'TypeError', message: 'invalid options.serializers: must be an object'},
'"serializers" cannot be a string');
options = {name: 'foo', serializers: [1,2,3]};
t.throws(function () { bunyan.createLogger(options); },
{name: 'TypeError', message: 'invalid options.serializers: must be an object'},
'"serializers" cannot be an array');
t.end();
});
test('ensure Logger child() options', function (t) {
var log = new Logger({name: 'foo'});