Permalink
Browse files

[issue #12] Add `bunyan.createLogger(OPTIONS)` form, as is more typic…

…al in node.js APIs.

This'll eventually become the preferred form.
  • Loading branch information...
1 parent 6e0d1ec commit c7d5f8b240ef2ec9348ba5fb7d7d4b85da6fe209 @trentm committed Apr 27, 2012
Showing with 59 additions and 6 deletions.
  1. +3 −2 CHANGES.md
  2. +6 −0 README.md
  3. +1 −1 bin/bunyan
  4. +5 −1 lib/bunyan.js
  5. +1 −1 package.json
  6. +43 −1 test/ctor.test.js
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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'});

0 comments on commit c7d5f8b

Please sign in to comment.