@hack4impact/logger
Version:
The lightweight & lightning-fast Logger Utility used by Hack4Impact Projects
1 lines • 5.36 kB
JavaScript
module.exports=(()=>{"use strict";var t={100:(t,e)=>{Object.defineProperty(e,"__esModule",{value:true});e.COLORS=void 0;e.COLORS={Reset:"[0m",Bright:"[1m",Dim:"[2m",Underscore:"[4m",Blink:"[5m",Reverse:"[7m",Hidden:"[8m",FgBlack:"[30m",FgRed:"[31m",FgGreen:"[32m",FgYellow:"[33m",FgBlue:"[34m",FgMagenta:"[35m",FgCyan:"[36m",FgWhite:"[37m",BgBlack:"[40m",BgRed:"[41m",BgGreen:"[42m",BgYellow:"[43m",BgBlue:"[44m",BgMagenta:"[45m",BgCyan:"[46m",BgWhite:"[47m"}},976:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:true});e.NO_LOGS_PATH=e.INVALID_TYPE=void 0;var o=r(144);e.INVALID_TYPE=new TypeError("Value for 'type' parameter must be one of "+o.LOG_TYPES);e.NO_LOGS_PATH=new Error("No 'logsPath' was entered when initializing this Logger instance")},144:function(t,e,r){var o=this&&this.__assign||function(){o=Object.assign||function(t){for(var e,r=1,o=arguments.length;r<o;r++){e=arguments[r];for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n))t[n]=e[n]}return t};return o.apply(this,arguments)};var n=this&&this.__spreadArrays||function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var o=Array(t),n=0,e=0;e<r;e++)for(var u=arguments[e],i=0,g=u.length;i<g;i++,n++)o[n]=u[i];return o};Object.defineProperty(e,"__esModule",{value:true});e.Output=e.Logger=e.LOG_TYPES=e.CONSOLE_LEVELS=void 0;var u=r(357);var i=r(747);var g=i.promises.writeFile;var s=r(976);var l=r(100);e.CONSOLE_LEVELS=["log","warn","error"];e.LOG_TYPES=["success","info","error","warn"];var a=function(){function Logger(t){this._logsPath=t===null||t===void 0?void 0:t.logsPath;this._logs=[]}Object.defineProperty(Logger.prototype,"logs",{get:function(){return this._logs},enumerable:false,configurable:true});Object.defineProperty(Logger.prototype,"logsPath",{get:function(){return this._logsPath},set:function(t){this._logsPath=t},enumerable:false,configurable:true});Logger.prototype.log=function(t,r){var n=(r!==null&&r!==void 0?r:{}).type;var i={timestamp:Date.now(),index:this.logs.length,message:t,type:n};if(n){u.strict.ok(e.LOG_TYPES.includes(n),s.INVALID_TYPE);Logger[n](t)}else Logger.log(t);if(!(r&&r.writeToFile===false)){var g=(r!==null&&r!==void 0?r:{}).extra;i=o(o({},i),{extra:g});this.logs.push(i);return this.writeLogs().then(function(){return i})}this.logs.push(i);return i};Logger.prototype.success=function(t,e){var r=o(o({},e),{type:"success"});if(r.writeToFile===false)return this.log(t,r);return this.log(t,r)};Logger.prototype.info=function(t,e){var r=o(o({},e),{type:"info"});if(r.writeToFile===false)return this.log(t,r);return this.log(t,r)};Logger.prototype.warn=function(t,e){var r=o(o({},e),{type:"warn"});if(r.writeToFile===false)return this.log(t,r);return this.log(t,r)};Logger.prototype.error=function(t,e){var r=o(o({},e),{type:"error"});if(r.writeToFile===false)return this.log(t,r);return this.log(t,r)};Logger.prototype.writeLogs=function(){if(!this.logsPath)throw s.NO_LOGS_PATH;return g(this.logsPath,JSON.stringify(this.logs),"utf-8")};Logger.log=function(t){var e=[];for(var r=1;r<arguments.length;r++){e[r-1]=arguments[r]}console.log.apply(console,n([t],e))};Logger.line=function(){console.log()};Logger.coloredLog=function(t,e,r,o){if(r===void 0){r=""}if(o===void 0){o="log"}console[o](""+this.COLORS[t]+e+this.COLORS.Reset+r)};Logger.bold=function(t,e){if(e===void 0){e=""}return this.coloredLog("Bright",t,e)};Logger.success=function(t,e){if(e===void 0){e=""}return this.coloredLog("FgGreen",t,e)};Logger.info=function(t,e){if(e===void 0){e=""}return this.coloredLog("FgBlue",t,e)};Logger.warn=function(t,e){if(e===void 0){e=""}return this.coloredLog("FgYellow",t,e,"warn")};Logger.error=function(t,e){if(e===void 0){e=""}return this.coloredLog("FgRed",t,e,"error")};Logger.COLORS=l.COLORS;return Logger}();e.Logger=a;var f=r(768);Object.defineProperty(e,"Output",{enumerable:true,get:function(){return f.Output}});e.default=a},768:function(t,e,r){var o=this&&this.__spreadArrays||function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var o=Array(t),n=0,e=0;e<r;e++)for(var u=arguments[e],i=0,g=u.length;i<g;i++,n++)o[n]=u[i];return o};Object.defineProperty(e,"__esModule",{value:true});e.Output=void 0;var n=r(100);var u=function(){function Output(){this._output=[]}Object.defineProperty(Output.prototype,"output",{get:function(){return this._output},set:function(t){this._output=t},enumerable:false,configurable:true});Output.prototype.log=function(t){this.output.push(t);return t};Output.prototype.line=function(){this.output.push("")};Output.prototype.coloredLog=function(t,e,r){if(r===void 0){r=""}var o=""+Output.COLORS[t]+e+Output.COLORS.Reset+r;this.output.push(o);return o};Output.prototype.nested=function(){var t=new Output;this.output.push(t);return t};Output.prototype.flush=function(){this.output.forEach(function(t){if(t instanceof Output)t.flush();else console.log(t)});var t=o(this.output);this.output=[];return t};Output.COLORS=n.COLORS;return Output}();e.Output=u;e.default=u},357:t=>{t.exports=require("assert")},747:t=>{t.exports=require("fs")}};var e={};function __nccwpck_require__(r){if(e[r]){return e[r].exports}var o=e[r]={exports:{}};var n=true;try{t[r].call(o.exports,o,o.exports,__nccwpck_require__);n=false}finally{if(n)delete e[r]}return o.exports}__nccwpck_require__.ab=__dirname+"/";return __nccwpck_require__(144)})();