@athenna/logger 3.0.6 → 3.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/logger",
3
- "version": "3.0.6",
3
+ "version": "3.0.8",
4
4
  "description": "The Athenna logging solution. Log in stdout, files and buckets.",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -51,9 +51,9 @@
51
51
  "telegraf": "4.7.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@athenna/common": "3.0.1",
55
- "@athenna/config": "3.0.3",
56
- "@athenna/ioc": "3.0.1",
54
+ "@athenna/common": "3.0.2",
55
+ "@athenna/config": "3.0.4",
56
+ "@athenna/ioc": "3.0.2",
57
57
  "@japa/assert": "1.3.4",
58
58
  "@japa/run-failed-tests": "1.0.7",
59
59
  "@japa/runner": "2.0.7",
@@ -135,8 +135,10 @@
135
135
  "node": true
136
136
  },
137
137
  "globals": {
138
+ "ioc": true,
138
139
  "Env": true,
139
- "ioc": true
140
+ "Path": true,
141
+ "Config": true
140
142
  },
141
143
  "plugins": [
142
144
  "prettier"
@@ -20,6 +20,7 @@ import { TelegramDriver } from '#src/Drivers/TelegramDriver'
20
20
  import { DriverExistException } from '#src/Exceptions/DriverExistException'
21
21
  import { NotFoundDriverException } from '#src/Exceptions/NotFoundDriverException'
22
22
  import { NotImplementedConfigException } from '#src/Exceptions/NotImplementedConfigException'
23
+ import { Options } from '@athenna/common'
23
24
 
24
25
  export class DriverFactory {
25
26
  /**
@@ -70,17 +71,21 @@ export class DriverFactory {
70
71
  }
71
72
 
72
73
  /**
73
- * Fabricate a new instance of a driver without
74
+ * Fabricate a new instance of a driver with vanilla
74
75
  * configurations.
75
76
  *
76
- * @param {string} driverName
77
- * @param {any} runtimeConfig
77
+ * @param {any} configs
78
78
  * @return {any}
79
79
  */
80
- static fabricateOnly(driverName, runtimeConfig = {}) {
81
- const { Driver } = this.#drivers.get(driverName)
80
+ static fabricateVanilla(configs = {}) {
81
+ configs = Options.create(configs, {
82
+ driver: 'console',
83
+ formatter: 'none',
84
+ })
85
+
86
+ const { Driver } = this.#drivers.get(configs.driver)
82
87
 
83
- return new Driver(runtimeConfig)
88
+ return new Driver(configs)
84
89
  }
85
90
 
86
91
  /**
@@ -10,7 +10,7 @@
10
10
  import { ColorHelper } from '#src/index'
11
11
  import { DriverFactory } from '#src/Factories/DriverFactory'
12
12
 
13
- export class ConsoleLogger {
13
+ export class VanillaLogger {
14
14
  /**
15
15
  * The driver responsible for transporting the logs.
16
16
  *
@@ -21,18 +21,18 @@ export class ConsoleLogger {
21
21
  /**
22
22
  * Creates a new instance of ConsoleLogger.
23
23
  *
24
- * @param {any} [runtimeConfigs]
25
- * @return {ConsoleLogger}
24
+ * @param {any} [configs]
25
+ * @return {VanillaLogger}
26
26
  */
27
- constructor(runtimeConfigs) {
28
- this.#drivers.push(DriverFactory.fabricateOnly('console', runtimeConfigs))
27
+ constructor(configs) {
28
+ this.#drivers.push(DriverFactory.fabricateVanilla(configs))
29
29
  }
30
30
 
31
31
  /**
32
32
  * Set runtime configurations for drivers and
33
33
  * formatters.
34
34
  *
35
- * @return {ConsoleLogger}
35
+ * @return {VanillaLogger}
36
36
  */
37
37
  config() {
38
38
  return this
@@ -41,7 +41,7 @@ export class ConsoleLogger {
41
41
  /**
42
42
  * Change the log channel.
43
43
  *
44
- * @return {ConsoleLogger}
44
+ * @return {VanillaLogger}
45
45
  */
46
46
  channel() {
47
47
  return this
package/src/index.d.ts CHANGED
@@ -523,7 +523,24 @@ export class FormatterFactory {
523
523
  static createFormatter(name: string, formatter: () => any): void
524
524
  }
525
525
 
526
- export class ConsoleLogger {
526
+ export class VanillaLogger {
527
+ /**
528
+ * Set runtime configurations for drivers and
529
+ * formatters.
530
+ *
531
+ * @param {any} runtimeConfig
532
+ * @return {VanillaLogger}
533
+ */
534
+ config(runtimeConfig: any): VanillaLogger
535
+
536
+ /**
537
+ * Change the log channel.
538
+ *
539
+ * @param {string[]} channels
540
+ * @return {VanillaLogger}
541
+ */
542
+ channel(...channels: string[]): VanillaLogger
543
+
527
544
  /**
528
545
  * Creates a log of type trace in channel.
529
546
  *
@@ -619,17 +636,25 @@ export class ConsoleLogger {
619
636
  * @return {any | Promise<any>}
620
637
  */
621
638
  error(...args: string[] | any[]): any | Promise<any>
622
- }
623
639
 
624
- export class Logger {
625
640
  /**
626
- * Get a new instance of the ConsoleLogger.
641
+ * Creates a log of type fatal in channel.
627
642
  *
628
- * @param {any} [runtimeConfigs]
629
- * @return {ConsoleLogger}
643
+ * @param {string|any} message
644
+ * @return {any | Promise<any>}
630
645
  */
631
- static getConsoleLogger(runtimeConfigs?: any): ConsoleLogger
646
+ fatal(message: string | any): any | Promise<any>
632
647
 
648
+ /**
649
+ * Creates a log of type fatal in channel.
650
+ *
651
+ * @param {string[]|any[]} args
652
+ * @return {any | Promise<any>}
653
+ */
654
+ fatal(...args: string[] | any[]): any | Promise<any>
655
+ }
656
+
657
+ export class Logger {
633
658
  /**
634
659
  * Set runtime configurations for drivers and
635
660
  * formatters.
@@ -742,4 +767,31 @@ export class Logger {
742
767
  * @return {any | Promise<any>}
743
768
  */
744
769
  error(...args: string[] | any[]): any | Promise<any>
770
+
771
+ /**
772
+ * Creates a log of type fatal in channel.
773
+ *
774
+ * @param {string|any} message
775
+ * @return {any | Promise<any>}
776
+ */
777
+ fatal(message: string | any): any | Promise<any>
778
+
779
+ /**
780
+ * Creates a log of type fatal in channel.
781
+ *
782
+ * @param {string[]|any[]} args
783
+ * @return {any | Promise<any>}
784
+ */
785
+ fatal(...args: string[] | any[]): any | Promise<any>
786
+
787
+ /**
788
+ * Get a new instance of any log driver
789
+ * with vanilla configurations. By default,
790
+ * vanilla logger will use the "console" driver
791
+ * and "none" formatter.
792
+ *
793
+ * @param {any} [configs]
794
+ * @return {VanillaLogger}
795
+ */
796
+ static getVanillaLogger(configs?: any): VanillaLogger
745
797
  }
package/src/index.js CHANGED
@@ -8,13 +8,13 @@
8
8
  */
9
9
 
10
10
  import { ColorHelper } from '#src/index'
11
- import { ConsoleLogger } from '#src/Helpers/ConsoleLogger'
11
+ import { VanillaLogger } from '#src/Helpers/VanillaLogger'
12
12
  import { DriverFactory } from '#src/Factories/DriverFactory'
13
13
 
14
14
  export * from './Facades/Log.js'
15
15
 
16
16
  export * from './Helpers/ColorHelper.js'
17
- export * from './Helpers/ConsoleLogger.js'
17
+ export * from './Helpers/VanillaLogger.js'
18
18
  export * from './Helpers/FactoryHelper.js'
19
19
 
20
20
  export * from './Drivers/Driver.js'
@@ -24,16 +24,6 @@ export * from './Factories/DriverFactory.js'
24
24
  export * from './Factories/FormatterFactory.js'
25
25
 
26
26
  export class Logger {
27
- /**
28
- * Get a new instance of the ConsoleLogger.
29
- *
30
- * @param {any} [runtimeConfigs]
31
- * @return {ConsoleLogger}
32
- */
33
- static getConsoleLogger(runtimeConfigs) {
34
- return new ConsoleLogger(runtimeConfigs)
35
- }
36
-
37
27
  /**
38
28
  * The driver responsible for transporting the logs.
39
29
  *
@@ -54,6 +44,10 @@ export class Logger {
54
44
  * @return {Logger}
55
45
  */
56
46
  constructor() {
47
+ if (!Config.exists(`logging.channels.${Config.get('logging.default')}`)) {
48
+ return this
49
+ }
50
+
57
51
  this.#drivers.push(DriverFactory.fabricate('default', this.#runtimeConfigs))
58
52
  }
59
53
 
@@ -170,4 +164,17 @@ export class Logger {
170
164
  fatal(...args) {
171
165
  return this.#log('fatal', ...args)
172
166
  }
167
+
168
+ /**
169
+ * Get a new instance of any log driver
170
+ * with vanilla configurations. By default,
171
+ * vanilla logger will use the "console" driver
172
+ * and "none" formatter.
173
+ *
174
+ * @param {any} [configs]
175
+ * @return {VanillaLogger}
176
+ */
177
+ static getVanillaLogger(configs = {}) {
178
+ return new VanillaLogger(configs)
179
+ }
173
180
  }