issue #48: make dtrace-provider presence optional (disabled dtrace probes)

dtrace-provider is still in *dependencies* to strongly encourage
installing it. However I want bunyan.js to be useable for basic
usage standalone.
This commit is contained in:
Trent Mick 2012-10-31 22:46:05 -07:00
parent 2438b0b01c
commit 2c4d4713f2

View file

@ -25,7 +25,11 @@ var os = require('os');
var fs = require('fs');
var util = require('util');
var assert = require('assert');
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) ];