@youpaichris/logger 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +21 -19
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,7 @@
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
 
@@ -8,36 +9,37 @@ const __log = console.log;
8
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
14
  return __log.apply(this, arguments)
14
15
  }
16
+ const _error = console.error;
17
+ console.error = (...msg) => {
18
+ let isOutput = true;
19
+ [...msg].forEach(v => {
20
+ if (v?.includes?.(`Setting the NODE_TLS_REJECT_UNAUTHORIZED`)) {
21
+ isOutput = false;
22
+ }
23
+ })
24
+ isOutput && _error(...msg);
25
+ }
15
26
  const loggerConfig = {
16
27
  Date: (() => {
17
- return Date
28
+ return Date;
18
29
  })(),
19
30
  log: (() => {
20
- return __log__
31
+ return __log__;
21
32
  })(),
33
+ error: _error,
22
34
  Error: (() => {
23
- return Error
35
+ return Error;
24
36
  })(),
25
37
  RegExp: (() => {
26
- return RegExp
38
+ return RegExp;
27
39
  })(),
28
-
29
40
  }
30
41
 
31
- const _error = console.error;
32
- console.error = (...msg) => {
33
- let isOutput = true;
34
- [...msg].forEach(v => {
35
- if (v?.includes?.(`Setting the NODE_TLS_REJECT_UNAUTHORIZED`)) {
36
- isOutput = false;
37
- }
38
- })
39
- isOutput && _error(...msg);
40
- }
42
+
41
43
  Object.defineProperty(global, '__stack', {
42
44
  get: function () {
43
45
  return new Error().stack.split('\n').slice(2);
@@ -143,7 +145,7 @@ class Logger {
143
145
 
144
146
  error(...msg) {
145
147
  let pathLine = this?.path ? `[${this.path}:${__line}]` : "Anonymous";
146
- loggerConfig.log(consoleStyles['green'][0] + dateFormat("YYYY-mm-dd HH:MM:SS.ms", new loggerConfig.Date()),
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],
@@ -218,7 +220,7 @@ class Logger {
218
220
 
219
221
  module.exports = Logger;
220
222
 
221
- /* How to use:
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@youpaichris/logger",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {