From 594cc82da123e4e3687b0a7899ab0570cc57362e Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Fri, 26 Sep 2014 20:46:27 -0700 Subject: [PATCH] Better browser sniffing suggested at https://github.com/trentm/node-bunyan/commit/414f33563d52d6ceae558936a2eb111cc8b9ab66#commitcomment-7936060 --- lib/bunyan.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/bunyan.js b/lib/bunyan.js index bf6fda3..1e85649 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -47,13 +47,8 @@ try { } // Are we in the browser (e.g. running via browserify)? -var browser; -try { - window - browser = true; -} catch (e) { - browser = false; -} +var isBrowser = function () { + return typeof (window) !== 'undefined' && this === window; }(); @@ -380,7 +375,7 @@ function Logger(options, _childOptions, _childSimple) { } else if (parent && options.level) { this.level(options.level); } else if (!parent) { - if (browser) { + if (isBrowser) { /* * In the browser we'll be emitting to console.log by default. * Any console.log worth its salt these days can nicely render