@athenna/logger 1.2.8 → 1.2.9

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.
@@ -9,97 +9,7 @@
9
9
 
10
10
  import { Options } from '@secjs/utils'
11
11
 
12
- import { ColorHelper } from '#src/Helpers/ColorHelper'
13
-
14
12
  export class FactoryHelper {
15
- /**
16
- * Get the timestamp value formatted.
17
- *
18
- * @return {string}
19
- */
20
- static getTimestamp() {
21
- const localeStringOptions = {
22
- year: 'numeric',
23
- hour: 'numeric',
24
- minute: 'numeric',
25
- second: 'numeric',
26
- day: '2-digit',
27
- month: '2-digit',
28
- }
29
-
30
- return new Date(Date.now()).toLocaleString(undefined, localeStringOptions)
31
- }
32
-
33
- /**
34
- * Get the timestamp diff between logs.
35
- *
36
- * @param {number} lastTimestamp
37
- * @return {string}
38
- */
39
- static getTimestampDiff(lastTimestamp) {
40
- let timestampDiff = ''
41
-
42
- if (lastTimestamp) {
43
- timestampDiff = ColorHelper.yellow(` +${Date.now() - lastTimestamp}ms`)
44
- }
45
-
46
- return timestampDiff
47
- }
48
-
49
- /**
50
- * Get the emoji by level.
51
- *
52
- * @param {string} level
53
- * @param {string} [customEmoji]
54
- * @return {string}
55
- */
56
- static getEmojiByLevel(level, customEmoji) {
57
- if (customEmoji) {
58
- return customEmoji
59
- }
60
-
61
- const levelEmojis = {
62
- info: '\u{2139}',
63
- debug: '\u{1F50E}',
64
- warn: '\u{26A0}',
65
- error: '\u{274C}',
66
- success: '\u{2705}',
67
- critical: '\u{1F6D1}',
68
- }
69
-
70
- if (!levelEmojis[level.toLowerCase()]) {
71
- return ''
72
- }
73
-
74
- return levelEmojis[level.toLowerCase()]
75
- }
76
-
77
- /**
78
- * Paint the message by level.
79
- *
80
- * @param {string} level
81
- * @param {string} message
82
- * @return {string}
83
- */
84
- static paintByLevel(level, message) {
85
- level = level.toLowerCase()
86
-
87
- const levelColors = {
88
- info: ColorHelper.info,
89
- debug: ColorHelper.debug,
90
- warn: ColorHelper.warning,
91
- error: ColorHelper.error,
92
- success: ColorHelper.success,
93
- critical: ColorHelper.critical,
94
- }
95
-
96
- if (!levelColors[level]) {
97
- return message
98
- }
99
-
100
- return levelColors[level](message)
101
- }
102
-
103
13
  /**
104
14
  * Group the configuration values.
105
15
  *
package/src/index.d.ts CHANGED
@@ -2,6 +2,200 @@ import { Facade } from '@athenna/ioc'
2
2
 
3
3
  export const Log: Facade & Logger
4
4
 
5
+ export class Driver {
6
+ /**
7
+ * Holds the configuration object itself.
8
+ *
9
+ * @type {any}
10
+ */
11
+ configs: any
12
+
13
+ /**
14
+ * Holds the configuration object of driver.
15
+ *
16
+ * @type {any}
17
+ */
18
+ driverConfig: any
19
+
20
+ /**
21
+ * Holds the formatter string value.
22
+ *
23
+ * @type {string}
24
+ */
25
+ formatter: string
26
+
27
+ /**
28
+ * Holds the configuration object of formatter.
29
+ *
30
+ * @type {any}
31
+ */
32
+ formatterConfig: any
33
+
34
+ /**
35
+ * The max log level that this driver can transport.
36
+ *
37
+ * @return {string}
38
+ */
39
+ level: string
40
+
41
+ /**
42
+ * The log level order to check if log could
43
+ * be transported or not.
44
+ *
45
+ * @type {string[]}
46
+ */
47
+ levelOrder: string[]
48
+
49
+ /**
50
+ * Creates a new instance of ConsoleDriver.
51
+ *
52
+ * @param {any} configs
53
+ * @return {Driver}
54
+ */
55
+ constructor(configs: any)
56
+
57
+ /**
58
+ * Transport the log.
59
+ *
60
+ * @param {string} level
61
+ * @param {string} message
62
+ * @return {any | Promise<any>}
63
+ */
64
+ transport(level: string, message: string): any | Promise<any>
65
+
66
+ /**
67
+ * Check if message could be transported.
68
+ *
69
+ * @param level {string}
70
+ * @return {boolean}
71
+ */
72
+ couldBeTransported(level: string): boolean
73
+
74
+ /**
75
+ * Call formatter factory to format the message.
76
+ *
77
+ * @param level {string}
78
+ * @param message {string}
79
+ * @param [clean] {boolean}
80
+ * @return {any}
81
+ */
82
+ format(level: string, message: string, clean?: boolean): any
83
+
84
+ /**
85
+ * Get the stream type for level.
86
+ *
87
+ * @param level {string}
88
+ * @return {string}
89
+ */
90
+ getStreamTypeFor(level: string): string
91
+ }
92
+
93
+ export class Formatter {
94
+ /**
95
+ * Holds the configuration object of formatter.
96
+ */
97
+ configs: any
98
+
99
+ /**
100
+ * Creates a new instance of Formatter.
101
+ *
102
+ * @param {any} configs
103
+ * @return {Formatter}
104
+ */
105
+ config(configs: any): Formatter
106
+
107
+ /**
108
+ * Format the message.
109
+ *
110
+ * @param {string} message
111
+ * @return {string}
112
+ */
113
+ format(message: string): string
114
+
115
+ /**
116
+ * Create the PID for formatter.
117
+ *
118
+ * @return {string}
119
+ */
120
+ pid(): string
121
+
122
+ /**
123
+ * Create the hostname for formatter.
124
+ *
125
+ * @return {string}
126
+ */
127
+ hostname(): string
128
+
129
+ /**
130
+ * Create the timestamp for formatter.
131
+ *
132
+ * @return {string}
133
+ */
134
+ timestamp(): string
135
+
136
+ /**
137
+ * Transform the message to string.
138
+ *
139
+ * @param message {string}
140
+ * @return {string}
141
+ */
142
+ toString(message: string): string
143
+
144
+ /**
145
+ * Clean the message removing colors if clean
146
+ * option is true.
147
+ *
148
+ * @param message {string}
149
+ * @return {string}
150
+ */
151
+ clean(message: string): string
152
+
153
+ /**
154
+ * Apply all colors necessary to message.
155
+ *
156
+ * @param message {string}
157
+ * @return {string}
158
+ */
159
+ applyColors(message: string): string
160
+
161
+ /**
162
+ * Apply colors in message.
163
+ *
164
+ * @param message {string}
165
+ * @return {string}
166
+ */
167
+ applyColorsByChalk(message: string): string
168
+
169
+ /**
170
+ * Apply colors in message by level.
171
+ *
172
+ * @param message {string}
173
+ * @return {string}
174
+ */
175
+ applyColorsByLevel(message: string): string
176
+
177
+ /**
178
+ * Create the cli level string.
179
+ *
180
+ * @return {string}
181
+ */
182
+ cliLevel(): string
183
+
184
+ /**
185
+ * Create the simple level string.
186
+ *
187
+ * @return {string}
188
+ */
189
+ simpleLevel(): string
190
+
191
+ /**
192
+ * Create the message level emoji string.
193
+ *
194
+ * @return {string}
195
+ */
196
+ messageLevel(): string
197
+ }
198
+
5
199
  export class ColorHelper {
6
200
  /**
7
201
  * Chalk instance.
@@ -80,6 +274,20 @@ export class ColorHelper {
80
274
  */
81
275
  static get red(): import('chalk').ChalkInstance
82
276
 
277
+ /**
278
+ * Paint traces.
279
+ *
280
+ * @return {import('chalk').ChalkInstance}
281
+ */
282
+ static get trace(): import('chalk').ChalkInstance
283
+
284
+ /**
285
+ * Paint debugs.
286
+ *
287
+ * @return {import('chalk').ChalkInstance}
288
+ */
289
+ static get debug(): import('chalk').ChalkInstance
290
+
83
291
  /**
84
292
  * Paint infos.
85
293
  *
@@ -88,18 +296,18 @@ export class ColorHelper {
88
296
  static get info(): import('chalk').ChalkInstance
89
297
 
90
298
  /**
91
- * Paint logs.
299
+ * Paint success.
92
300
  *
93
301
  * @return {import('chalk').ChalkInstance}
94
302
  */
95
- static get log(): import('chalk').ChalkInstance
303
+ static get success(): import('chalk').ChalkInstance
96
304
 
97
305
  /**
98
- * Paint debugs.
306
+ * Paint warns.
99
307
  *
100
308
  * @return {import('chalk').ChalkInstance}
101
309
  */
102
- static get debug(): import('chalk').ChalkInstance
310
+ static get warn(): import('chalk').ChalkInstance
103
311
 
104
312
  /**
105
313
  * Paint errors.
@@ -109,11 +317,11 @@ export class ColorHelper {
109
317
  static get error(): import('chalk').ChalkInstance
110
318
 
111
319
  /**
112
- * Paint warnings.
320
+ * Paint fatals.
113
321
  *
114
322
  * @return {import('chalk').ChalkInstance}
115
323
  */
116
- static get warning(): import('chalk').ChalkInstance
324
+ static get fatal(): import('chalk').ChalkInstance
117
325
 
118
326
  /**
119
327
  * Paint http method.
@@ -168,9 +376,9 @@ export class ColorHelper {
168
376
  * Remove all colors and special chars of string.
169
377
  *
170
378
  * @param {string} string
171
- * @return {import('chalk').ChalkInstance}
379
+ * @return {string}
172
380
  */
173
- static removeColors(string: string): import('chalk').ChalkInstance
381
+ static removeColors(string: string): string
174
382
 
175
383
  /**
176
384
  * Paint by the http method.
@@ -182,39 +390,6 @@ export class ColorHelper {
182
390
  }
183
391
 
184
392
  export class FactoryHelper {
185
- /**
186
- * Get the timestamp value formatted.
187
- *
188
- * @return {string}
189
- */
190
- static getTimestamp(): string
191
-
192
- /**
193
- * Get the timestamp diff between logs.
194
- *
195
- * @param {number} lastTimestamp
196
- * @return {string}
197
- */
198
- static getTimestampDiff(lastTimestamp: number): string
199
-
200
- /**
201
- * Get the emoji by level.
202
- *
203
- * @param {string} level
204
- * @param {string} [customEmoji]
205
- * @return {string}
206
- */
207
- static getEmojiByLevel(level: string, customEmoji?: string): string
208
-
209
- /**
210
- * Paint the message by level.
211
- *
212
- * @param {string} level
213
- * @param {string|any} message
214
- * @return {string}
215
- */
216
- static paintByLevel(level: string, message: string): string
217
-
218
393
  /**
219
394
  * Group the configuration values.
220
395
  *
@@ -323,56 +498,98 @@ export class Logger {
323
498
  channel(...channels: string[]): Logger
324
499
 
325
500
  /**
326
- * Creates a log of type info in channel.
501
+ * Creates a log of type trace in channel.
327
502
  *
328
503
  * @param {string|any} message
329
- * @param {any} [options]
330
- * @return {void | Promise<void>}
504
+ * @return {any | Promise<any>}
331
505
  */
332
- info(message: string | any, options?: any): void | Promise<void>
506
+ trace(message: string | any): any | Promise<any>
333
507
 
334
508
  /**
335
- * Creates a log of type warn in channel.
509
+ * Creates a log of type trace in channel.
336
510
  *
337
- * @param {string|any} message
338
- * @param {any} [options]
339
- * @return {void | Promise<void>}
511
+ * @param {string[]|any[]} args
512
+ * @return {any | Promise<any>}
340
513
  */
341
- warn(message: string | any, options?: any): void | Promise<void>
514
+ trace(...args: string[] | any[]): any | Promise<any>
342
515
 
343
516
  /**
344
- * Creates a log of type error in channel.
517
+ * Creates a log of type debug in channel.
345
518
  *
346
519
  * @param {string|any} message
347
- * @param {any} [options]
348
- * @return {void | Promise<void>}
520
+ * @return {any | Promise<any>}
521
+ */
522
+ debug(message: string | any): any | Promise<any>
523
+
524
+ /**
525
+ * Creates a log of type debug in channel.
526
+ *
527
+ * @param {string[]|any[]} args
528
+ * @return {any | Promise<any>}
349
529
  */
350
- error(message: string | any, options?: any): void | Promise<void>
530
+ debug(...args: string[] | any[]): any | Promise<any>
351
531
 
352
532
  /**
353
- * Creates a log of type critical in channel.
533
+ * Creates a log of type info in channel.
354
534
  *
355
535
  * @param {string|any} message
356
- * @param {any} [options]
357
- * @return {void | Promise<void>}
536
+ * @return {any | Promise<any>}
358
537
  */
359
- critical(message: string | any, options?: any): void | Promise<void>
538
+ info(message: string | any): any | Promise<any>
360
539
 
361
540
  /**
362
- * Creates a log of type debug in channel.
541
+ * Creates a log of type info in channel.
542
+ *
543
+ * @param {string[]|any[]} args
544
+ * @return {any | Promise<any>}
545
+ */
546
+ info(...args: string[] | any[]): any | Promise<any>
547
+
548
+ /**
549
+ * Creates a log of type success in channel.
363
550
  *
364
551
  * @param {string|any} message
365
- * @param {any} [options]
366
- * @return {void | Promise<void>}
552
+ * @return {any | Promise<any>}
367
553
  */
368
- debug(message: string | any, options?: any): void | Promise<void>
554
+ success(message: string | any): any | Promise<any>
369
555
 
370
556
  /**
371
557
  * Creates a log of type success in channel.
372
558
  *
559
+ * @param {string[]|any[]} args
560
+ * @return {any | Promise<any>}
561
+ */
562
+ success(...args: string[] | any[]): any | Promise<any>
563
+
564
+ /**
565
+ * Creates a log of type warn in channel.
566
+ *
567
+ * @param {string|any} message
568
+ * @return {any | Promise<any>}
569
+ */
570
+ warn(message: string | any): any | Promise<any>
571
+
572
+ /**
573
+ * Creates a log of type warn in channel.
574
+ *
575
+ * @param {string[]|any[]} args
576
+ * @return {any | Promise<any>}
577
+ */
578
+ warn(...args: string[] | any[]): any | Promise<any>
579
+
580
+ /**
581
+ * Creates a log of type error in channel.
582
+ *
373
583
  * @param {string|any} message
374
- * @param {any} [options]
375
- * @return {void | Promise<void>}
584
+ * @return {any | Promise<any>}
585
+ */
586
+ error(message: string | any): any | Promise<any>
587
+
588
+ /**
589
+ * Creates a log of type error in channel.
590
+ *
591
+ * @param {string[]|any[]} args
592
+ * @return {any | Promise<any>}
376
593
  */
377
- success(message: string | any, options?: any): void | Promise<void>
594
+ error(...args: string[] | any[]): any | Promise<any>
378
595
  }