@youpaichris/logger 1.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +31 -29
- package/package.json +1 -1
    
        package/index.js
    CHANGED
    
    | @@ -1,33 +1,18 @@ | |
| 1 1 | 
             
            /*!
         | 
| 2 2 | 
             
             * JavaScript logger
         | 
| 3 3 | 
             
             * Logger - v1.0.0 (2021-01-15T14:55:51+0800)
         | 
| 4 | 
            +
             * Logger - v3.0.0 (2023-12-07T14:13:51+0800)
         | 
| 4 5 | 
             
             * Chris / QQ:10512
         | 
| 5 6 | 
             
             */
         | 
| 6 7 |  | 
| 7 | 
            -
            const  | 
| 8 | 
            -
             | 
| 8 | 
            +
            const __log = console.log;
         | 
| 9 | 
            +
            const __log__ = function () {
         | 
| 9 10 | 
             
                if (arguments[3] === '\x1B[41m') {
         | 
| 10 11 | 
             
                    arguments[4] = "\b" + arguments[4];
         | 
| 11 | 
            -
                    arguments[arguments.length-1] += consoleStyles['redBG'][1] + consoleStyles['bold'][1] + '\b';
         | 
| 12 | 
            +
                    arguments[arguments.length - 1] += consoleStyles['redBG'][1] + consoleStyles['bold'][1] + '\b';
         | 
| 12 13 | 
             
                }
         | 
| 13 | 
            -
                return  | 
| 14 | 
            +
                return __log.apply(this, arguments)
         | 
| 14 15 | 
             
            }
         | 
| 15 | 
            -
            const loggerConfig = {
         | 
| 16 | 
            -
                Date: (() => {
         | 
| 17 | 
            -
                    return Date
         | 
| 18 | 
            -
                })(),
         | 
| 19 | 
            -
                warn: (() => {
         | 
| 20 | 
            -
                    return console.warn
         | 
| 21 | 
            -
                })(),
         | 
| 22 | 
            -
                Error: (() => {
         | 
| 23 | 
            -
                    return Error
         | 
| 24 | 
            -
                })(),
         | 
| 25 | 
            -
                RegExp: (() => {
         | 
| 26 | 
            -
                    return RegExp
         | 
| 27 | 
            -
                })(),
         | 
| 28 | 
            -
             | 
| 29 | 
            -
            }
         | 
| 30 | 
            -
             | 
| 31 16 | 
             
            const _error = console.error;
         | 
| 32 17 | 
             
            console.error = (...msg) => {
         | 
| 33 18 | 
             
                let isOutput = true;
         | 
| @@ -38,6 +23,23 @@ console.error = (...msg) => { | |
| 38 23 | 
             
                })
         | 
| 39 24 | 
             
                isOutput && _error(...msg);
         | 
| 40 25 | 
             
            }
         | 
| 26 | 
            +
            const loggerConfig = {
         | 
| 27 | 
            +
                Date: (() => {
         | 
| 28 | 
            +
                    return Date;
         | 
| 29 | 
            +
                })(),
         | 
| 30 | 
            +
                log: (() => {
         | 
| 31 | 
            +
                    return __log__;
         | 
| 32 | 
            +
                })(),
         | 
| 33 | 
            +
                error: _error,
         | 
| 34 | 
            +
                Error: (() => {
         | 
| 35 | 
            +
                    return Error;
         | 
| 36 | 
            +
                })(),
         | 
| 37 | 
            +
                RegExp: (() => {
         | 
| 38 | 
            +
                    return RegExp;
         | 
| 39 | 
            +
                })(),
         | 
| 40 | 
            +
            }
         | 
| 41 | 
            +
             | 
| 42 | 
            +
             | 
| 41 43 | 
             
            Object.defineProperty(global, '__stack', {
         | 
| 42 44 | 
             
                get: function () {
         | 
| 43 45 | 
             
                    return new Error().stack.split('\n').slice(2);
         | 
| @@ -121,7 +123,7 @@ class Logger { | |
| 121 123 |  | 
| 122 124 | 
             
                info(...msg) {
         | 
| 123 125 | 
             
                    let pathLine = this?.path ? `[${this.path}:${__line}]` : "Anonymous";
         | 
| 124 | 
            -
                    loggerConfig. | 
| 126 | 
            +
                    loggerConfig.log(consoleStyles['green'][0] + dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date()),
         | 
| 125 127 | 
             
                        consoleStyles['red'][0] + consoleStyles['bold'][0] + "| " +
         | 
| 126 128 | 
             
                        consoleStyles['bold'][0] + consoleStyles['blue'][0] + "INFO    " + consoleStyles['red'][0] + " |" +
         | 
| 127 129 | 
             
                        consoleStyles['blue'][0], ` ${pathLine.padEnd(22, " ")}${consoleStyles['blue'][0]}📡`, consoleStyles['blue'][0],
         | 
| @@ -132,7 +134,7 @@ class Logger { | |
| 132 134 |  | 
| 133 135 | 
             
                warn(...msg) {
         | 
| 134 136 | 
             
                    let pathLine = this?.path ? `[${this.path}:${__line}]` : "Anonymous";
         | 
| 135 | 
            -
                    loggerConfig. | 
| 137 | 
            +
                    loggerConfig.log(consoleStyles['green'][0] + dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date()),
         | 
| 136 138 | 
             
                        consoleStyles['red'][0] + consoleStyles['bold'][0] + "| " +
         | 
| 137 139 | 
             
                        consoleStyles['bold'][0] + consoleStyles['yellow'][0] + "WARNING " + consoleStyles['red'][0] + " |" +
         | 
| 138 140 | 
             
                        consoleStyles['blue'][0], ` ${pathLine.padEnd(22, " ")}${consoleStyles['yellow'][0]}💡`, consoleStyles['yellow'][0],
         | 
| @@ -143,7 +145,7 @@ class Logger { | |
| 143 145 |  | 
| 144 146 | 
             
                error(...msg) {
         | 
| 145 147 | 
             
                    let pathLine = this?.path ? `[${this.path}:${__line}]` : "Anonymous";
         | 
| 146 | 
            -
                    loggerConfig. | 
| 148 | 
            +
                    loggerConfig.error(consoleStyles['green'][0] + dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date()),
         | 
| 147 149 | 
             
                        consoleStyles['red'][0] + consoleStyles['bold'][0] + "| " +
         | 
| 148 150 | 
             
                        consoleStyles['bold'][0] + consoleStyles['red'][0] + "ERROR   " + consoleStyles['red'][0] + " |" +
         | 
| 149 151 | 
             
                        consoleStyles['blue'][0], ` ${pathLine.padEnd(22, " ")}${consoleStyles['red'][0]}🚨`, consoleStyles['red'][0],
         | 
| @@ -154,7 +156,7 @@ class Logger { | |
| 154 156 |  | 
| 155 157 | 
             
                success(...msg) {
         | 
| 156 158 | 
             
                    let pathLine = this?.path ? `[${this.path}:${__line}]` : "Anonymous";
         | 
| 157 | 
            -
                    loggerConfig. | 
| 159 | 
            +
                    loggerConfig.log(consoleStyles['green'][0] + dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date()),
         | 
| 158 160 | 
             
                        consoleStyles['red'][0] + consoleStyles['bold'][0] + "| " +
         | 
| 159 161 | 
             
                        consoleStyles['bold'][0] + consoleStyles['green'][0] + "SUCCESS " + consoleStyles['red'][0] + " |" +
         | 
| 160 162 | 
             
                        consoleStyles['blue'][0], ` ${pathLine.padEnd(22, " ")}${consoleStyles['green'][0]}🎯`, consoleStyles['green'][0],
         | 
| @@ -165,7 +167,7 @@ class Logger { | |
| 165 167 |  | 
| 166 168 | 
             
                debug(...msg) {
         | 
| 167 169 | 
             
                    let pathLine = this?.path ? `[${this.path}:${__line}]` : "Anonymous";
         | 
| 168 | 
            -
                    loggerConfig. | 
| 170 | 
            +
                    loggerConfig.log(consoleStyles['green'][0] + dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date()),
         | 
| 169 171 | 
             
                        consoleStyles['red'][0] + consoleStyles['bold'][0] + "| " +
         | 
| 170 172 | 
             
                        consoleStyles['bold'][0] + consoleStyles['magenta'][0] + "DEBUG   " + consoleStyles['red'][0] + " |" +
         | 
| 171 173 | 
             
                        consoleStyles['blue'][0], ` ${pathLine.padEnd(22, " ")}${consoleStyles['magenta'][0]}🚧`, consoleStyles['magenta'][0],
         | 
| @@ -176,7 +178,7 @@ class Logger { | |
| 176 178 |  | 
| 177 179 | 
             
                call(...msg) {
         | 
| 178 180 | 
             
                    let pathLine = this?.path ? `[${this.path}:${__line}]` : "Anonymous";
         | 
| 179 | 
            -
                    loggerConfig. | 
| 181 | 
            +
                    loggerConfig.log(consoleStyles['green'][0] + dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date()),
         | 
| 180 182 | 
             
                        consoleStyles['red'][0] + consoleStyles['bold'][0] + "| " +
         | 
| 181 183 | 
             
                        consoleStyles['bold'][0] + consoleStyles['cyan'][0] + "CALL    " + consoleStyles['red'][0] + " |" +
         | 
| 182 184 | 
             
                        consoleStyles['blue'][0], ` ${pathLine.padEnd(22, " ")}${consoleStyles['cyan'][0]}🔔`, consoleStyles['cyan'][0],
         | 
| @@ -187,7 +189,7 @@ class Logger { | |
| 187 189 |  | 
| 188 190 | 
             
                critical(...msg) {
         | 
| 189 191 | 
             
                    let pathLine = this?.path ? `[${this.path}:${__line}]` : "Anonymous";
         | 
| 190 | 
            -
                    loggerConfig. | 
| 192 | 
            +
                    loggerConfig.log(consoleStyles['green'][0] + dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date()),
         | 
| 191 193 | 
             
                        consoleStyles['red'][0] + consoleStyles['bold'][0] + "| " +
         | 
| 192 194 | 
             
                        consoleStyles['bold'][0] + consoleStyles['redBG'][0] + consoleStyles['white'][0] + "CRITICAL" + consoleStyles['redBG'][1] + consoleStyles['red'][0] + " |" +
         | 
| 193 195 | 
             
                        consoleStyles['blue'][0], ` ${pathLine.padEnd(22, " ")}${consoleStyles['cyan'][0]}🔴 ${consoleStyles['white'][0]}`, consoleStyles['redBG'][0],
         | 
| @@ -218,7 +220,7 @@ class Logger { | |
| 218 220 |  | 
| 219 221 | 
             
            module.exports = Logger;
         | 
| 220 222 |  | 
| 221 | 
            -
             | 
| 223 | 
            +
             | 
| 222 224 | 
             
            const logger = new Logger();
         | 
| 223 225 | 
             
            logger.info(`info`);
         | 
| 224 226 | 
             
            logger.debug("debug")
         | 
| @@ -227,5 +229,5 @@ logger.call("call") | |
| 227 229 | 
             
            logger.error("error")
         | 
| 228 230 | 
             
            logger.critical("critical.", 2, 3, "4")
         | 
| 229 231 | 
             
            logger.info("info again");
         | 
| 230 | 
            -
             | 
| 232 | 
            +
             | 
| 231 233 |  |