@athenna/logger 1.1.6 → 1.1.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.
Files changed (68) hide show
  1. package/LICENSE.md +3 -15
  2. package/README.md +6 -6
  3. package/package.json +84 -101
  4. package/src/Drivers/ConsoleDriver.js +43 -22
  5. package/src/Drivers/DebugDriver.js +45 -23
  6. package/src/Drivers/DiscordDriver.js +57 -0
  7. package/src/Drivers/FileDriver.js +51 -34
  8. package/src/Drivers/NullDriver.js +28 -0
  9. package/src/Drivers/PinoDriver.js +94 -0
  10. package/src/Drivers/SlackDriver.js +54 -0
  11. package/src/Drivers/TelegramDriver.js +53 -0
  12. package/src/Exceptions/DriverExistException.js +31 -0
  13. package/src/Exceptions/FormatterExistException.js +32 -0
  14. package/src/Exceptions/NotFoundChannelException.js +32 -0
  15. package/src/Exceptions/NotFoundDriverException.js +22 -10
  16. package/src/Exceptions/NotFoundFormatterException.js +22 -10
  17. package/src/Exceptions/OnlyPinoPrettyException.js +28 -0
  18. package/src/Facades/Log.js +9 -5
  19. package/src/Factories/DriverFactory.js +98 -46
  20. package/src/Factories/FormatterFactory.js +67 -35
  21. package/src/Formatters/CliFormatter.js +21 -20
  22. package/src/Formatters/JsonFormatter.js +15 -10
  23. package/src/Formatters/MessageFormatter.js +40 -0
  24. package/src/Formatters/NestFormatter.js +31 -22
  25. package/src/Formatters/NoneFormatter.js +21 -0
  26. package/src/Formatters/RequestFormatter.js +49 -37
  27. package/src/Formatters/SimpleFormatter.js +30 -31
  28. package/src/Helpers/ColorHelper.js +259 -0
  29. package/src/Helpers/FactoryHelper.js +121 -0
  30. package/src/Providers/LoggerProvider.js +13 -15
  31. package/src/index.d.ts +383 -0
  32. package/src/index.js +269 -0
  33. package/index.d.ts +0 -13
  34. package/index.js +0 -25
  35. package/src/Contracts/DriverContract.d.ts +0 -11
  36. package/src/Contracts/DriverContract.js +0 -10
  37. package/src/Contracts/FormatterContract.d.ts +0 -11
  38. package/src/Contracts/FormatterContract.js +0 -10
  39. package/src/Contracts/LevelTypes.d.ts +0 -1
  40. package/src/Contracts/LevelTypes.js +0 -2
  41. package/src/Drivers/ConsoleDriver.d.ts +0 -25
  42. package/src/Drivers/DebugDriver.d.ts +0 -25
  43. package/src/Drivers/FileDriver.d.ts +0 -23
  44. package/src/Exceptions/ChannelNotConfiguredException.d.ts +0 -12
  45. package/src/Exceptions/ChannelNotConfiguredException.js +0 -19
  46. package/src/Exceptions/DriverAlreadyExistException.d.ts +0 -12
  47. package/src/Exceptions/DriverAlreadyExistException.js +0 -19
  48. package/src/Exceptions/FormatterAlreadyExistException.d.ts +0 -12
  49. package/src/Exceptions/FormatterAlreadyExistException.js +0 -19
  50. package/src/Exceptions/NotFoundDriverException.d.ts +0 -12
  51. package/src/Exceptions/NotFoundFormatterException.d.ts +0 -12
  52. package/src/Facades/Log.d.ts +0 -10
  53. package/src/Factories/DriverFactory.d.ts +0 -19
  54. package/src/Factories/FormatterFactory.d.ts +0 -18
  55. package/src/Formatters/CliFormatter.d.ts +0 -19
  56. package/src/Formatters/JsonFormatter.d.ts +0 -16
  57. package/src/Formatters/NestFormatter.d.ts +0 -19
  58. package/src/Formatters/RequestFormatter.d.ts +0 -17
  59. package/src/Formatters/SimpleFormatter.d.ts +0 -21
  60. package/src/Logger.d.ts +0 -21
  61. package/src/Logger.js +0 -140
  62. package/src/Providers/LoggerProvider.d.ts +0 -17
  63. package/src/Utils/Color.d.ts +0 -48
  64. package/src/Utils/Color.js +0 -93
  65. package/src/Utils/Handler.d.ts +0 -13
  66. package/src/Utils/Handler.js +0 -24
  67. package/src/Utils/getTimestamp.d.ts +0 -9
  68. package/src/Utils/getTimestamp.js +0 -23
@@ -0,0 +1,94 @@
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 pino from 'pino'
11
+
12
+ import { Config } from '@secjs/utils'
13
+
14
+ import { FactoryHelper } from '#src/index'
15
+ import { OnlyPinoPrettyException } from '#src/Exceptions/OnlyPinoPrettyException'
16
+
17
+ export class PinoDriver {
18
+ /**
19
+ * Holds the configuration set of PinoDriver.
20
+ *
21
+ * @type {import('pino').LoggerOptions & { formatter?: 'pino-pretty', formatterConfig?: import('pino-pretty').PrettyOptions }}
22
+ */
23
+ configs
24
+
25
+ /**
26
+ * Creates a new instance of PinoDriver.
27
+ *
28
+ * @param {string} channel
29
+ * @param {any} [configs]
30
+ * @return {PinoDriver}
31
+ */
32
+ constructor(channel, configs = {}) {
33
+ const channelConfig = Config.get(`logging.channels.${channel}`)
34
+
35
+ this.configs = FactoryHelper.groupConfigs(configs, channelConfig)
36
+ }
37
+
38
+ /**
39
+ * Transport the log.
40
+ *
41
+ * @param {string} message
42
+ * @param {import('pino').LoggerOptions & { formatter?: 'pino-pretty', formatterConfig?: import('pino-pretty').PrettyOptions }} [options]
43
+ * @return {void}
44
+ */
45
+ transport(message, options = {}) {
46
+ const configs = FactoryHelper.groupConfigs(options, this.configs)
47
+
48
+ configs.customLevels = {
49
+ info: 1,
50
+ warn: 2,
51
+ error: 3,
52
+ debug: 4,
53
+ success: 5,
54
+ critical: 6,
55
+ }
56
+ configs.useOnlyCustomLevels = true
57
+
58
+ const pinoMethod = configs.formatterConfig.level.toLowerCase()
59
+
60
+ delete configs.formatterConfig.level
61
+ delete configs.formatterConfig.chalk
62
+
63
+ if (configs.formatter !== 'pino-pretty') {
64
+ throw new OnlyPinoPrettyException()
65
+ }
66
+
67
+ const pinoConfigs = {}
68
+
69
+ Object.keys(configs).forEach(key => {
70
+ if (key === 'formatter') {
71
+ pinoConfigs.transport = {
72
+ target: 'pino-pretty',
73
+ options: configs.formatterConfig,
74
+ }
75
+ configs.formatterConfig.customLevels =
76
+ 'info:1,warn:2,error:3,debug:4,success:5,critical:6'
77
+ configs.formatterConfig.customColors =
78
+ 'info:cyan,warn:yellow,error:red,debug:magenta,success:green,critical:red'
79
+
80
+ return
81
+ }
82
+
83
+ if (['driver', 'formatterConfig'].includes(key)) {
84
+ return
85
+ }
86
+
87
+ pinoConfigs[key] = configs[key]
88
+ })
89
+
90
+ const logger = pino(pinoConfigs)
91
+
92
+ logger[pinoMethod](message)
93
+ }
94
+ }
@@ -0,0 +1,54 @@
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 axios from 'axios'
11
+
12
+ import { Config } from '@secjs/utils'
13
+
14
+ import { ColorHelper, FactoryHelper, FormatterFactory } from '#src/index'
15
+
16
+ export class SlackDriver {
17
+ /**
18
+ * Holds the configuration set of SlackDriver.
19
+ *
20
+ * @type {{ url?: string, formatter?: 'pino-pretty', formatterConfig?: import('pino-pretty').PrettyOptions }}
21
+ */
22
+ configs
23
+
24
+ /**
25
+ * Creates a new instance of SlackDriver.
26
+ *
27
+ * @param {string} channel
28
+ * @param {any} [configs]
29
+ * @return {SlackDriver}
30
+ */
31
+ constructor(channel, configs = {}) {
32
+ const channelConfig = Config.get(`logging.channels.${channel}`)
33
+
34
+ this.configs = FactoryHelper.groupConfigs(configs, channelConfig)
35
+ }
36
+
37
+ /**
38
+ * Transport the log.
39
+ *
40
+ * @param {string} message
41
+ * @param {{ url?: string, formatter?: 'pino-pretty', formatterConfig?: import('pino-pretty').PrettyOptions }} [options]
42
+ * @return {Promise<void>}
43
+ */
44
+ async transport(message, options = {}) {
45
+ const configs = FactoryHelper.groupConfigs(options, this.configs)
46
+
47
+ message = FormatterFactory.fabricate(configs.formatter).format(
48
+ message,
49
+ configs.formatterConfig,
50
+ )
51
+
52
+ await axios.post(configs.url, { text: ColorHelper.removeColors(message) })
53
+ }
54
+ }
@@ -0,0 +1,53 @@
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
+
12
+ import { Config } from '@secjs/utils'
13
+
14
+ import { ColorHelper, FactoryHelper, FormatterFactory } from '#src/index'
15
+
16
+ export class TelegramDriver {
17
+ /**
18
+ * Holds the configuration set of SlackDriver.
19
+ *
20
+ * @type {{ token?: string, chatId?: string|number, parseMode?: 'HTML'|'Markdown'|'MarkdownV2', formatter?: 'pino-pretty', formatterConfig?: import('pino-pretty').PrettyOptions }}
21
+ */
22
+ configs
23
+
24
+ constructor(channel, configs = {}) {
25
+ const channelConfig = Config.get(`logging.channels.${channel}`)
26
+
27
+ this.configs = FactoryHelper.groupConfigs(configs, channelConfig)
28
+ }
29
+
30
+ /**
31
+ * Transport the log.
32
+ *
33
+ * @param {string} message
34
+ * @param {{ token?: string, chatId?: string|number, parseMode?: 'HTML'|'Markdown'|'MarkdownV2', formatter?: 'pino-pretty', formatterConfig?: import('pino-pretty').PrettyOptions }} [options]
35
+ * @return {Promise<void>}
36
+ */
37
+ async transport(message, options = {}) {
38
+ const configs = FactoryHelper.groupConfigs(options, this.configs)
39
+
40
+ message = FormatterFactory.fabricate(configs.formatter).format(
41
+ message,
42
+ configs.formatterConfig,
43
+ )
44
+
45
+ await new Telegraf(configs.token).telegram.sendMessage(
46
+ configs.chatId,
47
+ ColorHelper.removeColors(message),
48
+ {
49
+ parse_mode: configs.parseMode,
50
+ },
51
+ )
52
+ }
53
+ }
@@ -0,0 +1,31 @@
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 '@secjs/utils'
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
+ }
@@ -0,0 +1,32 @@
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 '@secjs/utils'
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
+ }
@@ -0,0 +1,32 @@
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, Exception } from '@secjs/utils'
11
+
12
+ export class NotFoundChannelException extends Exception {
13
+ /**
14
+ * Creates a new instance of NotFoundChannelException.
15
+ *
16
+ * @param {string} channelName
17
+ * @return {NotFoundChannelException}
18
+ */
19
+ constructor(channelName) {
20
+ const content = `Channel ${channelName} not found.`
21
+ const availableChannels = Object.keys(Config.get('logging.channels')).join(
22
+ ', ',
23
+ )
24
+
25
+ super(
26
+ content,
27
+ 500,
28
+ 'E_NOT_FOUND',
29
+ `Available channels are: ${availableChannels}. Look into your config/logger file if ${channelName} channel is inside "channels" property, if it does not exist create ${channelName} channel object inside "channels".`,
30
+ )
31
+ }
32
+ }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @athenna/logger
4
3
  *
@@ -7,13 +6,26 @@
7
6
  * For the full copyright and license information, please view the LICENSE
8
7
  * file that was distributed with this source code.
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.NotFoundDriverException = void 0;
12
- const utils_1 = require("@secjs/utils");
13
- class NotFoundDriverException extends utils_1.Exception {
14
- constructor(driverName) {
15
- const content = `The driver ${driverName} has not been found`;
16
- super(content, 500, 'NOT_FOUND_ERROR', `Look into your config/logger file if this driver is implemented by logger. Or create this driver implementation using Logger.buildDriver method`);
17
- }
9
+
10
+ import { Exception } from '@secjs/utils'
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 file if ${driverName} driver is implemented by logger. Or create ${driverName} driver implementation using DriverFactory.createDriver("${driverName}", ...) method.`,
29
+ )
30
+ }
18
31
  }
19
- exports.NotFoundDriverException = NotFoundDriverException;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @athenna/logger
4
3
  *
@@ -7,13 +6,26 @@
7
6
  * For the full copyright and license information, please view the LICENSE
8
7
  * file that was distributed with this source code.
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.NotFoundFormatterException = void 0;
12
- const utils_1 = require("@secjs/utils");
13
- class NotFoundFormatterException extends utils_1.Exception {
14
- constructor(formatterName) {
15
- const content = `The driver ${formatterName} has not been found`;
16
- super(content, 500, 'NOT_FOUND_ERROR', `Look into your config/logger file if this formatter is implemented by logger. Or create this formatter implementation using Logger.buildFormatter method`);
17
- }
9
+
10
+ import { Exception } from '@secjs/utils'
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 file if ${formatterName} formatter is implemented by logger. Or create ${formatterName} formatter implementation using FormatterFactory.createFormatter("${formatterName}", ...) method.`,
29
+ )
30
+ }
18
31
  }
19
- exports.NotFoundFormatterException = NotFoundFormatterException;
@@ -0,0 +1,28 @@
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 '@secjs/utils'
11
+
12
+ export class OnlyPinoPrettyException extends Exception {
13
+ /**
14
+ * Creates a new instance of OnlyPinoPrettyException.
15
+ *
16
+ * @return {OnlyPinoPrettyException}
17
+ */
18
+ constructor() {
19
+ const content = `The driver "pino" can only be used with "pino-pretty" formatter.`
20
+
21
+ super(
22
+ content,
23
+ 500,
24
+ 'E_PINO_PRETTY',
25
+ `Available formatters are: pino-pretty. Look into your config/logger file where your are using "pino" driver and change the formatter to pino-pretty.`,
26
+ )
27
+ }
28
+ }
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @athenna/logger
4
3
  *
@@ -7,7 +6,12 @@
7
6
  * For the full copyright and license information, please view the LICENSE
8
7
  * file that was distributed with this source code.
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Log = void 0;
12
- const Handler_1 = require("../Utils/Handler");
13
- exports.Log = new Proxy({}, new Handler_1.Handler('Athenna/Core/Logger'));
9
+
10
+ import { Facade } from '@athenna/ioc'
11
+
12
+ /**
13
+ * Log facade.
14
+ *
15
+ * @type {Facade & import('../index').Logger}
16
+ */
17
+ export const Log = Facade.createFor('Athenna/Core/Logger')
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * @athenna/logger
4
3
  *
@@ -7,53 +6,106 @@
7
6
  * For the full copyright and license information, please view the LICENSE
8
7
  * file that was distributed with this source code.
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.DriverFactory = void 0;
12
- const utils_1 = require("@secjs/utils");
13
- const FileDriver_1 = require("../Drivers/FileDriver");
14
- const DebugDriver_1 = require("../Drivers/DebugDriver");
15
- const ConsoleDriver_1 = require("../Drivers/ConsoleDriver");
16
- const NotFoundDriverException_1 = require("../Exceptions/NotFoundDriverException");
17
- const DriverAlreadyExistException_1 = require("../Exceptions/DriverAlreadyExistException");
18
- const ChannelNotConfiguredException_1 = require("../Exceptions/ChannelNotConfiguredException");
19
- class DriverFactory {
20
- static availableDrivers() {
21
- const availableDrivers = [];
22
- for (const [key] of this.drivers.entries()) {
23
- availableDrivers.push(key);
24
- }
25
- return availableDrivers;
9
+
10
+ import { Config } from '@secjs/utils'
11
+
12
+ import { FileDriver } from '#src/Drivers/FileDriver'
13
+ import { NullDriver } from '#src/Drivers/NullDriver'
14
+ import { PinoDriver } from '#src/Drivers/PinoDriver'
15
+ import { DebugDriver } from '#src/Drivers/DebugDriver'
16
+ import { SlackDriver } from '#src/Drivers/SlackDriver'
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 { NotFoundChannelException } from '#src/Exceptions/NotFoundChannelException'
23
+
24
+ export class DriverFactory {
25
+ /**
26
+ * Drivers of DriverFactory.
27
+ *
28
+ * @type {Map<string, { Driver: any }>}
29
+ */
30
+ static drivers = new Map()
31
+ .set('file', { Driver: FileDriver })
32
+ .set('null', { Driver: NullDriver })
33
+ .set('pino', { Driver: PinoDriver })
34
+ .set('slack', { Driver: SlackDriver })
35
+ .set('debug', { Driver: DebugDriver })
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.entries()) {
49
+ availableDrivers.push(key)
26
50
  }
27
- static fabricate(channelName, runtimeConfig = {}) {
28
- if (channelName === 'default') {
29
- channelName = utils_1.Config.get('logging.default');
30
- }
31
- const channelConfig = this.getChannelConfig(channelName);
32
- const driverObject = this.drivers.get(channelConfig.driver);
33
- if (!driverObject) {
34
- throw new NotFoundDriverException_1.NotFoundDriverException(channelConfig.driver);
35
- }
36
- return new driverObject.Driver(channelName, runtimeConfig);
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
+ if (channelName === 'default') {
65
+ channelName = Config.get('logging.default')
37
66
  }
38
- static createDriver(name, driver) {
39
- if (this.drivers.has(name)) {
40
- throw new DriverAlreadyExistException_1.DriverAlreadyExistException(name);
41
- }
42
- this.drivers.set(name, { Driver: driver });
67
+
68
+ const channelConfig = this.#getChannelConfig(channelName)
69
+ const driverObject = this.drivers.get(channelConfig.driver)
70
+
71
+ if (!driverObject) {
72
+ throw new NotFoundDriverException(channelConfig.driver)
43
73
  }
44
- static getChannelConfig(channelName) {
45
- const channelConfig = utils_1.Config.get(`logging.channels.${channelName}`);
46
- if (!channelConfig) {
47
- throw new ChannelNotConfiguredException_1.ChannelNotConfiguredException(channelName);
48
- }
49
- if (!this.drivers.has(channelConfig.driver)) {
50
- throw new NotFoundDriverException_1.NotFoundDriverException(channelConfig.driver);
51
- }
52
- return channelConfig;
74
+
75
+ return new driverObject.Driver(channelName, runtimeConfig)
76
+ }
77
+
78
+ /**
79
+ * Creates a new driver implementation.
80
+ *
81
+ * @param {string} name
82
+ * @param {(channel: string, configs?: any) => any} driver
83
+ */
84
+ static createDriver(name, driver) {
85
+ if (this.drivers.has(name)) {
86
+ throw new DriverExistException(name)
53
87
  }
88
+
89
+ this.drivers.set(name, { Driver: driver })
90
+ }
91
+
92
+ /**
93
+ * Get all the configuration of a channel.
94
+ *
95
+ * @param {string} channelName
96
+ * @return {any}
97
+ */
98
+ static #getChannelConfig(channelName) {
99
+ const channelConfig = Config.get(`logging.channels.${channelName}`)
100
+
101
+ if (!channelConfig) {
102
+ throw new NotFoundChannelException(channelName)
103
+ }
104
+
105
+ if (!this.drivers.has(channelConfig.driver)) {
106
+ throw new NotFoundDriverException(channelConfig.driver)
107
+ }
108
+
109
+ return channelConfig
110
+ }
54
111
  }
55
- exports.DriverFactory = DriverFactory;
56
- DriverFactory.drivers = new Map()
57
- .set('file', { Driver: FileDriver_1.FileDriver })
58
- .set('debug', { Driver: DebugDriver_1.DebugDriver })
59
- .set('console', { Driver: ConsoleDriver_1.ConsoleDriver });