Permalink
Browse files

issue #48: make dtrace-provider presence optional (disabled dtrace pr…

…obes)

dtrace-provider is still in *dependencies* to strongly encourage
installing it. However I want bunyan.js to be useable for basic
usage standalone.
  • Loading branch information...
1 parent 2438b0b commit 2c4d4713f2d7439d12d76619932879cb6df0f668 @trentm committed Nov 1, 2012
Showing with 10 additions and 5 deletions.
  1. +10 −5 lib/bunyan.js
View
@@ -25,7 +25,11 @@ var os = require('os');
var fs = require('fs');
var util = require('util');
var assert = require('assert');
-var dtrace = require('dtrace-provider');
+try {
+ var dtrace = require('dtrace-provider');
+} catch (e) {
+ dtrace = null;
+}
var EventEmitter = require('events').EventEmitter;
@@ -48,7 +52,7 @@ function objCopy(obj) {
var format = util.format;
if (!format) {
- // If not node 0.6, then use its `util.format`:
+ // If node < 0.6, then use its `util.format`:
// <https://github.com/joyent/node/blob/master/lib/util.js#L22>:
var inspect = util.inspect;
var formatRegExp = /%[sdj%]/g;
@@ -157,8 +161,9 @@ var levelFromName = {
'fatal': FATAL
};
+// Dtrace probes.
var dtp = undefined;
-var probes = {};
+var probes = dtrace && {};
/**
* Resolve a level number, name (upper or lowercase) to a level number value.
@@ -302,7 +307,7 @@ function Logger(options, _childOptions, _childSimple) {
this.fields = {};
}
- if (!dtp) {
+ if (!dtp && dtrace) {
dtp = dtrace.createDTraceProvider('bunyan');
for (var level in levelFromName) {
@@ -768,7 +773,7 @@ function mkLogEmitter(minLevel) {
rec = mkRecord(msgArgs);
str = this._emit(rec);
}
- probes[minLevel].fire(function () {
+ probes && probes[minLevel].fire(function () {
return [ str ||
(rec && log._emit(rec, true)) ||
log._emit(mkRecord(msgArgs), true) ];

0 comments on commit 2c4d471

Please sign in to comment.