@athenna/logger 3.0.9 → 3.1.1

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.
Files changed (83) hide show
  1. package/build/Drivers/ConsoleDriver.d.ts +12 -0
  2. package/build/Drivers/ConsoleDriver.js +19 -0
  3. package/build/Drivers/DiscordDriver.d.ts +12 -0
  4. package/build/Drivers/DiscordDriver.js +22 -0
  5. package/build/Drivers/Driver.d.ts +52 -0
  6. package/build/Drivers/Driver.js +85 -0
  7. package/build/Drivers/FileDriver.d.ts +12 -0
  8. package/build/Drivers/FileDriver.js +24 -0
  9. package/build/Drivers/NullDriver.d.ts +12 -0
  10. package/build/Drivers/NullDriver.js +14 -0
  11. package/build/Drivers/SlackDriver.d.ts +12 -0
  12. package/build/Drivers/SlackDriver.js +19 -0
  13. package/build/Drivers/StackDriver.d.ts +12 -0
  14. package/build/Drivers/StackDriver.js +19 -0
  15. package/build/Drivers/TelegramDriver.d.ts +12 -0
  16. package/build/Drivers/TelegramDriver.js +21 -0
  17. package/build/Exceptions/DriverExistException.d.ts +12 -0
  18. package/build/Exceptions/DriverExistException.js +21 -0
  19. package/{src/Facades/Log.js → build/Exceptions/FormatterExistException.d.ts} +4 -9
  20. package/build/Exceptions/FormatterExistException.js +21 -0
  21. package/build/Exceptions/NotFoundDriverException.d.ts +12 -0
  22. package/build/Exceptions/NotFoundDriverException.js +21 -0
  23. package/build/Exceptions/NotFoundFormatterException.d.ts +12 -0
  24. package/build/Exceptions/NotFoundFormatterException.js +21 -0
  25. package/build/Exceptions/NotImplementedConfigException.d.ts +12 -0
  26. package/build/Exceptions/NotImplementedConfigException.js +28 -0
  27. package/build/Facades/Log.d.ts +10 -0
  28. package/build/Facades/Log.js +10 -0
  29. package/build/Factories/DriverFactory.d.ts +39 -0
  30. package/build/Factories/DriverFactory.js +93 -0
  31. package/build/Factories/FormatterFactory.d.ts +29 -0
  32. package/build/Factories/FormatterFactory.js +57 -0
  33. package/build/Formatters/CliFormatter.d.ts +12 -0
  34. package/build/Formatters/CliFormatter.js +15 -0
  35. package/build/Formatters/Formatter.d.ts +85 -0
  36. package/build/Formatters/Formatter.js +176 -0
  37. package/build/Formatters/JsonFormatter.d.ts +12 -0
  38. package/build/Formatters/JsonFormatter.js +26 -0
  39. package/build/Formatters/MessageFormatter.d.ts +12 -0
  40. package/build/Formatters/MessageFormatter.js +14 -0
  41. package/build/Formatters/NoneFormatter.d.ts +12 -0
  42. package/{src → build}/Formatters/NoneFormatter.js +4 -12
  43. package/build/Formatters/RequestFormatter.d.ts +12 -0
  44. package/build/Formatters/RequestFormatter.js +48 -0
  45. package/build/Formatters/SimpleFormatter.d.ts +12 -0
  46. package/build/Formatters/SimpleFormatter.js +18 -0
  47. package/build/Helpers/FactoryHelper.d.ts +14 -0
  48. package/build/Helpers/FactoryHelper.js +20 -0
  49. package/build/Logger/Logger.d.ts +68 -0
  50. package/build/Logger/Logger.js +105 -0
  51. package/build/Logger/VanillaLogger.d.ts +65 -0
  52. package/build/Logger/VanillaLogger.js +93 -0
  53. package/build/Providers/LoggerProvider.d.ts +12 -0
  54. package/{src → build}/Providers/LoggerProvider.js +5 -12
  55. package/build/index.d.ts +17 -0
  56. package/build/index.js +17 -0
  57. package/package.json +82 -61
  58. package/src/Drivers/ConsoleDriver.js +0 -40
  59. package/src/Drivers/DiscordDriver.js +0 -43
  60. package/src/Drivers/Driver.js +0 -134
  61. package/src/Drivers/FileDriver.js +0 -47
  62. package/src/Drivers/NullDriver.js +0 -33
  63. package/src/Drivers/SlackDriver.js +0 -40
  64. package/src/Drivers/StackDriver.js +0 -45
  65. package/src/Drivers/TelegramDriver.js +0 -46
  66. package/src/Exceptions/DriverExistException.js +0 -31
  67. package/src/Exceptions/FormatterExistException.js +0 -32
  68. package/src/Exceptions/NotFoundDriverException.js +0 -31
  69. package/src/Exceptions/NotFoundFormatterException.js +0 -31
  70. package/src/Exceptions/NotImplementedConfigException.js +0 -37
  71. package/src/Factories/DriverFactory.js +0 -128
  72. package/src/Factories/FormatterFactory.js +0 -77
  73. package/src/Formatters/CliFormatter.js +0 -24
  74. package/src/Formatters/Formatter.js +0 -266
  75. package/src/Formatters/JsonFormatter.js +0 -37
  76. package/src/Formatters/MessageFormatter.js +0 -26
  77. package/src/Formatters/RequestFormatter.js +0 -64
  78. package/src/Formatters/SimpleFormatter.js +0 -27
  79. package/src/Helpers/ColorHelper.js +0 -322
  80. package/src/Helpers/FactoryHelper.js +0 -31
  81. package/src/Helpers/VanillaLogger.js +0 -134
  82. package/src/index.d.ts +0 -797
  83. package/src/index.js +0 -180
@@ -1,43 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { HttpClient } from '@athenna/common'
11
- import { Driver } from '#src/Drivers/Driver'
12
-
13
- export class DiscordDriver extends Driver {
14
- /**
15
- * Creates a new instance of DiscordDriver.
16
- *
17
- * @param {any} configs
18
- * @return {DiscordDriver}
19
- */
20
- constructor(configs) {
21
- super(configs)
22
- }
23
-
24
- /**
25
- * Transport the log.
26
- *
27
- * @param {string} level
28
- * @param {string} message
29
- * @return {Promise<any>}
30
- */
31
- async transport(level, message) {
32
- if (!this.couldBeTransported(level)) {
33
- return
34
- }
35
-
36
- const formatted = this.format(level, message, true)
37
-
38
- return HttpClient.builder(true).post(this.configs.url, {
39
- username: this.configs.username,
40
- content: formatted,
41
- })
42
- }
43
- }
@@ -1,134 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Json } from '@athenna/common'
11
- import { FormatterFactory } from '#src/index'
12
-
13
- export class Driver {
14
- /**
15
- * Holds the configuration object itself.
16
- *
17
- * @type {any}
18
- */
19
- configs = {}
20
-
21
- /**
22
- * Holds the configuration object of driver.
23
- *
24
- * @type {any}
25
- */
26
- driverConfig = {}
27
-
28
- /**
29
- * Holds the formatter string value.
30
- *
31
- * @type {string}
32
- */
33
- formatter = 'none'
34
-
35
- /**
36
- * Holds the configuration object of formatter.
37
- *
38
- * @type {any}
39
- */
40
- formatterConfig = {}
41
-
42
- /**
43
- * The max log level that this driver can transport.
44
- *
45
- * @return {string}
46
- */
47
- level = 'info'
48
-
49
- /**
50
- * The log level order to check if log could
51
- * be transported or not.
52
- *
53
- * @type {string[]}
54
- */
55
- levelOrder = ['trace', 'debug', 'info', 'success', 'warn', 'error', 'fatal']
56
-
57
- /**
58
- * Creates a new instance of ConsoleDriver.
59
- *
60
- * @param {any} configs
61
- * @return {ConsoleDriver}
62
- */
63
- constructor(configs = {}) {
64
- this.configs = configs
65
-
66
- const json = Json.copy(configs)
67
-
68
- delete json.formatter
69
- delete json.formatterConfig
70
-
71
- this.driverConfig = json
72
- this.level = json.level || 'info'
73
- this.formatter = configs.formatter || 'none'
74
- this.formatterConfig = configs.formatterConfig || {}
75
- }
76
-
77
- /**
78
- * Transport the log.
79
- *
80
- * @param {string} level
81
- * @param {string} message
82
- * @return {any | Promise<any>}
83
- */
84
- transport(level, message) {}
85
-
86
- /**
87
- * Check if message could be transported.
88
- *
89
- * @param level {string}
90
- * @return {boolean}
91
- */
92
- couldBeTransported(level) {
93
- const levelIndex = this.levelOrder.indexOf(level)
94
- const maxLevelIndex = this.levelOrder.indexOf(this.level)
95
-
96
- return levelIndex >= maxLevelIndex
97
- }
98
-
99
- /**
100
- * Call formatter factory to format the message.
101
- *
102
- * @param level {string}
103
- * @param message {string}
104
- * @param [clean] {boolean}
105
- * @return {any}
106
- */
107
- format(level, message, clean = false) {
108
- const formatterConfig = { level, clean, ...this.formatterConfig }
109
-
110
- return FormatterFactory.fabricate(this.formatter)
111
- .config(formatterConfig)
112
- .format(message)
113
- }
114
-
115
- /**
116
- * Get the stream type for level.
117
- *
118
- * @param level {string}
119
- * @return {string}
120
- */
121
- getStreamTypeFor(level) {
122
- if (this.driverConfig.streamType) {
123
- return this.driverConfig.streamType
124
- }
125
-
126
- let streamType = 'stdout'
127
-
128
- if (level === 'error' || level === 'fatal') {
129
- streamType = 'stderr'
130
- }
131
-
132
- return streamType
133
- }
134
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { File } from '@athenna/common'
11
-
12
- import { Driver } from '#src/Drivers/Driver'
13
-
14
- export class FileDriver extends Driver {
15
- /**
16
- * Creates a new instance of FileDriver.
17
- *
18
- * @param {any} configs
19
- * @return {FileDriver}
20
- */
21
- constructor(configs) {
22
- super(configs)
23
- }
24
-
25
- /**
26
- * Transport the log.
27
- *
28
- * @param {string} level
29
- * @param {string} message
30
- * @return {Promise<any>}
31
- */
32
- async transport(level, message) {
33
- if (!this.couldBeTransported(level)) {
34
- return
35
- }
36
-
37
- const filePath = this.driverConfig.filePath
38
- const formatted = this.format(level, message, true)
39
- const buffer = Buffer.from(`${formatted}\n`, 'utf-8')
40
-
41
- if (await File.exists(filePath)) {
42
- return new File(filePath).append(buffer)
43
- }
44
-
45
- return new File(filePath, buffer).load()
46
- }
47
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Driver } from '#src/Drivers/Driver'
11
-
12
- export class NullDriver extends Driver {
13
- /**
14
- * Creates a new instance of NullDriver.
15
- *
16
- * @param {string} configs
17
- * @return {NullDriver}
18
- */
19
- constructor(configs) {
20
- super(configs)
21
- }
22
-
23
- /**
24
- * Transport the log.
25
- *
26
- * @param {string} level
27
- * @param {string} message
28
- * @return {any}
29
- */
30
- transport(level, message) {
31
- return null
32
- }
33
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { HttpClient } from '@athenna/common'
11
- import { Driver } from '#src/Drivers/Driver'
12
-
13
- export class SlackDriver extends Driver {
14
- /**
15
- * Creates a new instance of SlackDriver.
16
- *
17
- * @param {any} configs
18
- * @return {SlackDriver}
19
- */
20
- constructor(configs) {
21
- super(configs)
22
- }
23
-
24
- /**
25
- * Transport the log.
26
- *
27
- * @param {string} level
28
- * @param {string} message
29
- * @return {Promise<any>}
30
- */
31
- async transport(level, message) {
32
- if (!this.couldBeTransported(level)) {
33
- return
34
- }
35
-
36
- const formatted = this.format(level, message, true)
37
-
38
- return HttpClient.builder(true).post(this.configs.url, { text: formatted })
39
- }
40
- }
@@ -1,45 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Json } from '@athenna/common'
11
-
12
- import { Driver } from '#src/Drivers/Driver'
13
- import { DriverFactory } from '#src/Factories/DriverFactory'
14
-
15
- export class StackDriver extends Driver {
16
- /**
17
- * Creates a new instance of StackDriver.
18
- *
19
- * @param {any} configs
20
- * @return {StackDriver}
21
- */
22
- constructor(configs) {
23
- super(configs)
24
- }
25
-
26
- /**
27
- * Transport the log.
28
- *
29
- * @param {string} level
30
- * @param {any} message
31
- * @return {any}
32
- */
33
- transport(level, message) {
34
- const configs = Json.copy(this.configs)
35
-
36
- delete configs.driver
37
- delete configs.channels
38
-
39
- return Promise.all(
40
- this.driverConfig.channels.map(c =>
41
- DriverFactory.fabricate(c, configs).transport(level, message),
42
- ),
43
- )
44
- }
45
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Telegraf } from 'telegraf'
11
- import { Driver } from '#src/Drivers/Driver'
12
-
13
- export class TelegramDriver extends Driver {
14
- /**
15
- * Creates a new instance of TelegramDriver.
16
- *
17
- * @param {any} configs
18
- * @return {TelegramDriver}
19
- */
20
- constructor(configs) {
21
- super(configs)
22
- }
23
-
24
- /**
25
- * Transport the log.
26
- *
27
- * @param {string} level
28
- * @param {string} message
29
- * @return {Promise<any>}
30
- */
31
- async transport(level, message) {
32
- if (!this.couldBeTransported(level)) {
33
- return
34
- }
35
-
36
- const formatted = this.format(level, message, true)
37
-
38
- return new Telegraf(this.driverConfig.token).telegram.sendMessage(
39
- this.driverConfig.chatId,
40
- formatted,
41
- {
42
- parse_mode: this.driverConfig.parseMode,
43
- },
44
- )
45
- }
46
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Exception } from '@athenna/common'
11
- import { DriverFactory } from '#src/Factories/DriverFactory'
12
-
13
- export class DriverExistException extends Exception {
14
- /**
15
- * Creates a new instance of DriverExistException.
16
- *
17
- * @param {string} driverName
18
- * @return {DriverExistException}
19
- */
20
- constructor(driverName) {
21
- const content = `The driver ${driverName} already exists in DriverFactory.`
22
- const availableDrivers = DriverFactory.availableDrivers().join(', ')
23
-
24
- super(
25
- content,
26
- 500,
27
- 'E_EXIST_DRIVER',
28
- `Available drivers are: ${availableDrivers}. The name ${driverName} is already in use inside DriverFactory. Try using a different name for your driver implementation.`,
29
- )
30
- }
31
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Exception } from '@athenna/common'
11
- import { FormatterFactory } from '#src/Factories/FormatterFactory'
12
-
13
- export class FormatterExistException extends Exception {
14
- /**
15
- * Creates a new instance of FormatterExistException.
16
- *
17
- * @param {string} formatterName
18
- * @return {FormatterExistException}
19
- */
20
- constructor(formatterName) {
21
- const content = `The formatter ${formatterName} already exists in FormatterFactory.`
22
- const availableFormatters =
23
- FormatterFactory.availableFormatters().join(', ')
24
-
25
- super(
26
- content,
27
- 500,
28
- 'E_EXIST_FORMATTER',
29
- `Available formatters are: ${availableFormatters}. The name ${formatterName} is already in use inside FormatterFactory. Try using a different name for your formatter implementation.`,
30
- )
31
- }
32
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Exception, Path } from '@athenna/common'
11
- import { DriverFactory } from '#src/Factories/DriverFactory'
12
-
13
- export class NotFoundDriverException extends Exception {
14
- /**
15
- * Creates a new instance of NotFoundDriverException.
16
- *
17
- * @param {string} driverName
18
- * @return {NotFoundDriverException}
19
- */
20
- constructor(driverName) {
21
- const content = `The driver ${driverName} has not been found.`
22
- const availableDrivers = DriverFactory.availableDrivers().join(', ')
23
-
24
- super(
25
- content,
26
- 500,
27
- 'E_NOT_FOUND',
28
- `Available drivers are: ${availableDrivers}. Look into your config/logger.${Path.ext()} file if ${driverName} driver is implemented by logger. Or create ${driverName} driver implementation using DriverFactory.createDriver("${driverName}", ...) method.`,
29
- )
30
- }
31
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Exception } from '@athenna/common'
11
- import { FormatterFactory } from '#src/Factories/FormatterFactory'
12
-
13
- export class NotFoundFormatterException extends Exception {
14
- /**
15
- * Creates a new instance of NotFoundFormatterException.
16
- *
17
- * @param {string} formatterName
18
- * @return {NotFoundFormatterException}
19
- */
20
- constructor(formatterName) {
21
- const content = `The formatter ${formatterName} has not been found.`
22
- const availableDrivers = FormatterFactory.availableFormatters().join(', ')
23
-
24
- super(
25
- content,
26
- 500,
27
- 'E_NOT_FOUND',
28
- `Available formatters are: ${availableDrivers}. Look into your config/logger.js file if ${formatterName} formatter is implemented by logger. Or create ${formatterName} formatter implementation using FormatterFactory.createFormatter("${formatterName}", ...) method.`,
29
- )
30
- }
31
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Path, Exception } from '@athenna/common'
11
-
12
- export class NotImplementedConfigException extends Exception {
13
- /**
14
- * Creates a new instance of NotImplementedConfigException.
15
- *
16
- * @param {string} channelName
17
- * @param {any[]} channels
18
- * @return {NotImplementedConfigException}
19
- */
20
- constructor(channelName, channels) {
21
- const content = `Channel ${channelName} is not configured inside logging.channels object from config/logging.${Path.ext()} file.`
22
-
23
- let help = ''
24
-
25
- if (channels && channels.length) {
26
- const availableConfigs = Object.keys(channels).join(', ')
27
-
28
- help += `Available configurations are: ${availableConfigs}.`
29
- } else {
30
- help += `The "Config.get('logging.channels')" is empty, maybe your configuration files are not loaded?`
31
- }
32
-
33
- help += ` Create your configuration inside channels object to use it. Or load your configuration files using "Config.safeLoad(Path.config('logging.${Path.ext()}'))`
34
-
35
- super(content, 500, 'E_NOT_IMPLEMENTED_CONFIG_ERROR', help)
36
- }
37
- }
@@ -1,128 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Config } from '@athenna/config'
11
-
12
- import { FactoryHelper } from '#src/index'
13
- import { FileDriver } from '#src/Drivers/FileDriver'
14
- import { NullDriver } from '#src/Drivers/NullDriver'
15
- import { SlackDriver } from '#src/Drivers/SlackDriver'
16
- import { StackDriver } from '#src/Drivers/StackDriver'
17
- import { ConsoleDriver } from '#src/Drivers/ConsoleDriver'
18
- import { DiscordDriver } from '#src/Drivers/DiscordDriver'
19
- import { TelegramDriver } from '#src/Drivers/TelegramDriver'
20
- import { DriverExistException } from '#src/Exceptions/DriverExistException'
21
- import { NotFoundDriverException } from '#src/Exceptions/NotFoundDriverException'
22
- import { NotImplementedConfigException } from '#src/Exceptions/NotImplementedConfigException'
23
- import { Options } from '@athenna/common'
24
-
25
- export class DriverFactory {
26
- /**
27
- * Drivers of DriverFactory.
28
- *
29
- * @type {Map<string, { Driver: any }>}
30
- */
31
- static #drivers = new Map()
32
- .set('file', { Driver: FileDriver })
33
- .set('null', { Driver: NullDriver })
34
- .set('slack', { Driver: SlackDriver })
35
- .set('stack', { Driver: StackDriver })
36
- .set('console', { Driver: ConsoleDriver })
37
- .set('discord', { Driver: DiscordDriver })
38
- .set('telegram', { Driver: TelegramDriver })
39
-
40
- /**
41
- * Return an array with all available drivers.
42
- *
43
- * @return {any[]}
44
- */
45
- static availableDrivers() {
46
- const availableDrivers = []
47
-
48
- for (const key of this.#drivers.keys()) {
49
- availableDrivers.push(key)
50
- }
51
-
52
- return availableDrivers
53
- }
54
-
55
- /**
56
- * Fabricate a new instance of a driver based on
57
- * channel configurations.
58
- *
59
- * @param {string} channelName
60
- * @param {any} runtimeConfig
61
- * @return {any}
62
- */
63
- static fabricate(channelName, runtimeConfig = {}) {
64
- const channelConfig = this.#getChannelConfig(channelName)
65
-
66
- const { Driver } = this.#drivers.get(channelConfig.driver)
67
-
68
- const configs = FactoryHelper.groupConfigs(runtimeConfig, channelConfig)
69
-
70
- return new Driver(configs)
71
- }
72
-
73
- /**
74
- * Fabricate a new instance of a driver with vanilla
75
- * configurations.
76
- *
77
- * @param {any} configs
78
- * @return {any}
79
- */
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)
87
-
88
- return new Driver(configs)
89
- }
90
-
91
- /**
92
- * Creates a new driver implementation.
93
- *
94
- * @param {string} name
95
- * @param {(channel: string, configs?: any) => any} driver
96
- */
97
- static createDriver(name, driver) {
98
- if (this.#drivers.has(name)) {
99
- throw new DriverExistException(name)
100
- }
101
-
102
- this.#drivers.set(name, { Driver: driver })
103
- }
104
-
105
- /**
106
- * Get all the configuration of a channel.
107
- *
108
- * @param {string} channelName
109
- * @return {any}
110
- */
111
- static #getChannelConfig(channelName) {
112
- if (channelName === 'default') {
113
- channelName = Config.get('logging.default') || channelName
114
- }
115
-
116
- const channelConfig = Config.get(`logging.channels.${channelName}`)
117
-
118
- if (!channelConfig) {
119
- throw new NotImplementedConfigException(channelName)
120
- }
121
-
122
- if (!this.#drivers.has(channelConfig.driver)) {
123
- throw new NotFoundDriverException(channelConfig.driver)
124
- }
125
-
126
- return channelConfig
127
- }
128
- }