Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browser-bunyan

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-bunyan - npm Package Compare versions

Comparing version 0.4.0 to 1.0.0-pre

lib/console-formatted-stream.js

4

CHANGES.md
# bunyan Changelog
## 1.0.0
- Internals reworked. Better modularization, some ES6 features. Packaged with Rollup
- ES Modules interface.
## 0.4.0

@@ -4,0 +8,0 @@

7

dist/browser-bunyan.min.js

@@ -1,6 +0,1 @@

/**
* browser-bunyan - 0.4.0
* A fork of Bunyan specifically for the browser
* MIT
*/
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r;r="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,r.bunyan=e()}}(function(){return function e(r,t,s){function i(o,l){if(!t[o]){if(!r[o]){var a="function"==typeof require&&require;if(!l&&a)return a(o,!0);if(n)return n(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var f=t[o]={exports:{}};r[o][0].call(f.exports,function(e){var t=r[o][1][e];return i(t?t:e)},f,f.exports,e,r,t,s)}return t[o].exports}for(var n="function"==typeof require&&require,o=0;o<s.length;o++)i(s[o]);return i}({1:[function(e,r,t){"use strict";function s(e){if("undefined"==typeof e||null===e)return e;if(Array.isArray(e))return e.slice();if("object"==typeof e){var r={};return Object.keys(e).forEach(function(t){r[t]=e[t]}),r}return e}function i(e,r){var t=e.split("\n");t[0]&&t[0].indexOf(m)>=0&&t.shift();var s=t[r],i=null;if(s){var n=/^\s*(at|.*@)\s*(.+)?$/.exec(s);i=Array.isArray(n)&&n[2]?n[2]:s}return i}function n(e,r){r||(r=" ");var t=e.split(/\r?\n/g);return r+t.join("\n"+r)}function o(e,r){if(r){if(b[r])return;b[r]=!0}console.error(e+"\n")}function l(e){return b[e]}function a(){}function c(e){e=e||{},this.logByLevel=!!e.logByLevel}function f(e){var r="string"==typeof e?k[e.toLowerCase()]:e;return r}function u(e,r,t){if(!(this instanceof u))return new u(e,r);var i;if(void 0!==r&&(i=e,e=r,!(i instanceof u)))throw new TypeError("invalid Logger creation: do not pass a second arg");if(!e)throw new TypeError("options (object) is required");if(i){if(e.name)throw new TypeError("invalid options.name: child cannot set logger name")}else if(!e.name)throw new TypeError("options.name (string) is required");if(e.stream&&e.streams)throw new TypeError('cannot mix "streams" and "stream" options');if(e.streams&&!Array.isArray(e.streams))throw new TypeError("invalid options.streams: must be an array");if(e.serializers&&("object"!=typeof e.serializers||Array.isArray(e.serializers)))throw new TypeError("invalid options.serializers: must be an object");var n,o,l;if(i&&t){this._isSimpleChild=!0,this._level=i._level,this.streams=i.streams,this.serializers=i.serializers,this.src=i.src,n=this.fields={};var c=Object.keys(i.fields);for(l=0;l<c.length;l++)o=c[l],n[o]=i.fields[o];var f=Object.keys(e);for(l=0;l<f.length;l++)o=f[l],n[o]=e[o]}else{var p=this;if(i){for(this._level=i._level,this.streams=[],l=0;l<i.streams.length;l++){var h=s(i.streams[l]);h.closeOnExit=!1,this.streams.push(h)}this.serializers=s(i.serializers),this.src=i.src,this.fields=s(i.fields),e.level&&this.level(e.level)}else this._level=Number.POSITIVE_INFINITY,this.streams=[],this.serializers=null,this.src=!1,this.fields={};e.stream?p.addStream({type:"stream",stream:e.stream,closeOnExit:!1,level:e.level}):e.streams?e.streams.forEach(function(r){p.addStream(r,e.level)}):i&&e.level?this.level(e.level):i||p.addStream({type:"raw",stream:new a,closeOnExit:!1,level:e.level}),e.serializers&&p.addSerializers(e.serializers),e.src&&(this.src=!0),n=s(e),delete n.stream,delete n.level,delete n.streams,delete n.serializers,delete n.src,this.serializers&&this._applySerializers(n),Object.keys(n).forEach(function(e){p.fields[e]=n[e]})}}function p(e){return function(){function r(r){var c;r[0]instanceof Error?(n={err:t.serializers&&t.serializers.err?t.serializers.err(r[0]):u.stdSerializers.err(r[0])},c={err:!0},a=1===r.length?[n.err.message]:Array.prototype.slice.call(r,1)):"object"!=typeof r[0]&&null!==r[0]||Array.isArray(r[0])?(n=null,a=Array.prototype.slice.call(r)):(n=r[0],a=1===r.length&&n.err&&n.err instanceof Error?[n.err.message]:Array.prototype.slice.call(r,1));var f=s(t.fields);f.level=e;var p=n?s(n):null;if(p&&(t.serializers&&t._applySerializers(p,c),Object.keys(p).forEach(function(e){f[e]=p[e]})),f.levelName=N[e],f.msg=a.length?w.apply(t,a):"",f.time||(f.time=new Date),t.src&&!f.src)try{throw new Error(m)}catch(h){var v=i(h.stack,2);v||l("src")||o("Unable to determine src line info","src"),f.src=v||""}return f.v=d,f}var t=this,n=null,a=arguments,c=null;return 0===arguments.length?this._level<=e:void(this._level>e||(c=r(a),this._emit(c)))}}function h(e){var r=e.stack||e.toString();if(e.cause&&"function"==typeof e.cause){var t=e.cause();t&&(r+="\nCaused by: "+h(t))}return r}function v(){var e=[];return function(r,t){return t&&"object"==typeof t?e.indexOf(t)!==-1?"[Circular]":(e.push(t),t):t}}var y="0.4.0",d=0,m="call-stack-error",g=function(e){if("undefined"==typeof e)return"undefined";if(null===e)return"null";if(Array.isArray(e)){var r=e.map(function(e){return g(e)});return"[ "+r.join(", ")+" ]"}return"object"==typeof e?JSON.stringify(e):"function"==typeof e?"[Function: "+e.name+"]":"boolean"==typeof e||"number"==typeof e?e:"'"+e.toString()+"'"},w=function(e){if("string"!=typeof e){for(var r=new Array(arguments.length),t=0;t<arguments.length;t++)r[t]=g(arguments[t]);return r.join(" ")}for(var s=/%[sdj%]/g,i=1,n=arguments,o=n.length,l=String(e).replace(s,function(e){if("%%"===e)return"%";if(i>=o)return e;switch(e){case"%s":return String(n[i++]);case"%d":return Number(n[i++]);case"%j":try{return JSON.stringify(n[i++])}catch(r){return"[Circular]"}break;default:return e}}),a=n[i];i<o;a=n[++i])l+=" "+a;return l},b={};a.prototype.write=function(e){e.level<x?console.log(e):e.level<z?console.info(e):e.level<O?console.warn(e):console.error(e),e.err&&e.err.stack&&console.error(e.err.stack),e.obj&&console.log(e.obj)},c.prototype.write=function(e){function r(e,r){return Array(r+1-(e+"").length).join("0")+e}var t,s,i="color: DimGray",n="color: SteelBlue",o="color: DimGray; font-style: italic; font-size: 0.9em",l=e.childName?e.name+"/"+e.childName:e.name,a=N[e.level],c=(Array(6-a.length).join(" ")+a).toUpperCase();this.logByLevel?(e.level===E?a="debug":e.level===j&&(a="error"),s="function"==typeof console[a]?console[a]:console.log):s=console.log,t=e.level<S?"color: DeepPink":e.level<x?"color: GoldenRod":e.level<z?"color: DarkTurquoise":e.level<O?"color: Purple":e.level<j?"color: Crimson":"color: Black";var f=[];f.push("[%s:%s:%s:%s] %c%s%c: %s: %c%s %c%s"),f.push(r(e.time.getHours(),2)),f.push(r(e.time.getMinutes(),2)),f.push(r(e.time.getSeconds(),2)),f.push(r(e.time.getMilliseconds(),4)),f.push(t),f.push(c),f.push(i),f.push(l),f.push(n),f.push(e.msg),e.src&&(f.push(o),f.push(e.src)),s.apply(console,f),e.err&&e.err.stack&&s.call(console,"%c%s,",t,e.err.stack),e.obj&&s.call(console,e.obj)};var E=10,S=20,x=30,z=40,O=50,j=60,k={trace:E,debug:S,info:x,warn:z,error:O,fatal:j},N={};Object.keys(k).forEach(function(e){N[k[e]]=e}),u.prototype.addStream=function(e,r){var t=this;null!==r&&void 0!==r||(r=x),e=s(e),e.type="raw",e.level?e.level=f(e.level):e.level=f(r),e.level<t._level&&(t._level=e.level),e.closeOnExit||(e.closeOnExit=!1),t.streams.push(e),delete t.haveNonRawStreams},u.prototype.addSerializers=function(e){var r=this;r.serializers||(r.serializers={}),Object.keys(e).forEach(function(t){var s=e[t];if("function"!=typeof s)throw new TypeError(w('invalid serializer for "%s" field: must be a function',t));r.serializers[t]=s})},u.prototype.child=function(e,r){return new this.constructor(this,e||{},r)},u.prototype.level=function(e){if(void 0===e)return this._level;for(var r=f(e),t=this.streams.length,s=0;s<t;s++)this.streams[s].level=r;this._level=r},u.prototype.levels=function(e,r){if(void 0===e)return this.streams.map(function(e){return e.level});var t;if("number"==typeof e){if(t=this.streams[e],void 0===t)throw new Error("invalid stream index: "+e)}else{for(var s=this.streams.length,i=0;i<s;i++){var n=this.streams[i];if(n.name===e){t=n;break}}if(!t)throw new Error(w('no stream with name "%s"',e))}if(void 0===r)return t.level;var o=f(r);t.level=o,o<this._level&&(this._level=o)},u.prototype._applySerializers=function(e,r){var t=this;Object.keys(this.serializers).forEach(function(s){if(!(void 0===e[s]||r&&r[s]))try{e[s]=t.serializers[s](e[s])}catch(i){o(w('bunyan: ERROR: Exception thrown from the "%s" Bunyan serializer. This should never happen. This is a bugin that serializer function.\n%s',s,i.stack||i)),e[s]=w('(Error in Bunyan log "%s" serializer broke field. See stderr for details.)',s)}})},u.prototype._emit=function(e,r){var t;if(void 0===this.haveNonRawStreams)for(this.haveNonRawStreams=!1,t=0;t<this.streams.length;t++)if(!this.streams[t].raw){this.haveNonRawStreams=!0;break}var s;if(r||this.haveNonRawStreams)try{s=JSON.stringify(e,v())+"\n"}catch(i){var l=i.stack.split(/\n/g,2).join("\n");o('bunyan: ERROR: Exception in `JSON.stringify(rec)`. You can install the "safe-json-stringify" module to have Bunyan fallback to safer stringification. Record:\n'+n(w("%s\n%s",e,i.stack)),l),s=w("(Exception in JSON.stringify(rec): %j. See stderr for details.)\n",i.message)}if(r)return s;var a=e.level;for(t=0;t<this.streams.length;t++){var c=this.streams[t];c.level<=a&&c.stream.write(e)}return s},u.prototype.trace=p(E),u.prototype.debug=p(S),u.prototype.info=p(x),u.prototype.warn=p(z),u.prototype.error=p(O),u.prototype.fatal=p(j),u.stdSerializers={},u.stdSerializers.err=function(e){if(!e||!e.stack)return e;var r={message:e.message,name:e.name,stack:h(e),code:e.code,signal:e.signal};return r},r.exports=u,r.exports.TRACE=E,r.exports.DEBUG=S,r.exports.INFO=x,r.exports.WARN=z,r.exports.ERROR=O,r.exports.FATAL=j,r.exports.resolveLevel=f,r.exports.levelFromName=k,r.exports.nameFromLevel=N,r.exports.VERSION=y,r.exports.LOG_VERSION=d,r.exports.createLogger=function(e){return new u(e)},r.exports.safeCycles=v,r.exports.ConsoleFormattedStream=c,r.exports.ConsoleRawStream=a},{}]},{},[1])(1)});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e.bunyan={})}(this,function(e){"use strict";function r(e){return"string"==typeof e?h[e.toLowerCase()]:e}function t(e){return void 0===e||null===e?e:Array.isArray(e)?e.slice():"object"===(void 0===e?"undefined":d(e))?Object.assign({},e):e}function i(e){return void 0===e?"undefined":null===e?"null":Array.isArray(e)?"[ "+e.map(function(e){return i(e)}).join(", ")+" ]":"object"===(void 0===e?"undefined":d(e))?JSON.stringify(e):"function"==typeof e?"[Function: "+e.name+"]":"boolean"==typeof e||"number"==typeof e?e:"'"+e.toString()+"'"}function s(e){if("string"!=typeof e){for(var r=new Array(arguments.length),t=0;t<arguments.length;t++)r[t]=i(arguments[t]);return r.join(" ")}for(var s=1,n=arguments,o=n.length,l=String(e).replace(/%[sdj%]/g,function(e){if("%%"===e)return"%";if(s>=o)return e;switch(e){case"%s":return String(n[s++]);case"%d":return Number(n[s++]);case"%j":try{return JSON.stringify(n[s++])}catch(e){return"[Circular]"}default:return e}}),a=n[s];s<o;a=n[++s])l+=" "+a;return l}function n(e,r){var t=e.split("\n");t[0]&&t[0].indexOf(g)>=0&&t.shift();var i=t[r],s=null;if(i){var n=/^\s*(at|.*@)\s*(.+)?$/.exec(i);s=Array.isArray(n)&&n[2]?n[2]:i}return s}function o(e,r){return r||(r=" "),r+e.split(/\r?\n/g).join("\n"+r)}function l(e,r){if(r){if(b[r])return;b[r]=!0}console.error(e+"\n")}function a(e){return b[e]}function c(){var e=[];return function(r,t){return t&&"object"===(void 0===t?"undefined":d(t))?-1!==e.indexOf(t)?"[Circular]":(e.push(t),t):t}}function u(e){return function(){var r=this,i=null,o=arguments,c=null;if(0===arguments.length)return this._level<=e;this._level>e||(c=function(c){var u=void 0;c[0]instanceof Error?(i={err:r.serializers&&r.serializers.err?r.serializers.err(c[0]):S.err(c[0])},u={err:!0},o=1===c.length?[i.err.message]:Array.prototype.slice.call(c,1)):"object"!==d(c[0])&&null!==c[0]||Array.isArray(c[0])?(i=null,o=Array.prototype.slice.call(c)):(i=c[0],o=1===c.length&&i.err&&i.err instanceof Error?[i.err.message]:Array.prototype.slice.call(c,1));var f=t(r.fields);f.level=e;var v=i?t(i):null;if(v&&(r.serializers&&r._applySerializers(v,u),Object.keys(v).forEach(function(e){f[e]=v[e]})),f.levelName=y[e],f.msg=o.length?s.apply(r,o):"",f.time||(f.time=new Date),r.src&&!f.src)try{throw new Error(g)}catch(e){var h=n(e.stack,2);h||a("src")||l("Unable to determine src line info","src"),f.src=h||""}return f}(o),this._emit(c))}}function f(e){var r=e.stack||e.toString();if(e.cause&&"function"==typeof e.cause){var t=e.cause();t&&(r+="\nCaused by: "+f(t))}return r}function v(){for(var e=arguments.length,r=Array(e),t=0;t<e;t++)r[t]=arguments[t];return new(Function.prototype.bind.apply(k,[null].concat(r)))}var h={trace:10,debug:20,info:30,warn:40,error:50,fatal:60},y={};Object.keys(h).forEach(function(e){y[h[e]]=e});var d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},m=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},p=function(){function e(e,r){for(var t=0;t<r.length;t++){var i=r[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(r,t,i){return t&&e(r.prototype,t),i&&e(r,i),r}}(),g="call-stack-error",b={},w=function(){function e(){m(this,e)}return p(e,[{key:"write",value:function(e){e.level<30?console.log(e):e.level<40?console.info(e):e.level<50?console.warn(e):console.error(e),e.err&&e.err.stack&&console.error(e.err.stack),e.obj&&console.log(e.obj)}}]),e}(),k=function(){function e(r,i,s){var n=this;if(m(this,e),!(this instanceof e))return new e(r,i);var o=void 0;if(void 0!==i&&(o=r,r=i,!(o instanceof e)))throw new TypeError("invalid Logger creation: do not pass a second arg");if(!r)throw new TypeError("options (object) is required");if(o){if(r.name)throw new TypeError("invalid options.name: child cannot set logger name")}else if(!r.name)throw new TypeError("options.name (string) is required");if(r.stream&&r.streams)throw new TypeError('cannot mix "streams" and "stream" options');if(r.streams&&!Array.isArray(r.streams))throw new TypeError("invalid options.streams: must be an array");if(r.serializers&&("object"!==d(r.serializers)||Array.isArray(r.serializers)))throw new TypeError("invalid options.serializers: must be an object");var l=void 0,a=void 0,c=void 0;if(o&&s){this._level=o._level,this.streams=o.streams,this.serializers=o.serializers,this.src=o.src,l=this.fields={};var u=Object.keys(o.fields);for(c=0;c<u.length;c++)a=u[c],l[a]=o.fields[a];var f=Object.keys(r);for(c=0;c<f.length;c++)a=f[c],l[a]=r[a]}else{if(o){for(this._level=o._level,this.streams=[],c=0;c<o.streams.length;c++){var v=t(o.streams[c]);this.streams.push(v)}this.serializers=t(o.serializers),this.src=o.src,this.fields=t(o.fields),r.level&&this.level(r.level)}else this._level=Number.POSITIVE_INFINITY,this.streams=[],this.serializers=null,this.src=!1,this.fields={};r.stream?this.addStream({type:"stream",stream:r.stream,level:r.level}):r.streams?r.streams.forEach(function(e){n.addStream(e,r.level)}):o&&r.level?this.level(r.level):o||this.addStream({type:"raw",stream:new w,level:r.level}),r.serializers&&this.addSerializers(r.serializers),r.src&&(this.src=!0),delete(l=t(r)).stream,delete l.level,delete l.streams,delete l.serializers,delete l.src,this.serializers&&this._applySerializers(l),Object.keys(l).forEach(function(e){n.fields[e]=l[e]})}}return p(e,[{key:"addStream",value:function(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:30;(e=t(e)).type="raw",e.level=r(e.level||i),e.level<this._level&&(this._level=e.level),this.streams.push(e),delete this.haveNonRawStreams}},{key:"addSerializers",value:function(e){var r=this;this.serializers||(this.serializers={}),Object.keys(e).forEach(function(t){var i=e[t];if("function"!=typeof i)throw new TypeError(s('invalid serializer for "%s" field: must be a function',t));r.serializers[t]=i})}},{key:"child",value:function(e,r){return new this.constructor(this,e||{},r)}},{key:"level",value:function(e){if(void 0===e)return this._level;for(var t=r(e),i=this.streams.length,s=0;s<i;s++)this.streams[s].level=t;this._level=t}},{key:"levels",value:function(e,t){if(void 0===e)return this.streams.map(function(e){return e.level});var i=void 0;if("number"==typeof e){if(void 0===(i=this.streams[e]))throw new Error("invalid stream index: "+e)}else{for(var n=this.streams.length,o=0;o<n;o++){var l=this.streams[o];if(l.name===e){i=l;break}}if(!i)throw new Error(s('no stream with name "%s"',e))}if(void 0===t)return i.level;var a=r(t);i.level=a,a<this._level&&(this._level=a)}},{key:"_applySerializers",value:function(e,r){var t=this;Object.keys(this.serializers).forEach(function(i){if(!(void 0===e[i]||r&&r[i]))try{e[i]=t.serializers[i](e[i])}catch(r){l(s('bunyan: ERROR: Exception thrown from the "%s" Bunyan serializer. This should never happen. This is a bugin that serializer function.\n%s',i,r.stack||r)),e[i]=s('(Error in Bunyan log "%s" serializer broke field. See stderr for details.)',i)}})}},{key:"_emit",value:function(e,r){var t=void 0;if(void 0===this.haveNonRawStreams)for(this.haveNonRawStreams=!1,t=0;t<this.streams.length;t++)if(!this.streams[t].raw){this.haveNonRawStreams=!0;break}var i=void 0;if(r||this.haveNonRawStreams)try{i=JSON.stringify(e,c())+"\n"}catch(r){var n=r.stack.split(/\n/g,2).join("\n");l('bunyan: ERROR: Exception in `JSON.stringify(rec)`. You can install the "safe-json-stringify" module to have Bunyan fallback to safer stringification. Record:\n'+o(s("%s\n%s",e,r.stack)),n),i=s("(Exception in JSON.stringify(rec): %j. See stderr for details.)\n",r.message)}if(r)return i;var a=e.level;for(t=0;t<this.streams.length;t++){var u=this.streams[t];u.level<=a&&u.stream.write(e)}return i}}]),e}();k.prototype.trace=u(10),k.prototype.debug=u(20),k.prototype.info=u(30),k.prototype.warn=u(40),k.prototype.error=u(50),k.prototype.fatal=u(60);var S={err:function(e){return e&&e.stack?{message:e.message,name:e.name,stack:f(e),code:e.code,signal:e.signal}:e}},z=function(){function e(){var r=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).logByLevel,t=void 0!==r&&r;m(this,e),this.logByLevel=!!t}return p(e,[{key:"write",value:function(e){var r=void 0,t=void 0,i=e.childName?e.name+"/"+e.childName:e.name,s=y[e.level],n=(Array(6-s.length).join(" ")+s).toUpperCase();this.logByLevel?(10===e.level?s="debug":60===e.level&&(s="error"),t="function"==typeof console[s]?console[s]:console.log):t=console.log,r=e.level<20?"color: DeepPink":e.level<30?"color: GoldenRod":e.level<40?"color: DarkTurquoise":e.level<50?"color: Purple":e.level<60?"color: Crimson":"color: Black";var o=function(e,r){return Array(r+1-(e+"").length).join("0")+e},l=[];l.push("[%s:%s:%s:%s] %c%s%c: %s: %c%s %c%s"),l.push(o(e.time.getHours(),2)),l.push(o(e.time.getMinutes(),2)),l.push(o(e.time.getSeconds(),2)),l.push(o(e.time.getMilliseconds(),4)),l.push(r),l.push(n),l.push("color: DimGray"),l.push(i),l.push("color: SteelBlue"),l.push(e.msg),e.src&&(l.push("color: DimGray; font-style: italic; font-size: 0.9em"),l.push(e.src)),t.apply(console,l),e.err&&e.err.stack&&t.call(console,"%c%s,",r,e.err.stack),e.obj&&t.call(console,e.obj)}}]),e}();e.TRACE=10,e.DEBUG=20,e.INFO=30,e.WARN=40,e.ERROR=50,e.FATAL=60,e.resolveLevel=r,e.levelFromName=h,e.nameFromLevel=y,e.stdSerializers=S,e.Logger=k,e.createLogger=v,e.safeCycles=c,e.ConsoleFormattedStream=z,e.ConsoleRawStream=w,Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "browser-bunyan",
"version": "0.4.0",
"description": "A fork of Bunyan specifically for the browser",
"version": "1.0.0-pre",
"description": "Bunyan logging specifically for the browser",
"author": "Phil Mander <philip.mander@gmail.com>",
"main": "./lib/bunyan.js",
"main": "./lib/index.js",
"repository": {

@@ -18,16 +18,26 @@ "type": "git",

],
"scripts" : {
"test" : "node_modules/nodeunit/bin/nodeunit test/*.test.js"
"scripts": {
"lint": "eslint src",
"prepublish": "npm run lint && npm test && npm run build",
"build": "babel src --out-dir lib && rollup -c",
"test": "babel-tap test/*.test.js"
},
"devDependencies": {
"browserify": "^9.0.4",
"del": "^1.1.1",
"gulp": "^3.8.11",
"gulp-insert": "^0.5.0",
"gulp-jshint": "^1.10.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.1.0",
"nodeunit": "^0.10.2",
"verror": "^1.8.1",
"vinyl-source-stream": "^1.1.0"
"babel-cli": "^6.26.0",
"babel-core": "^6.25.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^6.4.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-module-resolver": "^2.7.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.5.2",
"babel-tap": "^5.0.0",
"eslint": "^4.5.0",
"rollup": "^0.52.0",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-uglify": "^2.0.1",
"rollup-plugin-uglify-es": "0.0.1"
},

@@ -37,5 +47,10 @@ "licenses": [

"type": "MIT",
"url": "https://github.com/philmander/browser-bunyan/blob/master/LICENSE.txt"
"url": "https://github.com/philmander/browser-bunyan/blob/master/LICENSE"
}
]
],
"babel": {
"presets": [
"env"
]
}
}
[![Build Status](https://travis-ci.org/philmander/browser-bunyan.svg?branch=master)](https://travis-ci.org/philmander/browser-bunyan)
I created this project because I wanted a version of, the awesome logging framework, Bunyan specifically for the
browser. Although Bunyan does support being browserified, it is still a bit bloated with
features which aren't relevant in a browser environment.
This package is an adaptation of, the Node logging library, [Bunyan](https://github.com/trentm/node-bunyan) but specifically for the browser.
Although Bunyan does support being [Browserified](https://github.com/trentm/node-bunyan#browserify), it is still a bit bloated with
features which aren't relevant in a browser environment. You can expect a Browserified and Gzipped `node-bunyan` to
be around **27kb** whereas `browser-bunyan` is < **4kb**, including its built-in log streams. With ES Modules and
tree-shaking this can be reduced further.
## Install
Install with NPM or Bower respectively:
`
```
npm install browser-bunyan --save
`
```
`
bower install browser-bunyan --save
`
or just copy the script from this repository's `/dist` directory.

@@ -23,16 +20,32 @@

To use as a **global**, include as a standard script tag:
### Import
`<script src=node_modules/browser-bunyan/dist/browser-bunyan.min.js></script>`
You can access Browser Bunyan's API using:
now `bunyan` will be available on the `window` object
#### ES modules:
Or, to use with **Browserify** or **Webpack**:
```javascript
import { createLogger } from 'browser-bunyan';
```
`
var bunyan = require('browser-bunyan');
`
#### CommonJS
Naturally, Browser Bunyan can also be *imported* using ES6 module syntax or used with an AMD loader.
```javascript
const { createLogger } = require('browser-bunyan');
```
#### Browser global
To use as a **global**, include as a standard script tag:
```html
<script src=node_modules/browser-bunyan/dist/browser-bunyan.min.js></script>
```
now `bunyan` will be available as a global.
```javascript
const log = bunyan.createLogger(...);
```
### Built-in Log Streams

@@ -45,11 +58,13 @@

```javascript
var log = bunyan.createLogger({
import { createLogger, ConsoleFormattedStream, INFO, stdSerializers } from 'browser-bunyan';
const log = createLogger({
name: 'myLogger',
streams: [
{
level: 'info',
stream: new bunyan.ConsoleFormattedStream()
level: INFO, // or use the string 'info'
stream: new ConsoleFormattedStream()
}
],
serializers: bunyan.stdSerializers,
serializers: stdSerializers,
src: true

@@ -71,7 +86,9 @@ });

```javascript
var log = bunyan.createLogger({
import { createLogger, ConsoleRawStream, INFO } from 'browser-bunyan';
const log = createLogger({
name: 'myLogger',
stream: {
level: 'info',
stream: new bunyan.ConsoleRawStream()
level: INFO,
stream: new ConsoleRawStream()
}

@@ -81,2 +98,34 @@ });

### Conditional logging
If a stream's log level is set to `info` then `debug` and `trace` messages will not be
logged. So this is fine:
```
logger.debug('Sent fetch request');
```
However, if you need to do some computation which is passed to your logger statement
in `debug`, then this is inefficient if the log level is higher than 'debug'.
Therefore you should conditionally execute the logger statement:
```javascript
import { DEBUG, createLogger, ConsoleRawStream } from 'browser-bunyan';
const log = createLogger({
name: 'myLogger',
stream: {
level,
stream: new ConsoleRawStream()
}
});
// do some stuff
const req = fetchStuff();
if(log.level() <= DEBUG) {
log.debug('Make fetch request');
log.debug(JSON.stringify(req));
}
```
#### Custom log streams

@@ -86,3 +135,3 @@

### Angular integration:
### Angular 1.x integration:

@@ -649,4 +698,2 @@ Integrate with Angular's log provider:

# Versioning

@@ -653,0 +700,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc