UNPKG

w-syslog

Version:
8 lines (7 loc) 15 kB
/*! * formatter v1.0.6 * (c) 2018-2021 yuda-lyu(semisphere) * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("fs"),require("path"),require("stream")):"function"==typeof define&&define.amd?define(["fs","path","stream"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).formatter=e(t.fs,t.path,t.stream)}(this,function(t,e,r){"use strict";"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var i={exports:{}};!function(t){t.exports=function(){var t=1e3,e=6e4,r=36e5,n="millisecond",i="second",u="minute",o="hour",a="day",s="week",c="month",f="quarter",l="year",h="date",d="Invalid Date",p=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,v=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,y={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],r=t%100;return"["+t+(e[(r-20)%10]||e[r]||e[0])+"]"}},$=function(t,e,r){var n=String(t);return!n||n.length>=e?t:""+Array(e+1-n.length).join(r)+t},_={s:$,z:function(t){var e=-t.utcOffset(),r=Math.abs(e),n=Math.floor(r/60),i=r%60;return(e<=0?"+":"-")+$(n,2,"0")+":"+$(i,2,"0")},m:function t(e,r){if(e.date()<r.date())return-t(r,e);var n=12*(r.year()-e.year())+(r.month()-e.month()),i=e.clone().add(n,c),u=r-i<0,o=e.clone().add(n+(u?-1:1),c);return+(-(n+(r-i)/(u?i-o:o-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:c,y:l,w:s,d:a,D:h,h:o,m:u,s:i,ms:n,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",b={};b[g]=y;var m="$isDayjsObject",S=function(t){return t instanceof D||!(!t||!t[m])},M=function t(e,r,n){var i;if(!e)return g;if("string"==typeof e){var u=e.toLowerCase();b[u]&&(i=u),r&&(b[u]=r,i=u);var o=e.split("-");if(!i&&o.length>1)return t(o[0])}else{var a=e.name;b[a]=e,i=a}return!n&&i&&(g=i),i||!n&&g},w=function(t,e){if(S(t))return t.clone();var r="object"==typeof e?e:{};return r.date=t,r.args=arguments,new D(r)},O=_;O.l=M,O.i=S,O.w=function(t,e){return w(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var D=function(){function y(t){this.$L=M(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[m]=!0}var $=y.prototype;return $.parse=function(t){this.$d=function(t){var e=t.date,r=t.utc;if(null===e)return new Date(NaN);if(O.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var n=e.match(p);if(n){var i=n[2]-1||0,u=(n[7]||"0").substring(0,3);return r?new Date(Date.UTC(n[1],i,n[3]||1,n[4]||0,n[5]||0,n[6]||0,u)):new Date(n[1],i,n[3]||1,n[4]||0,n[5]||0,n[6]||0,u)}}return new Date(e)}(t),this.init()},$.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},$.$utils=function(){return O},$.isValid=function(){return!(this.$d.toString()===d)},$.isSame=function(t,e){var r=w(t);return this.startOf(e)<=r&&r<=this.endOf(e)},$.isAfter=function(t,e){return w(t)<this.startOf(e)},$.isBefore=function(t,e){return this.endOf(e)<w(t)},$.$g=function(t,e,r){return O.u(t)?this[e]:this.set(r,t)},$.unix=function(){return Math.floor(this.valueOf()/1e3)},$.valueOf=function(){return this.$d.getTime()},$.startOf=function(t,e){var r=this,n=!!O.u(e)||e,f=O.p(t),d=function(t,e){var i=O.w(r.$u?Date.UTC(r.$y,e,t):new Date(r.$y,e,t),r);return n?i:i.endOf(a)},p=function(t,e){return O.w(r.toDate()[t].apply(r.toDate("s"),(n?[0,0,0,0]:[23,59,59,999]).slice(e)),r)},v=this.$W,y=this.$M,$=this.$D,_="set"+(this.$u?"UTC":"");switch(f){case l:return n?d(1,0):d(31,11);case c:return n?d(1,y):d(0,y+1);case s:var g=this.$locale().weekStart||0,b=(v<g?v+7:v)-g;return d(n?$-b:$+(6-b),y);case a:case h:return p(_+"Hours",0);case o:return p(_+"Minutes",1);case u:return p(_+"Seconds",2);case i:return p(_+"Milliseconds",3);default:return this.clone()}},$.endOf=function(t){return this.startOf(t,!1)},$.$set=function(t,e){var r,s=O.p(t),f="set"+(this.$u?"UTC":""),d=(r={},r[a]=f+"Date",r[h]=f+"Date",r[c]=f+"Month",r[l]=f+"FullYear",r[o]=f+"Hours",r[u]=f+"Minutes",r[i]=f+"Seconds",r[n]=f+"Milliseconds",r)[s],p=s===a?this.$D+(e-this.$W):e;if(s===c||s===l){var v=this.clone().set(h,1);v.$d[d](p),v.init(),this.$d=v.set(h,Math.min(this.$D,v.daysInMonth())).$d}else d&&this.$d[d](p);return this.init(),this},$.set=function(t,e){return this.clone().$set(t,e)},$.get=function(t){return this[O.p(t)]()},$.add=function(n,f){var h,d=this;n=Number(n);var p=O.p(f),v=function(t){var e=w(d);return O.w(e.date(e.date()+Math.round(t*n)),d)};if(p===c)return this.set(c,this.$M+n);if(p===l)return this.set(l,this.$y+n);if(p===a)return v(1);if(p===s)return v(7);var y=(h={},h[u]=e,h[o]=r,h[i]=t,h)[p]||1,$=this.$d.getTime()+n*y;return O.w($,this)},$.subtract=function(t,e){return this.add(-1*t,e)},$.format=function(t){var e=this,r=this.$locale();if(!this.isValid())return r.invalidDate||d;var n=t||"YYYY-MM-DDTHH:mm:ssZ",i=O.z(this),u=this.$H,o=this.$m,a=this.$M,s=r.weekdays,c=r.months,f=r.meridiem,l=function(t,r,i,u){return t&&(t[r]||t(e,n))||i[r].slice(0,u)},h=function(t){return O.s(u%12||12,t,"0")},p=f||function(t,e,r){var n=t<12?"AM":"PM";return r?n.toLowerCase():n};return n.replace(v,function(t,n){return n||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return O.s(e.$y,4,"0");case"M":return a+1;case"MM":return O.s(a+1,2,"0");case"MMM":return l(r.monthsShort,a,c,3);case"MMMM":return l(c,a);case"D":return e.$D;case"DD":return O.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return l(r.weekdaysMin,e.$W,s,2);case"ddd":return l(r.weekdaysShort,e.$W,s,3);case"dddd":return s[e.$W];case"H":return String(u);case"HH":return O.s(u,2,"0");case"h":return h(1);case"hh":return h(2);case"a":return p(u,o,!0);case"A":return p(u,o,!1);case"m":return String(o);case"mm":return O.s(o,2,"0");case"s":return String(e.$s);case"ss":return O.s(e.$s,2,"0");case"SSS":return O.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")})},$.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},$.diff=function(n,h,d){var p,v=this,y=O.p(h),$=w(n),_=($.utcOffset()-this.utcOffset())*e,g=this-$,b=function(){return O.m(v,$)};switch(y){case l:p=b()/12;break;case c:p=b();break;case f:p=b()/3;break;case s:p=(g-_)/6048e5;break;case a:p=(g-_)/864e5;break;case o:p=g/r;break;case u:p=g/e;break;case i:p=g/t;break;default:p=g}return d?p:O.a(p)},$.daysInMonth=function(){return this.endOf(c).$D},$.$locale=function(){return b[this.$L]},$.locale=function(t,e){if(!t)return this.$L;var r=this.clone(),n=M(t,e,!0);return n&&(r.$L=n),r},$.clone=function(){return O.w(this.$d,this)},$.toDate=function(){return new Date(this.valueOf())},$.toJSON=function(){return this.isValid()?this.toISOString():null},$.toISOString=function(){return this.$d.toISOString()},$.toString=function(){return this.$d.toUTCString()},y}(),j=D.prototype;return w.prototype=j,[["$ms",n],["$s",i],["$m",u],["$H",o],["$W",a],["$M",c],["$y",l],["$D",h]].forEach(function(t){j[t[1]]=function(e){return this.$g(e,t[0],t[1])}}),w.extend=function(t,e){return t.$i||(t(e,D,w),t.$i=!0),w},w.locale=M,w.isDayjs=S,w.unix=function(t){return w(1e3*t)},w.en=b[g],w.Ls=b,w.p={},w}()}(i);var u=n(i.exports),o=Array.isArray,a="object"==typeof global&&global&&global.Object===Object&&global,s="object"==typeof self&&self&&self.Object===Object&&self,c=a||s||Function("return this")(),f=c.Symbol,l=Object.prototype,h=l.hasOwnProperty,d=l.toString,p=f?f.toStringTag:void 0;var v=Object.prototype.toString;var y=f?f.toStringTag:void 0;function $(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":y&&y in Object(t)?function(t){var e=h.call(t,p),r=t[p];try{t[p]=void 0;var n=!0}catch(t){}var i=d.call(t);return n&&(e?t[p]=r:delete t[p]),i}(t):function(t){return v.call(t)}(t)}function _(t){return"symbol"==typeof t||function(t){return null!=t&&"object"==typeof t}(t)&&"[object Symbol]"==$(t)}var g=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,b=/^\w*$/;function m(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var S,M=c["__core-js_shared__"],w=(S=/[^.]+$/.exec(M&&M.keys&&M.keys.IE_PROTO||""))?"Symbol(src)_1."+S:"";var O=Function.prototype.toString;var D=/^\[object .+?Constructor\]$/,j=Function.prototype,T=Object.prototype,x=j.toString,k=T.hasOwnProperty,Y=RegExp("^"+x.call(k).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function z(t){if(!m(t)||(e=t,w&&w in e))return!1;var e,r=function(t){if(!m(t))return!1;var e=$(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}(t)?Y:D;return r.test(function(t){if(null!=t){try{return O.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t))}function A(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return z(r)?r:void 0}var H=A(Object,"create");var N=Object.prototype.hasOwnProperty;var C=Object.prototype.hasOwnProperty;function F(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function W(t,e){return t===e||t!=t&&e!=e}function L(t,e){for(var r=t.length;r--;)if(W(t[r][0],e))return r;return-1}F.prototype.clear=function(){this.__data__=H?H(null):{},this.size=0},F.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},F.prototype.get=function(t){var e=this.__data__;if(H){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return N.call(e,t)?e[t]:void 0},F.prototype.has=function(t){var e=this.__data__;return H?void 0!==e[t]:C.call(e,t)},F.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=H&&void 0===e?"__lodash_hash_undefined__":e,this};var P=Array.prototype.splice;function I(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}I.prototype.clear=function(){this.__data__=[],this.size=0},I.prototype.delete=function(t){var e=this.__data__,r=L(e,t);return!(r<0)&&(r==e.length-1?e.pop():P.call(e,r,1),--this.size,!0)},I.prototype.get=function(t){var e=this.__data__,r=L(e,t);return r<0?void 0:e[r][1]},I.prototype.has=function(t){return L(this.__data__,t)>-1},I.prototype.set=function(t,e){var r=this.__data__,n=L(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var U=A(c,"Map");function E(t,e){var r,n,i=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?i["string"==typeof e?"string":"hash"]:i.map}function Z(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Z.prototype.clear=function(){this.size=0,this.__data__={hash:new F,map:new(U||I),string:new F}},Z.prototype.delete=function(t){var e=E(this,t).delete(t);return this.size-=e?1:0,e},Z.prototype.get=function(t){return E(this,t).get(t)},Z.prototype.has=function(t){return E(this,t).has(t)},Z.prototype.set=function(t,e){var r=E(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function q(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,i=e?e.apply(this,n):n[0],u=r.cache;if(u.has(i))return u.get(i);var o=t.apply(this,n);return r.cache=u.set(i,o)||u,o};return r.cache=new(q.Cache||Z),r}q.Cache=Z;var J,B,V,R=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,G=/\\(\\)?/g,Q=(J=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(R,function(t,r,n,i){e.push(n?i.replace(G,"$1"):r||t)}),e},B=q(J,function(t){return 500===V.size&&V.clear(),t}),V=B.cache,B),K=Q;var X=f?f.prototype:void 0,tt=X?X.toString:void 0;function et(t){if("string"==typeof t)return t;if(o(t))return function(t,e){for(var r=-1,n=null==t?0:t.length,i=Array(n);++r<n;)i[r]=e(t[r],r,t);return i}(t,et)+"";if(_(t))return tt?tt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function rt(t){return null==t?"":et(t)}function nt(t,e){return o(t)?t:function(t,e){if(o(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!_(t))||b.test(t)||!g.test(t)||null!=e&&t in Object(e)}(t,e)?[t]:K(rt(t))}function it(t){if("string"==typeof t||_(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function ut(t,e,r){var n=null==t?void 0:function(t,e){for(var r=0,n=(e=nt(e,t)).length;null!=t&&r<n;)t=t[it(e[r++])];return r&&r==n?t:void 0}(t,e);return void 0===n?r:n}function ot(t){return!(!function(t){return"[object String]"===Object.prototype.toString.call(t)}(t)||""===t)}var at=/\s/;var st=/^\s+/;function ct(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&at.test(t.charAt(e)););return e}(t)+1).replace(st,""):t}var ft=/^[-+]0x[0-9a-f]+$/i,lt=/^0b[01]+$/i,ht=/^0o[0-7]+$/i,dt=parseInt;function pt(t){if("number"==typeof t)return t;if(_(t))return NaN;if(m(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=m(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=ct(t);var r=lt.test(t);return r||ht.test(t)?dt(t.slice(2),r?2:8):ft.test(t)?NaN:+t}var vt=1/0;function yt(t){return t?(t=pt(t))===vt||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function $t(t){var e=yt(t),r=e%1;return e==e?r?e-r:e:0}function _t(t){let e=!1;if(ot(t))e=!isNaN(Number(t));else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(function(t){return t!=t}(t))return!1;e=!0}return e}function gt(t){if(!_t(t))return 0;return yt(t)}function bt(t){return!!_t(t)&&(t=gt(t),"number"==typeof(e=t)&&e==$t(e));var e}var mt=c.isFinite,St=Math.min;var Mt=function(t){var e=Math[t];return function(t,r){if(t=pt(t),(r=null==r?0:St($t(r),292))&&mt(t)){var n=(rt(t)+"e").split("e");return+((n=(rt(e(n[0]+"e"+(+n[1]+r)))+"e").split("e"))[0]+"e"+(+n[1]-r))}return e(t)}}("round"),wt=Mt;function Ot(t){if(!_t(t))return 0;t=gt(t);let e=wt(t);return"0"===String(e)?0:e}function Dt(t,e){return ot(t)&&bt(r=e)&&Ot(r)>=0?0===(e=Ot(e))?"":t.substring(0,e):"";var r}return async function(n){let i=ut(n,"fdLog");ot(i)||(i="./_logs");let o=ut(n,"interval");"day"!==o&&"hr"!==o&&(o="day"),t.existsSync(i)||t.mkdirSync(i,{recursive:!0});let a=null,s="",c=()=>{let r=(()=>{let t=u().format("YYYY-MM-DDTHH:mm:ss.SSSZ");return"hr"===o?(t=Dt(t,13),t):(t=Dt(t,10),t)})();if(r!==s){s=r;let n=(t=>{let r=`${t}.log`;return e.join(i,r)})(r);a&&a.end(),a=t.createWriteStream(n,{flags:"a"})}};c();let f=new r.Writable({write(t,e,r){try{c();let e=Buffer.isBuffer(t)?t.toString("utf8"):String(t);a.write(e,r)}catch(t){r(t)}}});return f.on("error",t=>{console.error("formatter error",t)}),f}}); //# sourceMappingURL=formatter.umd.js.map