browser-bunyan
Advanced tools
Comparing version 1.0.0 to 1.0.1
# bunyan Changelog | ||
## 1.0.1 | ||
- Major README updates | ||
- Restore missing `v` field in log record | ||
## 1.0.0 | ||
@@ -4,0 +8,0 @@ - Internals reworked. Better modularization, some ES6 features. Packaged with Rollup |
@@ -1,1 +0,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})}); | ||
!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]):z.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.v=k,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(S,[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=0,S=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}();S.prototype.trace=u(10),S.prototype.debug=u(20),S.prototype.info=u(30),S.prototype.warn=u(40),S.prototype.error=u(50),S.prototype.fatal=u(60);var z={err:function(e){return e&&e.stack?{message:e.message,name:e.name,stack:f(e),code:e.code,signal:e.signal}:e}},j=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=z,e.Logger=S,e.createLogger=v,e.safeCycles=c,e.ConsoleFormattedStream=j,e.ConsoleRawStream=w,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -22,2 +22,4 @@ 'use strict'; | ||
var LOG_VERSION = 0; | ||
//---- Logger class | ||
@@ -58,2 +60,3 @@ | ||
*/ | ||
var Logger = function () { | ||
@@ -544,2 +547,3 @@ function Logger(options, _childOptions, _childSimple) { | ||
} | ||
rec.v = LOG_VERSION; | ||
return rec; | ||
@@ -546,0 +550,0 @@ } |
{ | ||
"name": "browser-bunyan", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Bunyan logging specifically for the browser", | ||
@@ -5,0 +5,0 @@ "author": "Phil Mander <philip.mander@gmail.com>", |
578
README.md
@@ -0,1 +1,4 @@ | ||
browser-bunyan | ||
=========== | ||
[![Build Status](https://travis-ci.org/philmander/browser-bunyan.svg?branch=master)](https://travis-ci.org/philmander/browser-bunyan) | ||
@@ -10,2 +13,6 @@ | ||
## Current status | ||
Browser Bunyan was originally forked from an already mature library with a rich feature set and stable API. Furthermore, the browser environment is less complex that server (no streams etc). Consequently, I've found it doesn't need much work. Hopefully this is a testament to the quality of the codebase. So, don't be too concerned if you don't see that much activity in this repo. Please do raise issues for bugs, feature requests and ideas. | ||
## Install | ||
@@ -17,4 +24,2 @@ | ||
or just copy the script from this repository's `/dist` directory. | ||
## Usage | ||
@@ -30,2 +35,4 @@ | ||
import { createLogger } from 'browser-bunyan'; | ||
const logger = createLogger({ name: 'my-logger' }); | ||
logger.info('hi on info'); | ||
``` | ||
@@ -37,2 +44,4 @@ | ||
const { createLogger } = require('browser-bunyan'); | ||
const logger = createLogger({ name: 'my-logger' }); | ||
logger.debug('hi on debug'); | ||
``` | ||
@@ -45,3 +54,3 @@ | ||
```html | ||
<script src=node_modules/browser-bunyan/dist/browser-bunyan.min.js></script> | ||
<script src="node_modules/browser-bunyan/dist/browser-bunyan.min.js"></script> | ||
``` | ||
@@ -52,3 +61,4 @@ | ||
```javascript | ||
const log = bunyan.createLogger(...); | ||
const logger = bunyan.createLogger({ name: 'my-logger' }); | ||
logger.warn('hi on warning'); | ||
``` | ||
@@ -63,4 +73,9 @@ | ||
The core library also includes a dedicated browser console stream with nice formatting. Use it like this: | ||
The core library also includes a dedicated browser console stream with nice formatting: | ||
<img src="https://versatile.nl/images/browser-bunyan.png"> | ||
Use it like this: | ||
```javascript | ||
@@ -87,3 +102,3 @@ import { createLogger, ConsoleFormattedStream, INFO, stdSerializers } from 'browser-bunyan'; | ||
`new bunyan.ConsoleFormattedStream( { logByLevel: true } );` | ||
`new ConsoleFormattedStream( { logByLevel: true } );` | ||
@@ -106,34 +121,2 @@ #### Console Raw Stream | ||
### 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 | ||
@@ -143,26 +126,7 @@ | ||
### Angular 1.x integration: | ||
## Browser specific features | ||
Integrate with Angular's log provider: | ||
```javascript | ||
adminApp.config(function($provide) { | ||
$provide.decorator('$log', function($delegate) { | ||
$delegate = bunyan.createLogger({ | ||
name: 'myLogger', | ||
streams: [{ | ||
level: 'info', | ||
stream: new bunyan.ConsoleFormattedStream(), | ||
}] | ||
}); | ||
return $delegate; | ||
}); | ||
}); | ||
``` | ||
### Browser specific features | ||
#### Logging objects to the console | ||
As per, Bunyan's [log API](#log-method-api), if you log an object under the | ||
As per, Bunyan's [log API](#log-method-api), if you log an object under the | ||
field `obj` as the first argument, Browser Bunyan's built-in log streams will log this object | ||
@@ -173,3 +137,3 @@ directly to the console: | ||
var myObject = { x: 1, y: 2 }; | ||
logger.info({ obj: myObject }, 'This is my object:'); | ||
logger.info({ obj: myObject }, 'This is my object:'); | ||
``` | ||
@@ -182,67 +146,18 @@ | ||
===================================== | ||
## Features shared with Node Bunyan | ||
## Docs from Bunyan | ||
**The following docs are the [node-bunyan](https://github.com/trentm/node-bunyan) docs at time of forking, with necessary | ||
modifications and documentation for the stripped features also removed:** | ||
The following docs are the [node-bunyan](https://github.com/trentm/node-bunyan) docs at time of forking, with necessary | ||
modifications and documentation for the stripped features also removed: | ||
### Overview of features | ||
Bunyan is **a simple and fast JSON logging library** for node.js services: | ||
var bunyan = require('browser-bunyan'); | ||
var log = bunyan.createLogger({name: "myapp"}); | ||
log.info("hi"); | ||
and **a `bunyan` CLI tool** for nicely viewing those logs: | ||
![bunyan CLI screenshot](https://raw.github.com/trentm/node-bunyan/master/tools/screenshot1.png) | ||
Manifesto: Server logs should be structured. JSON's a good format. Let's do | ||
that. A log record is one line of `JSON.stringify`'d output. Let's also | ||
specify some common names for the requisite and common fields for a log | ||
record (see below). | ||
Also: log4j is way more than you need. | ||
# Current Status | ||
Solid core functionality is there. Joyent is using this for a number of | ||
production services. Bunyan supports node 0.6 and greater. Follow | ||
<a href="https://twitter.com/intent/user?screen_name=trentmick" target="_blank">@trentmick</a> | ||
for updates to Bunyan. | ||
There is an email discussion list | ||
[bunyan-logging@googlegroups.com](mailto:bunyan-logging@googlegroups.com), | ||
also [as a forum in the | ||
browser](https://groups.google.com/forum/?fromgroups#!forum/bunyan-logging). | ||
# Installation | ||
npm install browser-bunyan | ||
**Tip**: The `bunyan` CLI tool is written to be compatible (within reason) with | ||
all versions of Bunyan logs. Therefore you might want to `npm install -g bunyan` | ||
to get the bunyan CLI on your PATH, then use local bunyan installs for | ||
node.js library usage of bunyan in your apps. | ||
# Features | ||
- elegant [log method API](#log-method-api) | ||
- extensible [streams](#streams) system for controlling where log records | ||
go (to a stream, to a file, [log file rotation](#stream-type-rotating-file), | ||
etc.) | ||
- [`bunyan` CLI](#cli-usage) for pretty-printing and filtering of Bunyan logs | ||
- simple include of log call source location (file, line, function) with | ||
go (to the console, local storage, the server, etc) | ||
[`src: true`](#src) | ||
- lightweight specialization of Logger instances with [`log.child`](#logchild) | ||
- custom rendering of logged objects with ["serializers"](#serializers) | ||
- [Runtime log snooping via Dtrace support](#runtime-log-snooping-via-dtrace) | ||
- Support for [browserify](http://browserify.org/). See [Browserify | ||
section](#browserify) below. | ||
# Introduction | ||
### Introduction | ||
@@ -252,8 +167,8 @@ Like most logging libraries you create a Logger instance and call methods | ||
$ cat hi.js | ||
var bunyan = require('browser-bunyan'); | ||
var log = bunyan.createLogger({name: 'myapp'}); | ||
log.info('hi'); | ||
log.warn({lang: 'fr'}, 'au revoir'); | ||
```javascript | ||
const { createLogger } = require('browser-bunyan'); | ||
const log = createLogger({name: 'myapp'}); | ||
log.info('hi'); | ||
log.warn({lang: 'fr'}, 'au revoir'); | ||
``` | ||
All loggers must provide a "name". This is somewhat akin to the log4j logger | ||
@@ -265,29 +180,31 @@ "name", but Bunyan doesn't do hierarchical logger names. | ||
$ node hi.js | ||
```json | ||
{"name":"myapp","hostname":"banana.local","pid":40161,"level":30,"msg":"hi","time":"2013-01-04T18:46:23.851Z","v":0} | ||
{"name":"myapp","hostname":"banana.local","pid":40161,"level":40,"lang":"fr","msg":"au revoir","time":"2013-01-04T18:46:23.853Z","v":0} | ||
``` | ||
### Log Method API | ||
## Log Method API | ||
The example above shows two different ways to call `log.info(...)`. The | ||
full API is: | ||
log.info(); // Returns a boolean: is the "info" level enabled? | ||
// This is equivalent to `log.isInfoEnabled()` or | ||
// `log.isEnabledFor(INFO)` in log4j. | ||
```javascript | ||
log.info(); // Returns a boolean: is the "info" level enabled? | ||
// This is equivalent to `log.isInfoEnabled()` or | ||
// `log.isEnabledFor(INFO)` in log4j. | ||
log.info('hi'); // Log a simple string message (or number). | ||
log.info('hi %s', bob, anotherVar); // Uses `util.format` for msg formatting. | ||
log.info('hi'); // Log a simple string message (or number). | ||
log.info('hi %s', bob, anotherVar); // Uses `util.format` for msg formatting. | ||
log.info({foo: 'bar'}, 'hi'); | ||
// Adds "foo" field to log record. You can add any number | ||
// of additional fields here. | ||
log.info({foo: 'bar'}, 'hi'); | ||
// Adds "foo" field to log record. You can add any number | ||
// of additional fields here. | ||
log.info(err); // Special case to log an `Error` instance to the record. | ||
// This adds an "err" field with exception details | ||
// (including the stack) and sets "msg" to the exception | ||
// message. | ||
log.info(err, 'more on this: %s', more); | ||
// ... or you can specify the "msg". | ||
log.info(err); // Special case to log an `Error` instance to the record. | ||
// This adds an "err" field with exception details | ||
// (including the stack) and sets "msg" to the exception | ||
// message. | ||
log.info(err, 'more on this: %s', more); | ||
// ... or you can specify the "msg". | ||
``` | ||
@@ -309,13 +226,15 @@ Note that this implies **you cannot pass any object as the first argument | ||
### Streams Introduction | ||
## Streams Introduction | ||
By default, log output is to stdout and at the "info" level. Explicitly that | ||
By default, log output is to console and at the "info" level. Explicitly that | ||
looks like: | ||
var log = bunyan.createLogger({ | ||
name: 'myapp', | ||
stream: process.stdout, | ||
level: 'info' | ||
}); | ||
```javascript | ||
import { createLogger, ConsoleRawStream } from 'browser-bunyan'; | ||
var log = createLogger({ | ||
name: 'myapp', | ||
stream: new ConsoleRawStream() | ||
level: 'info' | ||
}); | ||
``` | ||
@@ -325,15 +244,17 @@ That is an abbreviated form for a single stream. **You can define multiple | ||
var log = bunyan.createLogger({ | ||
name: 'myapp', | ||
streams: [ | ||
{ | ||
level: 'info', | ||
stream: process.stdout // log INFO and above to stdout | ||
}, | ||
{ | ||
level: 'error', | ||
path: '/var/tmp/myapp-error.log' // log ERROR and above to a file | ||
} | ||
] | ||
}); | ||
```javascript | ||
const log = createLogger({ | ||
name: 'myapp', | ||
streams: [ | ||
{ | ||
level: 'info', | ||
stream: new ConsoleRawStream() // log INFO and above to console | ||
}, | ||
{ | ||
level: 'error', | ||
path: new PostToServerStream() // record errors on the server | ||
} | ||
] | ||
}); | ||
``` | ||
@@ -343,3 +264,3 @@ More on streams in the [Streams section](#streams) below. | ||
## log.child | ||
### log.child | ||
@@ -355,4 +276,5 @@ Bunyan has a concept of a child logger to **specialize a logger for a | ||
var bunyan = require('browser-bunyan'); | ||
var log = bunyan.createLogger({name: 'myapp'}); | ||
```javascript | ||
const { createLogger } = require('browser-bunyan'); | ||
const log = createLogger({name: 'myapp'}); | ||
@@ -371,34 +293,15 @@ function Wuzzle(options) { | ||
log.info('done'); | ||
``` | ||
Running that looks like (raw): | ||
$ node myapp.js | ||
{"name":"myapp","hostname":"myhost","pid":34572,"level":30,"msg":"start","time":"2013-01-04T07:47:25.814Z","v":0} | ||
{"name":"myapp","hostname":"myhost","pid":34572,"widget_type":"wuzzle","level":30,"msg":"creating a wuzzle","time":"2013-01-04T07:47:25.815Z","v":0} | ||
{"name":"myapp","hostname":"myhost","pid":34572,"widget_type":"wuzzle","level":40,"msg":"This wuzzle is woosey.","time":"2013-01-04T07:47:25.815Z","v":0} | ||
{"name":"myapp","hostname":"myhost","pid":34572,"level":30,"msg":"done","time":"2013-01-04T07:47:25.816Z","v":0} | ||
```json | ||
{"name":"myapp","level":30,"msg":"start","time":"2013-01-04T07:47:25.814Z"} | ||
{"name":"myapp","widget_type":"wuzzle","level":30,"msg":"creating a wuzzle","time":"2013-01-04T07:47:25.815Z"} | ||
{"name":"myapp","widget_type":"wuzzle","level":40,"msg":"This wuzzle is woosey.","time":"2013-01-04T07:47:25.815Z"} | ||
{"name":"myapp","level":30,"msg":"done","time":"2013-01-04T07:47:25.816Z"} | ||
``` | ||
And with the `bunyan` CLI (using the "short" output mode): | ||
### Serializers | ||
$ node myapp.js | bunyan -o short | ||
07:46:42.707Z INFO myapp: start | ||
07:46:42.709Z INFO myapp: creating a wuzzle (widget_type=wuzzle) | ||
07:46:42.709Z WARN myapp: This wuzzle is woosey. (widget_type=wuzzle) | ||
07:46:42.709Z INFO myapp: done | ||
A more practical example is in the | ||
[node-restify](https://github.com/mcavage/node-restify) web framework. | ||
Restify uses Bunyan for its logging. One feature of its integration, is that | ||
if `server.use(restify.requestLogger())` is used, each restify request handler | ||
includes a `req.log` logger that is: | ||
log.child({req_id: <unique request id>}, true) | ||
Apps using restify can then use `req.log` and have all such log records | ||
include the unique request id (as "req\_id"). Handy. | ||
## Serializers | ||
Bunyan has a concept of **"serializers" to produce a JSON-able object from a | ||
@@ -412,22 +315,28 @@ JavaScript object**, so you can easily do the following: | ||
function reqSerializer(req) { | ||
return { | ||
method: req.method, | ||
url: req.url, | ||
headers: req.headers | ||
} | ||
```javascript | ||
function reqSerializer(req) { | ||
return { | ||
method: req.method, | ||
url: req.url, | ||
headers: req.headers | ||
} | ||
var log = bunyan.createLogger({ | ||
name: 'myapp', | ||
serializers: { | ||
req: reqSerializer | ||
} | ||
}); | ||
} | ||
const log = createLogger({ | ||
name: 'myapp', | ||
serializers: { | ||
req: reqSerializer | ||
} | ||
}); | ||
``` | ||
Or this: | ||
```javascript | ||
import { createLogger, stdSerializers } from 'browser-bunyan'; | ||
var log = bunyan.createLogger({ | ||
name: 'myapp', | ||
serializers: {req: bunyan.stdSerializers.req} | ||
}); | ||
const log = createLogger({ | ||
name: 'myapp', | ||
serializers: {req: stdSerializers.req} | ||
}); | ||
``` | ||
@@ -437,6 +346,9 @@ because Bunyan includes a small set of standard serializers. To use all the | ||
var log = bunyan.createLogger({ | ||
```javascript | ||
import { createLogger, stdSerializers } from 'browser-bunyan'; | ||
const log = createLogger({ | ||
... | ||
serializers: bunyan.stdSerializers | ||
serializers: stdSerializers | ||
}); | ||
``` | ||
@@ -447,3 +359,3 @@ **Note**: Your own serializers should never throw, otherwise you'll get an | ||
# Levels | ||
### Levels | ||
@@ -453,11 +365,11 @@ The log levels in bunyan are as follows. The level descriptions are best | ||
- "fatal" (60): The service/app is going to stop or become unusable now. | ||
- `fatal` (60): The service/app is going to stop or become unusable now. | ||
An operator should definitely look into this soon. | ||
- "error" (50): Fatal for a particular request, but the service/app continues | ||
- `error` (50): Fatal for a particular request, but the service/app continues | ||
servicing other requests. An operator should look at this soon(ish). | ||
- "warn" (40): A note on something that should probably be looked at by an | ||
- `warn` (40): A note on something that should probably be looked at by an | ||
operator eventually. | ||
- "info" (30): Detail on regular operation. | ||
- "debug" (20): Anything else, i.e. too verbose to be included in "info" level. | ||
- "trace" (10): Logging from external libraries used by your app or *very* | ||
- `info` (30): Detail on regular operation. | ||
- `debug` (20): Anything else, i.e. too verbose to be included in "info" level. | ||
- `trace` (10): Logging from external libraries used by your app or *very* | ||
detailed application logging. | ||
@@ -477,19 +389,20 @@ | ||
log.level() -> INFO // gets current level (lowest level of all streams) | ||
```javascript | ||
log.level() -> INFO // gets current level (lowest level of all streams) | ||
log.level(INFO) // set all streams to level INFO | ||
log.level("info") // set all streams to level INFO | ||
log.level(INFO) // set all streams to level INFO | ||
log.level("info") // set all streams to level INFO | ||
log.levels() -> [DEBUG, INFO] // get array of levels of all streams | ||
log.levels(0) -> DEBUG // get level of stream at index 0 | ||
log.levels("foo") // get level of stream with name "foo" | ||
log.levels() -> [DEBUG, INFO] // get array of levels of all streams | ||
log.levels(0) -> DEBUG // get level of stream at index 0 | ||
log.levels("foo") // get level of stream with name "foo" | ||
log.levels(0, INFO) // set level of stream 0 to INFO | ||
log.levels(0, "info") // can use "info" et al aliases | ||
log.levels("foo", WARN) // set stream named "foo" to WARN | ||
log.levels(0, INFO) // set level of stream 0 to INFO | ||
log.levels(0, "info") // can use "info" et al aliases | ||
log.levels("foo", WARN) // set stream named "foo" to WARN | ||
``` | ||
### Log Record Fields | ||
# Log Record Fields | ||
This section will describe *rules* for the Bunyan log format: field names, | ||
@@ -510,27 +423,28 @@ field meanings, required fields, etc. However, a Bunyan library doesn't | ||
{"name":"myserver","hostname":"banana.local","pid":123,"req":{"method":"GET","url":"/path?q=1#anchor","headers":{"x-hi":"Mom","connection":"close"}},"level":3,"msg":"start request","time":"2012-02-03T19:02:46.178Z","v":0} | ||
```json | ||
{"name":"myapp","req":{"method":"GET","url":"/path?q=1#anchor","headers":{"x-hi":"Mom","connection":"close"}},"level":3,"msg":"start request","time":"2012-02-03T19:02:46.178Z","v":0} | ||
``` | ||
Pretty-printed: | ||
{ | ||
"name": "myserver", | ||
"hostname": "banana.local", | ||
"pid": 123, | ||
"req": { | ||
"method": "GET", | ||
"url": "/path?q=1#anchor", | ||
"headers": { | ||
"x-hi": "Mom", | ||
"connection": "close" | ||
}, | ||
"remoteAddress": "120.0.0.1", | ||
"remotePort": 51244 | ||
}, | ||
"level": 3, | ||
"msg": "start request", | ||
"time": "2012-02-03T19:02:57.534Z", | ||
"v": 0 | ||
} | ||
```json | ||
{ | ||
"name": "myapp", | ||
"req": { | ||
"method": "GET", | ||
"url": "/path?q=1#anchor", | ||
"headers": { | ||
"x-hi": "Mom", | ||
"connection": "close" | ||
}, | ||
"remoteAddress": "120.0.0.1", | ||
"remotePort": 51244 | ||
}, | ||
"level": 3, | ||
"msg": "send request", | ||
"time": "2012-02-03T19:02:57.534Z", | ||
"v": 0 | ||
} | ||
``` | ||
Core fields: | ||
@@ -549,3 +463,2 @@ | ||
is the name of the service/app using Bunyan for logging. | ||
- `pid`: Required. Integer. Filled in automatically at Logger creation. | ||
- `time`: Required. String. Added by Bunyan. Can be overriden. | ||
@@ -573,3 +486,3 @@ The date and time of the event in [ISO 8601 | ||
... | ||
``` | ||
"err": { | ||
@@ -581,3 +494,3 @@ "message": "boom", | ||
"msg": "boom", | ||
... | ||
``` | ||
@@ -587,22 +500,21 @@ Or use the `bunyan.stdSerializers.err` serializer in your Logger and | ||
# Streams | ||
### Streams | ||
A "stream" is Bunyan's name for an output for log messages (the equivalent | ||
to a log4j Appender). Ultimately Bunyan uses a | ||
[Writable Stream](http://nodejs.org/docs/latest/api/all.html#writable_Stream) | ||
interface, but there are some additional attributes used to create and | ||
manage the stream. A Bunyan Logger instance has one or more streams. | ||
to a log4j Appender). A Bunyan Logger instance has one or more streams. | ||
In general streams are specified with the "streams" option: | ||
var bunyan = require('browser-bunyan'); | ||
var log = bunyan.createLogger({ | ||
name: "foo", | ||
streams: [ | ||
{ | ||
stream: process.stderr, | ||
level: "debug" | ||
}, | ||
... | ||
] | ||
}); | ||
```javascript | ||
const bunyan = require('browser-bunyan'); | ||
const log = createLogger({ | ||
name: "foo", | ||
streams: [ | ||
{ | ||
stream: new ConsoleRawStream(), | ||
level: "debug" | ||
}, | ||
... | ||
] | ||
}); | ||
``` | ||
@@ -612,127 +524,41 @@ For convenience, if there is only one stream, it can specified with the | ||
var log = bunyan.createLogger({ | ||
name: "foo", | ||
stream: process.stderr, | ||
level: "debug" | ||
}); | ||
```javascript | ||
const log = createLogger({ | ||
name: "foo", | ||
stream: new ConsoleRawStream(), | ||
level: "debug" | ||
}); | ||
``` | ||
Note that "file" streams do not support this shortcut (partly for historical | ||
reasons and partly to not make it difficult to add a literal "path" field | ||
on log records). | ||
If neither "streams" nor "stream" are specified, the default is a stream of | ||
type "stream" emitting to `process.stdout` at the "info" level. | ||
type `ConsoleRawStream` at the "info" level. | ||
## stream type: `raw` | ||
### stream type: `raw` | ||
- `raw`: Similar to a "stream" writeable stream, except that the write method | ||
is given raw log record *Object*s instead of a JSON-stringified string. | ||
This can be useful for hooking on further processing to all Bunyan logging: | ||
pushing to an external service, a RingBuffer (see below), etc. | ||
Note that in browser-bunyan streams are always `raw` | ||
# Browserify | ||
## Inegrations | ||
As the [Browserify](http://browserify.org/) site says it "lets you | ||
`require('modules')` in the browser by bundling up all of your dependencies." | ||
It is a build tool to run on your node.js script to bundle up your script and | ||
all its node.js dependencies into a single file that is runnable in the | ||
browser via: | ||
### Angular 1.x integration: | ||
<script src="play.browser.js"></script> | ||
Integrate with Angular's log provider: | ||
As of version 1.1.0, node-bunyan supports being run via Browserify. The | ||
default [stream](#streams) when running in the browser is one that emits | ||
raw log records to `console.log/info/warn/error`. | ||
Here is a quick example showing you how you can get this working for your | ||
script. | ||
1. Get browserify and bunyan installed in your module: | ||
$ npm install browserify bunyan | ||
2. An example script using Bunyan, "play.js": | ||
```javascript | ||
var bunyan = require('browser-bunyan'); | ||
var log = bunyan.createLogger({name: 'play', level: 'debug'}); | ||
log.trace('this one does not emit'); | ||
log.debug('hi on debug'); // console.log | ||
log.info('hi on info'); // console.info | ||
log.warn('hi on warn'); // console.warn | ||
log.error('hi on error'); // console.error | ||
``` | ||
3. Build this into a bundle to run in the browser, "play.browser.js": | ||
$ ./node_modules/.bin/browserify play.js -o play.browser.js | ||
4. Put that into an HTML file, "play.html": | ||
```html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script src="play.browser.js"></script> | ||
</head> | ||
<body> | ||
<div>hi</div> | ||
</body> | ||
</html> | ||
``` | ||
5. Open that in your browser and open your browser console: | ||
$ open play.html | ||
Here is what it looks like in Firefox's console: ![Bunyan + Browserify in the | ||
Firefox console](./docs/img/bunyan.browserify.png) | ||
For some, the raw log records might not be desired. To have a rendered log line | ||
you'll want to add your own stream, starting with something like this: | ||
```javascript | ||
var bunyan = require('./lib/bunyan'); | ||
function MyRawStream() {} | ||
MyRawStream.prototype.write = function (rec) { | ||
console.log('[%s] %s: %s', | ||
rec.time.toISOString(), | ||
bunyan.nameFromLevel[rec.level], | ||
rec.msg); | ||
} | ||
var log = bunyan.createLogger({ | ||
name: 'play', | ||
streams: [ | ||
{ | ||
level: 'info', | ||
stream: new MyRawStream(), | ||
type: 'raw' | ||
} | ||
] | ||
adminApp.config(function($provide) { | ||
$provide.decorator('$log', function($delegate) { | ||
$delegate = bunyan.createLogger({ | ||
name: 'myLogger', | ||
streams: [{ | ||
level: 'info', | ||
stream: new bunyan.ConsoleFormattedStream(), | ||
}] | ||
}); | ||
return $delegate; | ||
}); | ||
}); | ||
log.info('hi on info'); | ||
``` | ||
## License | ||
# Versioning | ||
The scheme I follow is most succintly described by the bootstrap guys | ||
[here](https://github.com/twitter/bootstrap#versioning). | ||
tl;dr: All versions are `<major>.<minor>.<patch>` which will be incremented for | ||
breaking backward compat and major reworks, new features without breaking | ||
change, and bug fixes, respectively. | ||
# License | ||
MIT. See "LICENSE.txt". | ||
MIT. See LICENSE. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1013
68336
535