Skip to content
This repository
Browse code

[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...
commit c7d5f8b240ef2ec9348ba5fb7d7d4b85da6fe209 1 parent 6e0d1ec
Trent Mick authored
5 CHANGES.md
Source Rendered
... ... @@ -1,8 +1,9 @@
1 1 # bunyan Changelog
2 2
3   -## bunyan 0.6.10 (not yet released)
  3 +## bunyan 0.7.0 (not yet released)
4 4
5   -(nothing yet)
  5 +- [issue #12] Add `bunyan.createLogger(OPTIONS)` form, as is more typical in
  6 + node.js APIs. This'll eventually become the preferred form.
6 7
7 8
8 9 ## bunyan 0.6.9
6 README.md
Source Rendered
@@ -37,6 +37,12 @@ to log4j logger "name", but Bunyan doesn't do hierarchical logger names.
37 37 var log = new Logger({name: "myapp"});
38 38 log.info("hi");
39 39
  40 +Alternatively, bunyan 0.7.0 and up supports a more node.js-land typical
  41 +style (which might become the preferred form over time):
  42 +
  43 + var bunyan = require('bunyan');
  44 + var log = bunyan.createLogger({name: "myapp"});
  45 +
40 46 **Log records are JSON.** "hostname", "time" and "v" (the Bunyan log
41 47 format version) are added for you.
42 48
2  bin/bunyan
@@ -5,7 +5,7 @@
5 5 // See <https://github.com/trentm/node-bunyan>.
6 6 //
7 7
8   -var VERSION = "0.6.10";
  8 +var VERSION = "0.7.0";
9 9
10 10 var util = require('util');
11 11 var pathlib = require('path');
6 lib/bunyan.js
@@ -4,7 +4,7 @@
4 4 * The bunyan logging library for node.js.
5 5 */
6 6
7   -var VERSION = "0.6.10";
  7 +var VERSION = "0.7.0";
8 8
9 9 // Bunyan log format version. This becomes the 'v' field on all log records.
10 10 // `0` is until I release a version "1.0.0" of node-bunyan. Thereafter,
@@ -955,3 +955,7 @@ module.exports.FATAL = FATAL;
955 955
956 956 module.exports.VERSION = VERSION;
957 957 module.exports.LOG_VERSION = LOG_VERSION;
  958 +
  959 +module.exports.createLogger = function createLogger(options) {
  960 + return new Logger(options);
  961 +};
2  package.json
... ... @@ -1,6 +1,6 @@
1 1 {
2 2 "name": "bunyan",
3   - "version": "0.6.10",
  3 + "version": "0.7.0",
4 4 "description": "a JSON Logger library for node.js servers",
5 5 "author": "Trent Mick <trentm@gmail.com> (http://trentm.com)",
6 6 "main": "./lib/bunyan.js",
44 test/ctor.test.js
@@ -5,7 +5,9 @@
5 5 */
6 6
7 7 var test = require('tap').test;
8   -var Logger = require('../lib/bunyan');
  8 +var bunyan = require('../lib/bunyan'),
  9 + Logger = bunyan;
  10 +
9 11
10 12
11 13 test('ensure Logger creation options', function (t) {
@@ -48,6 +50,46 @@ test('ensure Logger creation options', function (t) {
48 50 });
49 51
50 52
  53 +test('ensure Logger creation options (createLogger)', function (t) {
  54 + t.throws(function () { bunyan.createLogger(); },
  55 + {name: 'TypeError', message: 'options (object) is required'},
  56 + 'no options should throw');
  57 +
  58 + t.throws(function () { bunyan.createLogger({}); },
  59 + {name: 'TypeError', message: 'options.name (string) is required'},
  60 + 'no options.name should throw');
  61 +
  62 + t.doesNotThrow(function () { bunyan.createLogger({name: 'foo'}); },
  63 + 'just options.name should be sufficient');
  64 +
  65 + var options = {name: 'foo', stream: process.stdout, streams: []};
  66 + t.throws(function () { bunyan.createLogger(options); },
  67 + 'cannot use "stream" and "streams"');
  68 +
  69 + options = {name: 'foo', level: 'info', streams: []};
  70 + t.throws(function () { bunyan.createLogger(options); },
  71 + 'cannot use "level" and "streams"');
  72 +
  73 + // https://github.com/trentm/node-bunyan/issues/3
  74 + options = {name: 'foo', streams: {}};
  75 + t.throws(function () { bunyan.createLogger(options); },
  76 + {name: 'TypeError', message: 'invalid options.streams: must be an array'},
  77 + '"streams" must be an array');
  78 +
  79 + options = {name: 'foo', serializers: 'a string'};
  80 + t.throws(function () { bunyan.createLogger(options); },
  81 + {name: 'TypeError', message: 'invalid options.serializers: must be an object'},
  82 + '"serializers" cannot be a string');
  83 +
  84 + options = {name: 'foo', serializers: [1,2,3]};
  85 + t.throws(function () { bunyan.createLogger(options); },
  86 + {name: 'TypeError', message: 'invalid options.serializers: must be an object'},
  87 + '"serializers" cannot be an array');
  88 +
  89 + t.end();
  90 +});
  91 +
  92 +
51 93 test('ensure Logger child() options', function (t) {
52 94 var log = new Logger({name: 'foo'});
53 95

0 comments on commit c7d5f8b

Please sign in to comment.
Something went wrong with that request. Please try again.