diff --git a/dist/logplease.min.js b/dist/logplease.min.js index 9430b91..808e2b9 100644 --- a/dist/logplease.min.js +++ b/dist/logplease.min.js @@ -1 +1 @@ -var Logger=function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=15)}([function(t,e){var n=t.exports={version:"2.5.7"};"number"==typeof __e&&(__e=n)},function(t,e,n){t.exports=!n(2)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e,n){e.nextTick=function(t){setTimeout(t,0)},e.platform=e.arch=e.execPath=e.title="browser",e.pid=1,e.browser=!0,e.env={},e.argv=[],e.binding=function(t){throw new Error("No such module. (Possibly not yet loaded)")},function(){var t,r="/";e.cwd=function(){return r},e.chdir=function(e){t||(t=n(16)),r=t.resolve(e,r)}}(),e.exit=e.kill=e.umask=e.dlopen=e.uptime=e.memoryUsage=e.uvCounters=function(){},e.features={}},function(t,e){var n=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(t,e,n){var r=n(4),o=n(0),i=n(31),s=n(33),u=n(10),c=function(t,e,n){var l,a,f,p=t&c.F,h=t&c.G,v=t&c.S,y=t&c.P,g=t&c.B,d=t&c.W,m=h?o:o[e]||(o[e]={}),b=m.prototype,w=h?r:v?r[e]:(r[e]||{}).prototype;h&&(n=e);for(l in n)(a=!p&&w&&void 0!==w[l])&&u(m,l)||(f=a?w[l]:n[l],m[l]=h&&"function"!=typeof w[l]?n[l]:g&&a?i(f,r):d&&w[l]==f?function(t){var e=function(e,n,r){if(this instanceof t){switch(arguments.length){case 0:return new t;case 1:return new t(e);case 2:return new t(e,n)}return new t(e,n,r)}return t.apply(this,arguments)};return e.prototype=t.prototype,e}(f):y&&"function"==typeof f?i(Function.call,f):f,y&&((m.virtual||(m.virtual={}))[l]=f,t&c.R&&b&&!b[l]&&s(b,l,f)))};c.F=1,c.G=2,c.S=4,c.P=8,c.B=16,c.W=32,c.U=64,c.R=128,t.exports=c},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e,n){var r=n(8);t.exports=function(t){return Object(r(t))}},function(t,e){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,n){var r=n(20),o=n(29);t.exports=Object.keys||function(t){return r(t,o)}},function(t,e){var n={}.hasOwnProperty;t.exports=function(t,e){return n.call(t,e)}},function(t,e,n){var r=n(12),o=n(8);t.exports=function(t){return r(o(t))}},function(t,e,n){var r=n(21);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==r(t)?t.split(""):Object(t)}},function(t,e){var n=Math.ceil,r=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?r:n)(t)}},function(t,e,n){var r=n(34),o=n(35),i=n(37),s=Object.defineProperty;e.f=n(1)?Object.defineProperty:function(t,e,n){if(r(t),e=i(e,!0),r(n),o)try{return s(t,e,n)}catch(t){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(t[e]=n.value),t}},function(t,e,n){"use strict";(function(e){function r(t){return t&&t.__esModule?t:{default:t}}var o=n(17),i=r(o),s=n(39),u=r(s),c=n(45),l=r(c),a=n(46),f=r(a),p=n(50),h=n(51).format,v=n(55).EventEmitter,y=e.type&&"renderer"===e.type,g=!(y||!e.version),d={DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",ERROR:"ERROR",NONE:"NONE"},m=d.DEBUG,b=null,w=new v,_={Black:0,Red:1,Green:2,Yellow:3,Blue:4,Magenta:5,Cyan:6,Grey:7,White:9,Default:9};g||(_={Black:"Black",Red:"IndianRed",Green:"LimeGreen",Yellow:"Orange",Blue:"RoyalBlue",Magenta:"Orchid",Cyan:"SkyBlue",Grey:"DimGrey",White:"White",Default:"Black"});var x=[_.Cyan,_.Green,_.Yellow,_.Red,_.Default],O={useColors:!0,color:_.Default,showTimestamp:!0,useLocalTime:!1,showLevel:!0,filename:b,appendFile:!0},L=function(){function t(e,n){(0,l.default)(this,t),this.category=e;var r={};(0,u.default)(r,O),(0,u.default)(r,n),this.options=r,this.debug=this.debug.bind(this),this.log=this.log.bind(this),this.info=this.info.bind(this),this.warn=this.warn.bind(this),this.error=this.error.bind(this)}return(0,f.default)(t,[{key:"debug",value:function(){this._shouldLog(d.DEBUG)&&this._write(d.DEBUG,h.apply(null,arguments))}},{key:"log",value:function(){this._shouldLog(d.DEBUG)&&this.debug.apply(this,arguments)}},{key:"info",value:function(){this._shouldLog(d.INFO)&&this._write(d.INFO,h.apply(null,arguments))}},{key:"warn",value:function(){this._shouldLog(d.WARN)&&this._write(d.WARN,h.apply(null,arguments))}},{key:"error",value:function(){this._shouldLog(d.ERROR)&&this._write(d.ERROR,h.apply(null,arguments))}},{key:"_write",value:function(t,e){(this.options.filename||b)&&!this.fileWriter&&g&&(this.fileWriter=p.openSync(this.options.filename||b,this.options.appendFile?"a+":"w+"));var n=this._format(t,e),r=this._createLogMessage(t,e),o=this._createLogMessage(t,e,n.timestamp,n.level,n.category,n.text);this.fileWriter&&g&&p.writeSync(this.fileWriter,r+"\n",null,"utf-8"),g||!this.options.useColors?(console.log(o),w.emit("data",this.category,t,e)):t===d.ERROR?this.options.showTimestamp&&this.options.showLevel?console.error(o,n.timestamp,n.level,n.category,n.text):this.options.showTimestamp&&!this.options.showLevel?console.error(o,n.timestamp,n.category,n.text):!this.options.showTimestamp&&this.options.showLevel?console.error(o,n.level,n.category,n.text):console.error(o,n.category,n.text):this.options.showTimestamp&&this.options.showLevel?console.log(o,n.timestamp,n.level,n.category,n.text):this.options.showTimestamp&&!this.options.showLevel?console.log(o,n.timestamp,n.category,n.text):!this.options.showTimestamp&&this.options.showLevel?console.log(o,n.level,n.category,n.text):console.log(o,n.category,n.text)}},{key:"_format",value:function(t,e){var n="",r="",o="",s=": ";if(this.options.useColors){var u=(0,i.default)(d).map(function(t){return d[t]}).indexOf(t),c=this.options.color;g?(this.options.showTimestamp&&(n="[3"+_.Grey+"m"),this.options.showLevel&&(r="[3"+x[u]+";22m"),o="[3"+c+";1m",s=": "):(this.options.showTimestamp&&(n="color:"+_.Grey),this.options.showLevel&&(r="color:"+x[u]),o="color:"+c+"; font-weight: bold")}return{timestamp:n,level:r,category:o,text:s}}},{key:"_createLogMessage",value:function(t,e,n,r,o,i){n=n||"",r=r||"",o=o||"",i=i||": ",!g&&this.options.useColors&&(this.options.showTimestamp&&(n="%c"),this.options.showLevel&&(r="%c"),o="%c",i=": %c");var s="";return this.options.showTimestamp&&!this.options.useLocalTime&&(s+=(new Date).toISOString()+" "),this.options.showTimestamp&&this.options.useLocalTime&&(s+=(new Date).toLocaleString()+" "),s=n+s,this.options.showLevel&&(s+=r+"["+t+"]"+(t===d.INFO||t===d.WARN?" ":"")+" "),s+=o+this.category,s+=i+e}},{key:"_shouldLog",value:function(t){var n=void 0!==e&&void 0!==e.env&&void 0!==e.env.LOG?e.env.LOG.toUpperCase():null;n="undefined"!=typeof window&&window.LOG?window.LOG.toUpperCase():n;var r=n||m,o=(0,i.default)(d).map(function(t){return d[t]});return o.indexOf(t)>=o.indexOf(r)}}]),t}();t.exports={Colors:_,LogLevels:d,setLogLevel:function(t){m=t},setLogfile:function(t){b=t},create:function(t,e){return new L(t,e)},forceBrowserMode:function(t){return g=!t},events:w}}).call(e,n(3))},function(t,e,n){(function(t){function n(t,e){for(var n=0,r=t.length-1;r>=0;r--){var o=t[r];"."===o?t.splice(r,1):".."===o?(t.splice(r,1),n++):n&&(t.splice(r,1),n--)}if(e)for(;n--;n)t.unshift("..");return t}function r(t,e){if(t.filter)return t.filter(e);for(var n=[],r=0;r=-1&&!o;i--){var s=i>=0?arguments[i]:t.cwd();if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(e=s+"/"+e,o="/"===s.charAt(0))}return e=n(r(e.split("/"),function(t){return!!t}),!o).join("/"),(o?"/":"")+e||"."},e.normalize=function(t){var o=e.isAbsolute(t),i="/"===s(t,-1);return t=n(r(t.split("/"),function(t){return!!t}),!o).join("/"),t||o||(t="."),t&&i&&(t+="/"),(o?"/":"")+t},e.isAbsolute=function(t){return"/"===t.charAt(0)},e.join=function(){var t=Array.prototype.slice.call(arguments,0);return e.normalize(r(t,function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))},e.relative=function(t,n){function r(t){for(var e=0;e=0&&""===t[n];n--);return e>n?[]:t.slice(e,n-e+1)}t=e.resolve(t).substr(1),n=e.resolve(n).substr(1);for(var o=r(t.split("/")),i=r(n.split("/")),s=Math.min(o.length,i.length),u=s,c=0;cc;)r(u,n=e[c++])&&(~i(l,n)||l.push(n));return l}},function(t,e){var n={}.toString;t.exports=function(t){return n.call(t).slice(8,-1)}},function(t,e,n){var r=n(11),o=n(23),i=n(24);t.exports=function(t){return function(e,n,s){var u,c=r(e),l=o(c.length),a=i(s,l);if(t&&n!=n){for(;l>a;)if((u=c[a++])!=u)return!0}else for(;l>a;a++)if((t||a in c)&&c[a]===n)return t||a||0;return!t&&-1}}},function(t,e,n){var r=n(13),o=Math.min;t.exports=function(t){return t>0?o(r(t),9007199254740991):0}},function(t,e,n){var r=n(13),o=Math.max,i=Math.min;t.exports=function(t,e){return t=r(t),t<0?o(t+e,0):i(t,e)}},function(t,e,n){var r=n(26)("keys"),o=n(28);t.exports=function(t){return r[t]||(r[t]=o(t))}},function(t,e,n){var r=n(0),o=n(4),i=o["__core-js_shared__"]||(o["__core-js_shared__"]={});(t.exports=function(t,e){return i[t]||(i[t]=void 0!==e?e:{})})("versions",[]).push({version:r.version,mode:n(27)?"pure":"global",copyright:"© 2018 Denis Pushkarev (zloirock.ru)"})},function(t,e){t.exports=!0},function(t,e){var n=0,r=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++n+r).toString(36))}},function(t,e){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(t,e,n){var r=n(5),o=n(0),i=n(2);t.exports=function(t,e){var n=(o.Object||{})[t]||Object[t],s={};s[t]=e(n),r(r.S+r.F*i(function(){n(1)}),"Object",s)}},function(t,e,n){var r=n(32);t.exports=function(t,e,n){if(r(t),void 0===e)return t;switch(n){case 1:return function(n){return t.call(e,n)};case 2:return function(n,r){return t.call(e,n,r)};case 3:return function(n,r,o){return t.call(e,n,r,o)}}return function(){return t.apply(e,arguments)}}},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,e,n){var r=n(14),o=n(38);t.exports=n(1)?function(t,e,n){return r.f(t,e,o(1,n))}:function(t,e,n){return t[e]=n,t}},function(t,e,n){var r=n(6);t.exports=function(t){if(!r(t))throw TypeError(t+" is not an object!");return t}},function(t,e,n){t.exports=!n(1)&&!n(2)(function(){return 7!=Object.defineProperty(n(36)("div"),"a",{get:function(){return 7}}).a})},function(t,e,n){var r=n(6),o=n(4).document,i=r(o)&&r(o.createElement);t.exports=function(t){return i?o.createElement(t):{}}},function(t,e,n){var r=n(6);t.exports=function(t,e){if(!r(t))return t;var n,o;if(e&&"function"==typeof(n=t.toString)&&!r(o=n.call(t)))return o;if("function"==typeof(n=t.valueOf)&&!r(o=n.call(t)))return o;if(!e&&"function"==typeof(n=t.toString)&&!r(o=n.call(t)))return o;throw TypeError("Can't convert object to primitive value")}},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e,n){t.exports={default:n(40),__esModule:!0}},function(t,e,n){n(41),t.exports=n(0).Object.assign},function(t,e,n){var r=n(5);r(r.S+r.F,"Object",{assign:n(42)})},function(t,e,n){"use strict";var r=n(9),o=n(43),i=n(44),s=n(7),u=n(12),c=Object.assign;t.exports=!c||n(2)(function(){var t={},e={},n=Symbol(),r="abcdefghijklmnopqrst";return t[n]=7,r.split("").forEach(function(t){e[t]=t}),7!=c({},t)[n]||Object.keys(c({},e)).join("")!=r})?function(t,e){for(var n=s(t),c=arguments.length,l=1,a=o.f,f=i.f;c>l;)for(var p,h=u(arguments[l++]),v=a?r(h).concat(a(h)):r(h),y=v.length,g=0;y>g;)f.call(h,p=v[g++])&&(n[p]=h[p]);return n}:c},function(t,e){e.f=Object.getOwnPropertySymbols},function(t,e){e.f={}.propertyIsEnumerable},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(47),o=function(t){return t&&t.__esModule?t:{default:t}}(r);e.default=function(){function t(t,e){for(var n=0;n=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),y(n)?r.showHidden=n:n&&e._extend(r,n),_(r.showHidden)&&(r.showHidden=!1),_(r.depth)&&(r.depth=2),_(r.colors)&&(r.colors=!1),_(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=i),c(r,t,r.depth)}function i(t,e){var n=o.styles[e];return n?"["+o.colors[n][0]+"m"+t+"["+o.colors[n][1]+"m":t}function s(t,e){return t}function u(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}function c(t,n,r){if(t.customInspect&&n&&E(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var o=n.inspect(r,t);return b(o)||(o=c(t,o,r)),o}var i=l(t,n);if(i)return i;var s=Object.keys(n),y=u(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(n)),j(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return a(n);if(0===s.length){if(E(n)){var g=n.name?": "+n.name:"";return t.stylize("[Function"+g+"]","special")}if(x(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(L(n))return t.stylize(Date.prototype.toString.call(n),"date");if(j(n))return a(n)}var d="",m=!1,w=["{","}"];if(v(n)&&(m=!0,w=["[","]"]),E(n)){d=" [Function"+(n.name?": "+n.name:"")+"]"}if(x(n)&&(d=" "+RegExp.prototype.toString.call(n)),L(n)&&(d=" "+Date.prototype.toUTCString.call(n)),j(n)&&(d=" "+a(n)),0===s.length&&(!m||0==n.length))return w[0]+d+w[1];if(r<0)return x(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special");t.seen.push(n);var _;return _=m?f(t,n,r,y,s):s.map(function(e){return p(t,n,r,y,e,m)}),t.seen.pop(),h(_,d,w)}function l(t,e){if(_(e))return t.stylize("undefined","undefined");if(b(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}return m(e)?t.stylize(""+e,"number"):y(e)?t.stylize(""+e,"boolean"):g(e)?t.stylize("null","null"):void 0}function a(t){return"["+Error.prototype.toString.call(t)+"]"}function f(t,e,n,r,o){for(var i=[],s=0,u=e.length;s-1&&(u=i?u.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+u.split("\n").map(function(t){return" "+t}).join("\n"))):u=t.stylize("[Circular]","special")),_(s)){if(i&&o.match(/^\d+$/))return u;s=JSON.stringify(""+o),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+u}function h(t,e,n){var r=0;return t.reduce(function(t,e){return r++,e.indexOf("\n")>=0&&r++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60?n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1]:n[0]+e+" "+t.join(", ")+" "+n[1]}function v(t){return Array.isArray(t)}function y(t){return"boolean"==typeof t}function g(t){return null===t}function d(t){return null==t}function m(t){return"number"==typeof t}function b(t){return"string"==typeof t}function w(t){return"symbol"==typeof t}function _(t){return void 0===t}function x(t){return O(t)&&"[object RegExp]"===k(t)}function O(t){return"object"==typeof t&&null!==t}function L(t){return O(t)&&"[object Date]"===k(t)}function j(t){return O(t)&&("[object Error]"===k(t)||t instanceof Error)}function E(t){return"function"==typeof t}function S(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t}function k(t){return Object.prototype.toString.call(t)}function R(t){return t<10?"0"+t.toString(10):t.toString(10)}function M(){var t=new Date,e=[R(t.getHours()),R(t.getMinutes()),R(t.getSeconds())].join(":");return[t.getDate(),z[t.getMonth()],e].join(" ")}function T(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var N=/%[sdj%]/g;e.format=function(t){if(!b(t)){for(var e=[],n=0;n=i)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return t}}),u=r[n];n0&&this._events[t].length>o&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace()),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function n(){this.removeListener(t,n),o||(o=!0,e.apply(this,arguments))}if(!r(e))throw TypeError("listener must be a function");var o=!1;return n.listener=e,this.on(t,n),this},n.prototype.removeListener=function(t,e){var n,o,s,u;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],s=n.length,o=-1,n===e||r(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(i(n)){for(u=s;u-- >0;)if(n[u]===e||n[u].listener&&n[u].listener===e){o=u;break}if(o<0)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(o,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],r(n))this.removeListener(t,n);else if(n)for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){return this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(r(e))return 1;if(e)return e.length}return 0},n.listenerCount=function(t,e){return t.listenerCount(e)}}]); \ No newline at end of file +var Logger=function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=15)}([function(t,e){var n=t.exports={version:"2.5.7"};"number"==typeof __e&&(__e=n)},function(t,e,n){t.exports=!n(2)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e,n){e.nextTick=function(t){setTimeout(t,0)},e.platform=e.arch=e.execPath=e.title="browser",e.pid=1,e.browser=!0,e.env={},e.argv=[],e.binding=function(t){throw new Error("No such module. (Possibly not yet loaded)")},function(){var t,r="/";e.cwd=function(){return r},e.chdir=function(e){t||(t=n(16)),r=t.resolve(e,r)}}(),e.exit=e.kill=e.umask=e.dlopen=e.uptime=e.memoryUsage=e.uvCounters=function(){},e.features={}},function(t,e){var n=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(t,e,n){var r=n(4),o=n(0),i=n(31),s=n(33),u=n(10),c=function(t,e,n){var l,a,f,p=t&c.F,h=t&c.G,v=t&c.S,y=t&c.P,g=t&c.B,d=t&c.W,m=h?o:o[e]||(o[e]={}),b=m.prototype,w=h?r:v?r[e]:(r[e]||{}).prototype;h&&(n=e);for(l in n)(a=!p&&w&&void 0!==w[l])&&u(m,l)||(f=a?w[l]:n[l],m[l]=h&&"function"!=typeof w[l]?n[l]:g&&a?i(f,r):d&&w[l]==f?function(t){var e=function(e,n,r){if(this instanceof t){switch(arguments.length){case 0:return new t;case 1:return new t(e);case 2:return new t(e,n)}return new t(e,n,r)}return t.apply(this,arguments)};return e.prototype=t.prototype,e}(f):y&&"function"==typeof f?i(Function.call,f):f,y&&((m.virtual||(m.virtual={}))[l]=f,t&c.R&&b&&!b[l]&&s(b,l,f)))};c.F=1,c.G=2,c.S=4,c.P=8,c.B=16,c.W=32,c.U=64,c.R=128,t.exports=c},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e,n){var r=n(8);t.exports=function(t){return Object(r(t))}},function(t,e){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,n){var r=n(20),o=n(29);t.exports=Object.keys||function(t){return r(t,o)}},function(t,e){var n={}.hasOwnProperty;t.exports=function(t,e){return n.call(t,e)}},function(t,e,n){var r=n(12),o=n(8);t.exports=function(t){return r(o(t))}},function(t,e,n){var r=n(21);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==r(t)?t.split(""):Object(t)}},function(t,e){var n=Math.ceil,r=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?r:n)(t)}},function(t,e,n){var r=n(34),o=n(35),i=n(37),s=Object.defineProperty;e.f=n(1)?Object.defineProperty:function(t,e,n){if(r(t),e=i(e,!0),r(n),o)try{return s(t,e,n)}catch(t){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(t[e]=n.value),t}},function(t,e,n){"use strict";(function(e){function r(t){return t&&t.__esModule?t:{default:t}}var o=n(17),i=r(o),s=n(39),u=r(s),c=n(45),l=r(c),a=n(46),f=r(a),p=n(50),h=n(51).format,v=n(55).EventEmitter,y=e.type&&"renderer"===e.type,g=!(y||!e.version),d={DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",ERROR:"ERROR",NONE:"NONE"},m=d.DEBUG,b=null,w=new v,_={Black:0,Red:1,Green:2,Yellow:3,Blue:4,Magenta:5,Cyan:6,Grey:7,White:9,Default:9};g||(_={Black:"Black",Red:"IndianRed",Green:"LimeGreen",Yellow:"Orange",Blue:"RoyalBlue",Magenta:"Orchid",Cyan:"SkyBlue",Grey:"DimGrey",White:"White",Default:"Black"});var x=[_.Cyan,_.Green,_.Yellow,_.Red,_.Default],O={useColors:!0,color:_.Default,showTimestamp:!0,useLocalTime:!1,showLevel:!0,filename:b,appendFile:!0},L=function(){function t(e,n){(0,l.default)(this,t),this.category=e;var r={};(0,u.default)(r,O),(0,u.default)(r,n),this.options=r,this.debug=this.debug.bind(this),this.log=this.log.bind(this),this.info=this.info.bind(this),this.warn=this.warn.bind(this),this.error=this.error.bind(this)}return(0,f.default)(t,[{key:"debug",value:function(){this._shouldLog(d.DEBUG)&&this._write(d.DEBUG,h.apply(null,arguments))}},{key:"log",value:function(){this._shouldLog(d.DEBUG)&&this.debug.apply(this,arguments)}},{key:"info",value:function(){this._shouldLog(d.INFO)&&this._write(d.INFO,h.apply(null,arguments))}},{key:"warn",value:function(){this._shouldLog(d.WARN)&&this._write(d.WARN,h.apply(null,arguments))}},{key:"error",value:function(){this._shouldLog(d.ERROR)&&this._write(d.ERROR,h.apply(null,arguments))}},{key:"_write",value:function(t,e){!this.options.filename&&!b||this.fileWriter||!g&&!y||(this.fileWriter=p.openSync(this.options.filename||b,this.options.appendFile?"a+":"w+"));var n=this._format(t,e),r=this._createLogMessage(t,e),o=this._createLogMessage(t,e,n.timestamp,n.level,n.category,n.text);this.fileWriter&&(g||y)&&(y&&(r=r.replace(/\%c/gm,"")),p.writeSync(this.fileWriter,r+"\n",null,"utf-8")),g||!this.options.useColors?(console.log(o),w.emit("data",this.category,t,e)):t===d.ERROR?this.options.showTimestamp&&this.options.showLevel?console.error(o,n.timestamp,n.level,n.category,n.text):this.options.showTimestamp&&!this.options.showLevel?console.error(o,n.timestamp,n.category,n.text):!this.options.showTimestamp&&this.options.showLevel?console.error(o,n.level,n.category,n.text):console.error(o,n.category,n.text):this.options.showTimestamp&&this.options.showLevel?console.log(o,n.timestamp,n.level,n.category,n.text):this.options.showTimestamp&&!this.options.showLevel?console.log(o,n.timestamp,n.category,n.text):!this.options.showTimestamp&&this.options.showLevel?console.log(o,n.level,n.category,n.text):console.log(o,n.category,n.text)}},{key:"_format",value:function(t,e){var n="",r="",o="",s=": ";if(this.options.useColors){var u=(0,i.default)(d).map(function(t){return d[t]}).indexOf(t),c=this.options.color;g?(this.options.showTimestamp&&(n="[3"+_.Grey+"m"),this.options.showLevel&&(r="[3"+x[u]+";22m"),o="[3"+c+";1m",s=": "):(this.options.showTimestamp&&(n="color:"+_.Grey),this.options.showLevel&&(r="color:"+x[u]),o="color:"+c+"; font-weight: bold")}return{timestamp:n,level:r,category:o,text:s}}},{key:"_createLogMessage",value:function(t,e,n,r,o,i){n=n||"",r=r||"",o=o||"",i=i||": ",!g&&this.options.useColors&&(this.options.showTimestamp&&(n="%c"),this.options.showLevel&&(r="%c"),o="%c",i=": %c");var s="";return this.options.showTimestamp&&!this.options.useLocalTime&&(s+=(new Date).toISOString()+" "),this.options.showTimestamp&&this.options.useLocalTime&&(s+=(new Date).toLocaleString()+" "),s=n+s,this.options.showLevel&&(s+=r+"["+t+"]"+(t===d.INFO||t===d.WARN?" ":"")+" "),s+=o+this.category,s+=i+e}},{key:"_shouldLog",value:function(t){var n=void 0!==e&&void 0!==e.env&&void 0!==e.env.LOG?e.env.LOG.toUpperCase():null;n="undefined"!=typeof window&&window.LOG?window.LOG.toUpperCase():n;var r=n||m,o=(0,i.default)(d).map(function(t){return d[t]});return o.indexOf(t)>=o.indexOf(r)}}]),t}();t.exports={Colors:_,LogLevels:d,setLogLevel:function(t){m=t},setLogfile:function(t){b=t},create:function(t,e){return new L(t,e)},forceBrowserMode:function(t){return g=!t},events:w}}).call(e,n(3))},function(t,e,n){(function(t){function n(t,e){for(var n=0,r=t.length-1;r>=0;r--){var o=t[r];"."===o?t.splice(r,1):".."===o?(t.splice(r,1),n++):n&&(t.splice(r,1),n--)}if(e)for(;n--;n)t.unshift("..");return t}function r(t,e){if(t.filter)return t.filter(e);for(var n=[],r=0;r=-1&&!o;i--){var s=i>=0?arguments[i]:t.cwd();if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(e=s+"/"+e,o="/"===s.charAt(0))}return e=n(r(e.split("/"),function(t){return!!t}),!o).join("/"),(o?"/":"")+e||"."},e.normalize=function(t){var o=e.isAbsolute(t),i="/"===s(t,-1);return t=n(r(t.split("/"),function(t){return!!t}),!o).join("/"),t||o||(t="."),t&&i&&(t+="/"),(o?"/":"")+t},e.isAbsolute=function(t){return"/"===t.charAt(0)},e.join=function(){var t=Array.prototype.slice.call(arguments,0);return e.normalize(r(t,function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))},e.relative=function(t,n){function r(t){for(var e=0;e=0&&""===t[n];n--);return e>n?[]:t.slice(e,n-e+1)}t=e.resolve(t).substr(1),n=e.resolve(n).substr(1);for(var o=r(t.split("/")),i=r(n.split("/")),s=Math.min(o.length,i.length),u=s,c=0;cc;)r(u,n=e[c++])&&(~i(l,n)||l.push(n));return l}},function(t,e){var n={}.toString;t.exports=function(t){return n.call(t).slice(8,-1)}},function(t,e,n){var r=n(11),o=n(23),i=n(24);t.exports=function(t){return function(e,n,s){var u,c=r(e),l=o(c.length),a=i(s,l);if(t&&n!=n){for(;l>a;)if((u=c[a++])!=u)return!0}else for(;l>a;a++)if((t||a in c)&&c[a]===n)return t||a||0;return!t&&-1}}},function(t,e,n){var r=n(13),o=Math.min;t.exports=function(t){return t>0?o(r(t),9007199254740991):0}},function(t,e,n){var r=n(13),o=Math.max,i=Math.min;t.exports=function(t,e){return t=r(t),t<0?o(t+e,0):i(t,e)}},function(t,e,n){var r=n(26)("keys"),o=n(28);t.exports=function(t){return r[t]||(r[t]=o(t))}},function(t,e,n){var r=n(0),o=n(4),i=o["__core-js_shared__"]||(o["__core-js_shared__"]={});(t.exports=function(t,e){return i[t]||(i[t]=void 0!==e?e:{})})("versions",[]).push({version:r.version,mode:n(27)?"pure":"global",copyright:"© 2018 Denis Pushkarev (zloirock.ru)"})},function(t,e){t.exports=!0},function(t,e){var n=0,r=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++n+r).toString(36))}},function(t,e){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(t,e,n){var r=n(5),o=n(0),i=n(2);t.exports=function(t,e){var n=(o.Object||{})[t]||Object[t],s={};s[t]=e(n),r(r.S+r.F*i(function(){n(1)}),"Object",s)}},function(t,e,n){var r=n(32);t.exports=function(t,e,n){if(r(t),void 0===e)return t;switch(n){case 1:return function(n){return t.call(e,n)};case 2:return function(n,r){return t.call(e,n,r)};case 3:return function(n,r,o){return t.call(e,n,r,o)}}return function(){return t.apply(e,arguments)}}},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,e,n){var r=n(14),o=n(38);t.exports=n(1)?function(t,e,n){return r.f(t,e,o(1,n))}:function(t,e,n){return t[e]=n,t}},function(t,e,n){var r=n(6);t.exports=function(t){if(!r(t))throw TypeError(t+" is not an object!");return t}},function(t,e,n){t.exports=!n(1)&&!n(2)(function(){return 7!=Object.defineProperty(n(36)("div"),"a",{get:function(){return 7}}).a})},function(t,e,n){var r=n(6),o=n(4).document,i=r(o)&&r(o.createElement);t.exports=function(t){return i?o.createElement(t):{}}},function(t,e,n){var r=n(6);t.exports=function(t,e){if(!r(t))return t;var n,o;if(e&&"function"==typeof(n=t.toString)&&!r(o=n.call(t)))return o;if("function"==typeof(n=t.valueOf)&&!r(o=n.call(t)))return o;if(!e&&"function"==typeof(n=t.toString)&&!r(o=n.call(t)))return o;throw TypeError("Can't convert object to primitive value")}},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e,n){t.exports={default:n(40),__esModule:!0}},function(t,e,n){n(41),t.exports=n(0).Object.assign},function(t,e,n){var r=n(5);r(r.S+r.F,"Object",{assign:n(42)})},function(t,e,n){"use strict";var r=n(9),o=n(43),i=n(44),s=n(7),u=n(12),c=Object.assign;t.exports=!c||n(2)(function(){var t={},e={},n=Symbol(),r="abcdefghijklmnopqrst";return t[n]=7,r.split("").forEach(function(t){e[t]=t}),7!=c({},t)[n]||Object.keys(c({},e)).join("")!=r})?function(t,e){for(var n=s(t),c=arguments.length,l=1,a=o.f,f=i.f;c>l;)for(var p,h=u(arguments[l++]),v=a?r(h).concat(a(h)):r(h),y=v.length,g=0;y>g;)f.call(h,p=v[g++])&&(n[p]=h[p]);return n}:c},function(t,e){e.f=Object.getOwnPropertySymbols},function(t,e){e.f={}.propertyIsEnumerable},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e,n){"use strict";e.__esModule=!0;var r=n(47),o=function(t){return t&&t.__esModule?t:{default:t}}(r);e.default=function(){function t(t,e){for(var n=0;n=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),y(n)?r.showHidden=n:n&&e._extend(r,n),_(r.showHidden)&&(r.showHidden=!1),_(r.depth)&&(r.depth=2),_(r.colors)&&(r.colors=!1),_(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=i),c(r,t,r.depth)}function i(t,e){var n=o.styles[e];return n?"["+o.colors[n][0]+"m"+t+"["+o.colors[n][1]+"m":t}function s(t,e){return t}function u(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}function c(t,n,r){if(t.customInspect&&n&&E(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var o=n.inspect(r,t);return b(o)||(o=c(t,o,r)),o}var i=l(t,n);if(i)return i;var s=Object.keys(n),y=u(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(n)),j(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return a(n);if(0===s.length){if(E(n)){var g=n.name?": "+n.name:"";return t.stylize("[Function"+g+"]","special")}if(x(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(L(n))return t.stylize(Date.prototype.toString.call(n),"date");if(j(n))return a(n)}var d="",m=!1,w=["{","}"];if(v(n)&&(m=!0,w=["[","]"]),E(n)){d=" [Function"+(n.name?": "+n.name:"")+"]"}if(x(n)&&(d=" "+RegExp.prototype.toString.call(n)),L(n)&&(d=" "+Date.prototype.toUTCString.call(n)),j(n)&&(d=" "+a(n)),0===s.length&&(!m||0==n.length))return w[0]+d+w[1];if(r<0)return x(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special");t.seen.push(n);var _;return _=m?f(t,n,r,y,s):s.map(function(e){return p(t,n,r,y,e,m)}),t.seen.pop(),h(_,d,w)}function l(t,e){if(_(e))return t.stylize("undefined","undefined");if(b(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}return m(e)?t.stylize(""+e,"number"):y(e)?t.stylize(""+e,"boolean"):g(e)?t.stylize("null","null"):void 0}function a(t){return"["+Error.prototype.toString.call(t)+"]"}function f(t,e,n,r,o){for(var i=[],s=0,u=e.length;s-1&&(u=i?u.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+u.split("\n").map(function(t){return" "+t}).join("\n"))):u=t.stylize("[Circular]","special")),_(s)){if(i&&o.match(/^\d+$/))return u;s=JSON.stringify(""+o),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+u}function h(t,e,n){var r=0;return t.reduce(function(t,e){return r++,e.indexOf("\n")>=0&&r++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60?n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1]:n[0]+e+" "+t.join(", ")+" "+n[1]}function v(t){return Array.isArray(t)}function y(t){return"boolean"==typeof t}function g(t){return null===t}function d(t){return null==t}function m(t){return"number"==typeof t}function b(t){return"string"==typeof t}function w(t){return"symbol"==typeof t}function _(t){return void 0===t}function x(t){return O(t)&&"[object RegExp]"===k(t)}function O(t){return"object"==typeof t&&null!==t}function L(t){return O(t)&&"[object Date]"===k(t)}function j(t){return O(t)&&("[object Error]"===k(t)||t instanceof Error)}function E(t){return"function"==typeof t}function S(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t}function k(t){return Object.prototype.toString.call(t)}function R(t){return t<10?"0"+t.toString(10):t.toString(10)}function M(){var t=new Date,e=[R(t.getHours()),R(t.getMinutes()),R(t.getSeconds())].join(":");return[t.getDate(),z[t.getMonth()],e].join(" ")}function T(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var N=/%[sdj%]/g;e.format=function(t){if(!b(t)){for(var e=[],n=0;n=i)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return t}}),u=r[n];n0&&this._events[t].length>o&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace()),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function n(){this.removeListener(t,n),o||(o=!0,e.apply(this,arguments))}if(!r(e))throw TypeError("listener must be a function");var o=!1;return n.listener=e,this.on(t,n),this},n.prototype.removeListener=function(t,e){var n,o,s,u;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],s=n.length,o=-1,n===e||r(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(i(n)){for(u=s;u-- >0;)if(n[u]===e||n[u].listener&&n[u].listener===e){o=u;break}if(o<0)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(o,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],r(n))this.removeListener(t,n);else if(n)for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){return this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(r(e))return 1;if(e)return e.length}return 0},n.listenerCount=function(t,e){return t.listenerCount(e)}}]); \ No newline at end of file diff --git a/es5/index.js b/es5/index.js index 9e3da56..6aa7cd4 100644 --- a/es5/index.js +++ b/es5/index.js @@ -127,13 +127,18 @@ var Logger = function () { }, { key: '_write', value: function _write(level, text) { - if ((this.options.filename || GlobalLogfile) && !this.fileWriter && isNodejs) this.fileWriter = fs.openSync(this.options.filename || GlobalLogfile, this.options.appendFile ? 'a+' : 'w+'); + if ((this.options.filename || GlobalLogfile) && !this.fileWriter && (isNodejs || isElectronRenderer)) this.fileWriter = fs.openSync(this.options.filename || GlobalLogfile, this.options.appendFile ? 'a+' : 'w+'); var format = this._format(level, text); var unformattedText = this._createLogMessage(level, text); var formattedText = this._createLogMessage(level, text, format.timestamp, format.level, format.category, format.text); - if (this.fileWriter && isNodejs) fs.writeSync(this.fileWriter, unformattedText + '\n', null, 'utf-8'); + if (this.fileWriter && (isNodejs || isElectronRenderer)) { + if (isElectronRenderer) { + unformattedText = unformattedText.replace(/\%c/gm, ''); + } + fs.writeSync(this.fileWriter, unformattedText + '\n', null, 'utf-8'); + } if (isNodejs || !this.options.useColors) { console.log(formattedText); diff --git a/example/bundle.js b/example/bundle.js index c543e36..0b6bfb9 100644 --- a/example/bundle.js +++ b/example/bundle.js @@ -516,13 +516,18 @@ var Logger = function () { }, { key: '_write', value: function _write(level, text) { - if ((this.options.filename || GlobalLogfile) && !this.fileWriter && isNodejs) this.fileWriter = fs.openSync(this.options.filename || GlobalLogfile, this.options.appendFile ? 'a+' : 'w+'); + if ((this.options.filename || GlobalLogfile) && !this.fileWriter && (isNodejs || isElectronRenderer)) this.fileWriter = fs.openSync(this.options.filename || GlobalLogfile, this.options.appendFile ? 'a+' : 'w+'); var format = this._format(level, text); var unformattedText = this._createLogMessage(level, text); var formattedText = this._createLogMessage(level, text, format.timestamp, format.level, format.category, format.text); - if (this.fileWriter && isNodejs) fs.writeSync(this.fileWriter, unformattedText + '\n', null, 'utf-8'); + if (this.fileWriter && (isNodejs || isElectronRenderer)) { + if (isElectronRenderer) { + unformattedText = unformattedText.replace(/\%c/gm, ''); + } + fs.writeSync(this.fileWriter, unformattedText + '\n', null, 'utf-8'); + } if (isNodejs || !this.options.useColors) { console.log(formattedText); diff --git a/src/index.js b/src/index.js index 313b44e..e249330 100644 --- a/src/index.js +++ b/src/index.js @@ -105,15 +105,17 @@ class Logger { } _write(level, text) { - if((this.options.filename || GlobalLogfile) && !this.fileWriter && isNodejs) + if((this.options.filename || GlobalLogfile) && !this.fileWriter && (isNodejs || isElectronRenderer)) this.fileWriter = fs.openSync(this.options.filename || GlobalLogfile, this.options.appendFile ? 'a+' : 'w+'); let format = this._format(level, text); let unformattedText = this._createLogMessage(level, text); let formattedText = this._createLogMessage(level, text, format.timestamp, format.level, format.category, format.text); - if(this.fileWriter && isNodejs) + if(this.fileWriter && (isNodejs || isElectronRenderer)) { + if (isElectronRenderer) { unformattedText = unformattedText.replace(/\%c/gm, ''); } fs.writeSync(this.fileWriter, unformattedText + '\n', null, 'utf-8'); + } if(isNodejs || !this.options.useColors) { console.log(formattedText) diff --git a/test/logplease.test.js b/test/logplease.test.js index 4edf9ae..da721e5 100644 --- a/test/logplease.test.js +++ b/test/logplease.test.js @@ -340,6 +340,17 @@ describe('logplease', function() { done() }) + it('writes to log file when in electron renderer process', (done) => { + process.type = 'renderer'; + const log = Logger.create('test1', { filename: logfile, appendFile: false, showTimestamp: false }) + assert(!fs.existsSync(logfile)) + log.debug('hello') + assert(fs.existsSync(logfile)) + const f = fs.readFileSync(logfile, 'utf-8') + assert.equal(f, '[DEBUG] test1: hello\n') + done() + }); + it('appends to a log file', (done) => { const log = Logger.create('test1', { filename: logfile, appendFile: true, showTimestamp: false }) assert(!fs.existsSync(logfile))