From 660b70647913aa1eb5c8aa4979d291361a5e3cc9 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Fri, 1 Aug 2014 15:57:48 -0700 Subject: [PATCH] doc new -c CODE; drop dtrace-provider as optionalDependency (fixes #135); add 'bunyan -0' shortcut --- AUTHORS | 1 + CHANGES.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++-- Makefile | 3 ++- bin/bunyan | 44 +++++++++++++++++----------------- lib/bunyan.js | 9 +++---- package.json | 10 ++++---- test/cli.test.js | 1 - 7 files changed, 93 insertions(+), 36 deletions(-) diff --git a/AUTHORS b/AUTHORS index ed0a0ce..1b28a0d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,3 +9,4 @@ Michael Hart (https://github.com/mhart) Simon Wade (https://github.com/aexmachina) https://github.com/glenn-murray-bse Chakrit Wichian (https://github.com/chakrit) +Patrick Mooney (https://github.com/pfmooney) diff --git a/CHANGES.md b/CHANGES.md index 7f29ae7..66f6860 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,9 +6,66 @@ Known issues: bug](https://github.com/TooTallNate/node-gyp/issues/65). -## bunyan 0.23.2 (not yet released) +## bunyan 1.0.0 (not yet released) + +- [issue #87] **Backward incompatible change to `-c CODE`** improving + performance by over 10x (good!), with a backward incompatible change to + semantics (unfortunate), and adding some sugar (good!). + + The `-c CODE` implementation was changed to use a JS function for processing + rather than `vm.runInNewContext`. The latter was specatularly slow, so + won't be missed. Unfortunately this does mean a few semantic differences in + the `CODE`, the most noticeable of which is that **`this` is required to + access the object fields:** + + # Bad. Works with bunyan 0.x but not 1.x. + $ bunyan -c 'pid === 123' foo.log + ... + + # Good. Works with all versions of bunyan + $ bunyan -c 'this.pid === 123' foo.log + ... + + The old behaviour of `-c` can be restored with the `BUNYAN_EXEC=vm` + environment variable: + + $ BUNYAN_EXEC=vm bunyan -c 'pid === 123' foo.log + ... + + Some sugar was also added: the TRACE, DEBUG, ... constants are defined, so + one can: + + $ bunyan -c 'this.level >= ERROR && this.component === "http"' foo.log + ... + + And example of the speed improvement on a 10 MiB log example: + + $ time BUNYAN_EXEC=vm bunyan -c 'this.level === ERROR' big.log | cat >slow + + real 0m6.349s + user 0m6.292s + sys 0m0.110s + + $ time bunyan -c 'this.level === ERROR' big.log | cat >fast + + real 0m0.333s + user 0m0.303s + sys 0m0.028s + + The change was courtesy Patrick Mooney (https://github.com/pfmooney). Thanks! + +- Add `bunyan -0 ...` shortcut for `bunyan -o bunyan ...`. + +- [issue #135] **Backward incompatible.** Drop dtrace-provider even from + `optionalDependencies`. Dtrace-provider has proven a consistent barrier to + installing bunyan, because it is a binary dep. Even as an *optional* dep it + still caused confusion and install noise. + + Users of Bunyan on dtrace-y platforms (SmartOS, Mac, Solaris) will need to + manually `npm install dtrace-provider` themselves to get [Bunyan's + dtrace support](https://github.com/trentm/node-bunyan#runtime-log-snooping-via-dtrace) + to work. If not installed, bunyan should stub it out properly. -(nothing yet) ## bunyan 0.23.1 diff --git a/Makefile b/Makefile index c38a767..1d78df8 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,9 @@ NON_DTRACE_TEST_FILES := $(shell ls -1 test/*.test.js | grep -v dtrace | xargs) #---- Targets -all: +all $(NODEUNIT): npm install + npm install dtrace-provider # Ensure all version-carrying files have the same version. .PHONY: versioncheck diff --git a/bin/bunyan b/bin/bunyan index 4942a10..a8a3f25 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -1,12 +1,17 @@ #!/usr/bin/env node -// -*- mode: js -*- -// -// bunyan -- filter and pretty-print JSON logs, like Bunyan logs. -// -// See . -// +/** + * Copyright (c) 2014 Trent Mick. All rights reserved. + * Copyright (c) 2014 Joyent Inc. All rights reserved. + * + * bunyan -- filter and pretty-print Bunyan log files (line-delimited JSON) + * + * See . + * + * -*- mode: js -*- + * vim: expandtab:ts=4:sw=4 + */ -var VERSION = '0.23.2'; +var VERSION = '1.0.0'; var p = console.log; var util = require('util'); @@ -187,8 +192,8 @@ function printHelp() { p('Filtering options:'); p(' -l, --level LEVEL'); p(' Only show messages at or above the specified level.'); - p(' You can specify level *names* or numeric values.'); - p(' (See "Log Levels" below.)'); + p(' You can specify level *names* or the internal numeric'); + p(' values.'); p(' -c, --condition CONDITION'); p(' Run each log message through the condition and'); p(' only show those that return truish. E.g.:'); @@ -218,18 +223,7 @@ function printHelp() { p(' inspect: node.js `util.inspect` output'); p(' short: like "long", but more concise'); p(' -j shortcut for `-o json`'); - p(''); - p('Log Levels:'); - p(' Either numeric values or their associated strings are valid for the'); - p(' -l|--level argument. However, -c|--condition scripts will see a numeric'); - p(' "level" value, not a string.'); - p(''); - Object.keys(levelFromName).forEach(function (name) { - var n = name; - while (n.length < 6) - n += ' '; - p(' %s %d', n, levelFromName[name]); - }); + p(' -0 shortcut for `-o bunyan`'); p(''); p('Environment Variables:'); p(' BUNYAN_NO_COLOR Set to a non-empty value to force no output '); @@ -490,6 +484,9 @@ function parseArgv(argv) { case '-j': // output with JSON.stringify parsed.outputMode = OM_JSON; break; + case '-0': + parsed.outputMode = OM_BUNYAN; + break; case '-p': if (!parsed.pids) { parsed.pids = []; @@ -530,8 +527,9 @@ function parseArgv(argv) { case '-c': case '--condition': var condition = args.shift(); - if (Boolean(process.env.JSON_EXEC && - process.env.JSON_EXEC === 'vm')) { + if (Boolean(process.env.BUNYAN_EXEC && + process.env.BUNYAN_EXEC === 'vm')) + { parsed.condVm = parsed.condVm || []; var scriptName = 'bunyan-condition-'+parsed.condVm.length; var code = condDefines + condition; diff --git a/lib/bunyan.js b/lib/bunyan.js index f4b84ce..8c6e178 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -1,13 +1,14 @@ -/* - * Copyright (c) 2013 Trent Mick. All rights reserved. - * Copyright (c) 2013 Joyent Inc. All rights reserved. +/** + * Copyright (c) 2014 Trent Mick. All rights reserved. + * Copyright (c) 2014 Joyent Inc. All rights reserved. * * The bunyan logging library for node.js. * + * -*- mode: js -*- * vim: expandtab:ts=4:sw=4 */ -var VERSION = '0.23.2'; +var VERSION = '1.0.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, diff --git a/package.json b/package.json index 6fd7edb..3791ad5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bunyan", - "version": "0.23.2", - "description": "a JSON Logger library for node.js services", + "version": "1.0.0", + "description": "a JSON logging library for node.js services", "author": "Trent Mick (http://trentm.com)", "main": "./lib/bunyan.js", "bin": { @@ -17,10 +17,10 @@ "dependencies": { }, - "// comment": "'mv' required for RotatingFileStream", + "// comment: mv": "'mv' required for RotatingFileStream", + "// comment: dtrace": "dtrace-provider required for Bunyan dtrace features, but install is notoriously problematic on some plats (#135)", "optionalDependencies": { - "mv": "~2", - "dtrace-provider": "0.2.8" + "mv": "~2" }, "devDependencies": { "nodeunit": "0.7.4", diff --git a/test/cli.test.js b/test/cli.test.js index c9a210f..7d83184 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -330,7 +330,6 @@ test('--condition "this.level === TRACE', function (t) { }); // multiple -// not sure if this is a bug or a feature. let's call it a feature! test('multiple --conditions', function (t) { var expect = [ '# levels\n',