@athenna/logger 1.0.0

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 (47) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +34 -0
  3. package/index.d.ts +12 -0
  4. package/index.js +24 -0
  5. package/package.json +159 -0
  6. package/src/Contracts/DriverContract.d.ts +11 -0
  7. package/src/Contracts/DriverContract.js +10 -0
  8. package/src/Contracts/FormatterContract.d.ts +11 -0
  9. package/src/Contracts/FormatterContract.js +10 -0
  10. package/src/Drivers/ConsoleDriver.d.ts +24 -0
  11. package/src/Drivers/ConsoleDriver.js +32 -0
  12. package/src/Drivers/DebugDriver.d.ts +25 -0
  13. package/src/Drivers/DebugDriver.js +33 -0
  14. package/src/Drivers/FileDriver.d.ts +23 -0
  15. package/src/Drivers/FileDriver.js +41 -0
  16. package/src/Exceptions/ChannelNotConfiguredException.d.ts +12 -0
  17. package/src/Exceptions/ChannelNotConfiguredException.js +19 -0
  18. package/src/Exceptions/DriverAlreadyExistException.d.ts +12 -0
  19. package/src/Exceptions/DriverAlreadyExistException.js +19 -0
  20. package/src/Exceptions/FormatterAlreadyExistException.d.ts +12 -0
  21. package/src/Exceptions/FormatterAlreadyExistException.js +19 -0
  22. package/src/Exceptions/NotFoundDriverException.d.ts +12 -0
  23. package/src/Exceptions/NotFoundDriverException.js +19 -0
  24. package/src/Exceptions/NotFoundFormatterException.d.ts +12 -0
  25. package/src/Exceptions/NotFoundFormatterException.js +19 -0
  26. package/src/Factories/DriverFactory.d.ts +19 -0
  27. package/src/Factories/DriverFactory.js +59 -0
  28. package/src/Factories/FormatterFactory.d.ts +18 -0
  29. package/src/Factories/FormatterFactory.js +45 -0
  30. package/src/Formatters/ContextFormatter.d.ts +19 -0
  31. package/src/Formatters/ContextFormatter.js +32 -0
  32. package/src/Formatters/DebugFormatter.d.ts +20 -0
  33. package/src/Formatters/DebugFormatter.js +32 -0
  34. package/src/Formatters/JsonFormatter.d.ts +16 -0
  35. package/src/Formatters/JsonFormatter.js +20 -0
  36. package/src/Formatters/LogFormatter.d.ts +18 -0
  37. package/src/Formatters/LogFormatter.js +33 -0
  38. package/src/Log.d.ts +18 -0
  39. package/src/Log.js +79 -0
  40. package/src/Logger.d.ts +19 -0
  41. package/src/Logger.js +73 -0
  42. package/src/Utils/Color.d.ts +37 -0
  43. package/src/Utils/Color.js +84 -0
  44. package/src/Utils/getTimestamp.d.ts +9 -0
  45. package/src/Utils/getTimestamp.js +23 -0
  46. package/src/Utils/global.d.ts +15 -0
  47. package/src/Utils/global.js +15 -0
@@ -0,0 +1,19 @@
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
+ import { DriverContract } from '../Contracts/DriverContract';
10
+ export interface DriverObject {
11
+ Driver: any;
12
+ }
13
+ export declare class DriverFactory {
14
+ private static drivers;
15
+ static availableDrivers(): string[];
16
+ static fabricate(channelName: string, runtimeConfig?: any): DriverContract;
17
+ static createDriver(name: string, driver: new (channel: string, configs?: any) => DriverContract): void;
18
+ private static getChannelConfig;
19
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * @athenna/logger
4
+ *
5
+ * (c) João Lenon <lenon@athenna.io>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
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;
26
+ }
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);
37
+ }
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 });
43
+ }
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;
53
+ }
54
+ }
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 });
@@ -0,0 +1,18 @@
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
+ import { FormatterContract } from '../Contracts/FormatterContract';
10
+ export interface FormatterObject {
11
+ Formatter: any;
12
+ }
13
+ export declare class FormatterFactory {
14
+ private static formatters;
15
+ static availableFormatters(): string[];
16
+ static fabricate(formatterName: string): FormatterContract;
17
+ static createFormatter(name: string, driver: new () => FormatterContract): void;
18
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /**
3
+ * @athenna/logger
4
+ *
5
+ * (c) João Lenon <lenon@athenna.io>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.FormatterFactory = void 0;
12
+ const LogFormatter_1 = require("../Formatters/LogFormatter");
13
+ const JsonFormatter_1 = require("../Formatters/JsonFormatter");
14
+ const DebugFormatter_1 = require("../Formatters/DebugFormatter");
15
+ const ContextFormatter_1 = require("../Formatters/ContextFormatter");
16
+ const NotFoundFormatterException_1 = require("../Exceptions/NotFoundFormatterException");
17
+ const FormatterAlreadyExistException_1 = require("../Exceptions/FormatterAlreadyExistException");
18
+ class FormatterFactory {
19
+ static availableFormatters() {
20
+ const availableFormatters = [];
21
+ for (const [key] of this.formatters.entries()) {
22
+ availableFormatters.push(key);
23
+ }
24
+ return availableFormatters;
25
+ }
26
+ static fabricate(formatterName) {
27
+ const formatterObject = this.formatters.get(formatterName);
28
+ if (!formatterObject) {
29
+ throw new NotFoundFormatterException_1.NotFoundFormatterException(formatterName);
30
+ }
31
+ return new formatterObject.Formatter();
32
+ }
33
+ static createFormatter(name, driver) {
34
+ if (this.formatters.has(name)) {
35
+ throw new FormatterAlreadyExistException_1.FormatterAlreadyExistException(name);
36
+ }
37
+ this.formatters.set(name, { Formatter: driver });
38
+ }
39
+ }
40
+ exports.FormatterFactory = FormatterFactory;
41
+ FormatterFactory.formatters = new Map()
42
+ .set('context', { Formatter: ContextFormatter_1.ContextFormatter })
43
+ .set('debug', { Formatter: DebugFormatter_1.DebugFormatter })
44
+ .set('json', { Formatter: JsonFormatter_1.JsonFormatter })
45
+ .set('log', { Formatter: LogFormatter_1.LogFormatter });
@@ -0,0 +1,19 @@
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
+ import { Chalk } from 'chalk';
10
+ import { FormatterContract } from '../Contracts/FormatterContract';
11
+ export interface ContextFormatterOptions {
12
+ color: Chalk;
13
+ context: string;
14
+ }
15
+ export declare class ContextFormatter implements FormatterContract {
16
+ format(message: string, options?: ContextFormatterOptions): string;
17
+ private static lastTimestamp?;
18
+ private static getTimestampDiff;
19
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * @athenna/logger
4
+ *
5
+ * (c) João Lenon <lenon@athenna.io>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.ContextFormatter = void 0;
12
+ const Color_1 = require("../Utils/Color");
13
+ const getTimestamp_1 = require("../Utils/getTimestamp");
14
+ class ContextFormatter {
15
+ format(message, options) {
16
+ options = Object.assign({}, { color: Color_1.Color.green, context: 'Logger' }, options);
17
+ const pid = Color_1.Color.darkPurple(`[Athenna] - PID: ${process.pid}`);
18
+ const timestamp = getTimestamp_1.getTimestamp();
19
+ const messageCtx = Color_1.Color.yellow(`[${options.context}] `);
20
+ const timestampDiff = ContextFormatter.getTimestampDiff();
21
+ return `${pid} - ${timestamp} ${messageCtx}${options.color(message)}${timestampDiff}`;
22
+ }
23
+ static getTimestampDiff() {
24
+ let result = '';
25
+ if (this.lastTimestamp) {
26
+ result = Color_1.Color.yellow(` +${Date.now() - this.lastTimestamp}ms`);
27
+ }
28
+ this.lastTimestamp = Date.now();
29
+ return result;
30
+ }
31
+ }
32
+ exports.ContextFormatter = ContextFormatter;
@@ -0,0 +1,20 @@
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
+ import { Chalk } from 'chalk';
10
+ import { FormatterContract } from '../Contracts/FormatterContract';
11
+ export interface DebugFormatterOptions {
12
+ color: Chalk;
13
+ context: string;
14
+ namespace: string;
15
+ }
16
+ export declare class DebugFormatter implements FormatterContract {
17
+ format(message: string, options?: DebugFormatterOptions): string;
18
+ private static lastTimestamp?;
19
+ private static getTimestampDiff;
20
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * @athenna/logger
4
+ *
5
+ * (c) João Lenon <lenon@athenna.io>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.DebugFormatter = void 0;
12
+ const Color_1 = require("../Utils/Color");
13
+ const getTimestamp_1 = require("../Utils/getTimestamp");
14
+ class DebugFormatter {
15
+ format(message, options) {
16
+ options = Object.assign({}, { color: Color_1.Color.green, context: 'Debugger', namespace: 'api:main' }, options);
17
+ const pid = Color_1.Color.purple(`[Athenna Debugger] - PID: ${process.pid}`);
18
+ const timestamp = Color_1.Color.white(getTimestamp_1.getTimestamp());
19
+ const messageCtx = Color_1.Color.yellow(`[${options.context}] `);
20
+ const timestampDiff = DebugFormatter.getTimestampDiff();
21
+ return `${pid} - ${timestamp} ${messageCtx}${options.color(message)}${timestampDiff}`;
22
+ }
23
+ static getTimestampDiff() {
24
+ let result = '';
25
+ if (this.lastTimestamp) {
26
+ result = Color_1.Color.yellow(` +${Date.now() - this.lastTimestamp}ms`);
27
+ }
28
+ this.lastTimestamp = Date.now();
29
+ return result;
30
+ }
31
+ }
32
+ exports.DebugFormatter = DebugFormatter;
@@ -0,0 +1,16 @@
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
+ import { Chalk } from 'chalk';
10
+ import { FormatterContract } from '../Contracts/FormatterContract';
11
+ export interface JsonFormatterOptions {
12
+ color: Chalk;
13
+ }
14
+ export declare class JsonFormatter implements FormatterContract {
15
+ format(message: Record<any, unknown>, options?: JsonFormatterOptions): string;
16
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * @athenna/logger
4
+ *
5
+ * (c) João Lenon <lenon@athenna.io>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.JsonFormatter = void 0;
12
+ const Color_1 = require("../Utils/Color");
13
+ class JsonFormatter {
14
+ format(message, options) {
15
+ options = Object.assign({}, { color: Color_1.Color.green }, options);
16
+ const pid = Color_1.Color.yellow(`[Athenna] - PID: ${process.pid}`);
17
+ return `${pid} - ${Color_1.Color.bold('JSON:')} ${options.color(JSON.stringify(message))}`;
18
+ }
19
+ }
20
+ exports.JsonFormatter = JsonFormatter;
@@ -0,0 +1,18 @@
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
+ import { Chalk } from 'chalk';
10
+ import { FormatterContract } from '../Contracts/FormatterContract';
11
+ export interface LogFormatterOptions {
12
+ color: Chalk;
13
+ level: 'INFO' | 'DEBUG' | 'WARN' | 'ERROR' | 'SUCCESS';
14
+ }
15
+ export declare class LogFormatter implements FormatterContract {
16
+ format(message: string, options?: LogFormatterOptions): string;
17
+ private static paintByLevel;
18
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /**
3
+ * @athenna/logger
4
+ *
5
+ * (c) João Lenon <lenon@athenna.io>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.LogFormatter = void 0;
12
+ const Color_1 = require("../Utils/Color");
13
+ const getTimestamp_1 = require("../Utils/getTimestamp");
14
+ class LogFormatter {
15
+ format(message, options) {
16
+ options = Object.assign({}, { color: Color_1.Color.green, level: 'info' }, options);
17
+ const pid = Color_1.Color.yellow(`[Athenna] - PID: ${process.pid}`);
18
+ const timestamp = getTimestamp_1.getTimestamp();
19
+ const level = LogFormatter.paintByLevel(options.level);
20
+ return `${pid} - ${timestamp} ${level} ${options.color(message)}`;
21
+ }
22
+ static paintByLevel(level) {
23
+ const levelColors = {
24
+ info: Color_1.Color.info,
25
+ debug: Color_1.Color.debug,
26
+ warn: Color_1.Color.warning,
27
+ error: Color_1.Color.error,
28
+ success: Color_1.Color.log,
29
+ };
30
+ return levelColors[level.toLowerCase()](`[${level}]`);
31
+ }
32
+ }
33
+ exports.LogFormatter = LogFormatter;
package/src/Log.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { DriverContract } from './Contracts/DriverContract';
2
+ import { FormatterContract } from './Contracts/FormatterContract';
3
+ export declare class Log {
4
+ private static _options?;
5
+ private static logger;
6
+ static options(options?: any): void;
7
+ static buildDriver(name: string, driver: new (channel: string, configs?: any) => DriverContract): typeof Log;
8
+ static buildFormatter(name: string, formatter: new () => FormatterContract): typeof Log;
9
+ static get drivers(): string[];
10
+ static get formatters(): string[];
11
+ static channel(channel: string): typeof Log;
12
+ static log(message: any, options?: any): void;
13
+ static info(message: any, options?: any): void;
14
+ static warn(message: any, options?: any): void;
15
+ static error(message: any, options?: any): void;
16
+ static debug(message: any, options?: any): void;
17
+ static success(message: any, options?: any): void;
18
+ }
package/src/Log.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Log = void 0;
4
+ const Logger_1 = require("./Logger");
5
+ class Log {
6
+ static options(options) {
7
+ this._options = options;
8
+ }
9
+ static buildDriver(name, driver) {
10
+ Logger_1.Logger.buildDriver(name, driver);
11
+ return this;
12
+ }
13
+ static buildFormatter(name, formatter) {
14
+ Logger_1.Logger.buildFormatter(name, formatter);
15
+ return this;
16
+ }
17
+ static get drivers() {
18
+ return Logger_1.Logger.drivers;
19
+ }
20
+ static get formatters() {
21
+ return Logger_1.Logger.formatters;
22
+ }
23
+ static channel(channel) {
24
+ if (!this.logger)
25
+ this.logger = new Logger_1.Logger();
26
+ this.logger.channel(channel);
27
+ return this;
28
+ }
29
+ static log(message, options) {
30
+ options = {
31
+ ...options,
32
+ ...this._options,
33
+ };
34
+ this.logger.log(message, options);
35
+ this.logger = new Logger_1.Logger();
36
+ }
37
+ static info(message, options) {
38
+ options = {
39
+ ...options,
40
+ ...this._options,
41
+ };
42
+ this.logger.info(message, options);
43
+ this.logger = new Logger_1.Logger();
44
+ }
45
+ static warn(message, options) {
46
+ options = {
47
+ ...options,
48
+ ...this._options,
49
+ };
50
+ this.logger.warn(message, options);
51
+ this.logger = new Logger_1.Logger();
52
+ }
53
+ static error(message, options) {
54
+ options = {
55
+ ...options,
56
+ ...this._options,
57
+ };
58
+ this.logger.error(message, options);
59
+ this.logger = new Logger_1.Logger();
60
+ }
61
+ static debug(message, options) {
62
+ options = {
63
+ ...options,
64
+ ...this._options,
65
+ };
66
+ this.logger.debug(message, options);
67
+ this.logger = new Logger_1.Logger();
68
+ }
69
+ static success(message, options) {
70
+ options = {
71
+ ...options,
72
+ ...this._options,
73
+ };
74
+ this.logger.success(message, options);
75
+ this.logger = new Logger_1.Logger();
76
+ }
77
+ }
78
+ exports.Log = Log;
79
+ Log._options = {};
@@ -0,0 +1,19 @@
1
+ import { DriverContract } from './Contracts/DriverContract';
2
+ import { FormatterContract } from './Contracts/FormatterContract';
3
+ export declare class Logger {
4
+ private runtimeConfig;
5
+ private channelName;
6
+ private driver;
7
+ static buildDriver(name: string, driver: new (channel: string, configs?: any) => DriverContract): void;
8
+ static buildFormatter(name: string, formatter: new () => FormatterContract): void;
9
+ static get drivers(): string[];
10
+ static get formatters(): string[];
11
+ constructor(runtimeConfig?: any);
12
+ channel(channel: string, runtimeConfig?: any): Logger;
13
+ log(message: any, options?: any): Promise<void>;
14
+ info(message: any, options?: any): Promise<void>;
15
+ warn(message: any, options?: any): Promise<void>;
16
+ error(message: any, options?: any): Promise<void>;
17
+ debug(message: any, options?: any): Promise<void>;
18
+ success(message: any, options?: any): Promise<void>;
19
+ }
package/src/Logger.js ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ const Color_1 = require("./Utils/Color");
5
+ const utils_1 = require("@secjs/utils");
6
+ const DriverFactory_1 = require("./Factories/DriverFactory");
7
+ const FormatterFactory_1 = require("./Factories/FormatterFactory");
8
+ class Logger {
9
+ constructor(runtimeConfig = {}) {
10
+ new utils_1.Config().safeLoad(utils_1.Path.config('logging'));
11
+ this.runtimeConfig = runtimeConfig;
12
+ this.channelName = 'default';
13
+ this.driver = DriverFactory_1.DriverFactory.fabricate(this.channelName, this.runtimeConfig);
14
+ }
15
+ static buildDriver(name, driver) {
16
+ DriverFactory_1.DriverFactory.createDriver(name, driver);
17
+ }
18
+ static buildFormatter(name, formatter) {
19
+ FormatterFactory_1.FormatterFactory.createFormatter(name, formatter);
20
+ }
21
+ static get drivers() {
22
+ return DriverFactory_1.DriverFactory.availableDrivers();
23
+ }
24
+ static get formatters() {
25
+ return FormatterFactory_1.FormatterFactory.availableFormatters();
26
+ }
27
+ channel(channel, runtimeConfig) {
28
+ if (runtimeConfig)
29
+ this.runtimeConfig = runtimeConfig;
30
+ this.driver = DriverFactory_1.DriverFactory.fabricate(channel, this.runtimeConfig);
31
+ return this;
32
+ }
33
+ async log(message, options) {
34
+ options = Object.assign({}, { context: 'Logger' }, options);
35
+ await this.driver.transport(message, options);
36
+ }
37
+ async info(message, options) {
38
+ options = Object.assign({}, { context: 'Logger' }, options);
39
+ options.level = 'INFO';
40
+ options.color = Color_1.Color.cyan;
41
+ options.streamType = 'stdout';
42
+ await this.driver.transport(message, options);
43
+ }
44
+ async warn(message, options) {
45
+ options = Object.assign({}, { context: 'Logger' }, options);
46
+ options.level = 'WARN';
47
+ options.color = Color_1.Color.orange;
48
+ options.streamType = 'stdout';
49
+ await this.driver.transport(message, options);
50
+ }
51
+ async error(message, options) {
52
+ options = Object.assign({}, { context: 'Logger' }, options);
53
+ options.level = 'ERROR';
54
+ options.color = Color_1.Color.red;
55
+ options.streamType = 'stderr';
56
+ await this.driver.transport(message, options);
57
+ }
58
+ async debug(message, options) {
59
+ options = Object.assign({}, { context: 'Logger' }, options);
60
+ options.level = 'DEBUG';
61
+ options.color = Color_1.Color.purple;
62
+ options.streamType = 'stdout';
63
+ await this.driver.transport(message, options);
64
+ }
65
+ async success(message, options) {
66
+ options = Object.assign({}, { context: 'Logger' }, options);
67
+ options.level = 'SUCCESS';
68
+ options.color = Color_1.Color.green;
69
+ options.streamType = 'stdout';
70
+ await this.driver.transport(message, options);
71
+ }
72
+ }
73
+ exports.Logger = Logger;
@@ -0,0 +1,37 @@
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
+ import { Chalk } from 'chalk';
10
+ declare type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE';
11
+ export declare class Color {
12
+ static chalk: Chalk & {
13
+ supportsColor: import("chalk").ColorSupport;
14
+ };
15
+ static get bold(): Chalk;
16
+ static get purple(): Chalk;
17
+ static get darkPurple(): Chalk;
18
+ static get yellow(): Chalk;
19
+ static get cyan(): Chalk;
20
+ static get white(): Chalk;
21
+ static get orange(): Chalk;
22
+ static get green(): Chalk;
23
+ static get darkGreen(): Chalk;
24
+ static get red(): Chalk;
25
+ static removeColors(string: string): any;
26
+ static get info(): any;
27
+ static get log(): any;
28
+ static get debug(): any;
29
+ static get error(): any;
30
+ static get warning(): any;
31
+ static httpMethod(method: Methods): any;
32
+ static get GET(): any;
33
+ static get PUT(): any;
34
+ static get POST(): any;
35
+ static get DELETE(): any;
36
+ }
37
+ export {};
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * @athenna/logger
4
+ *
5
+ * (c) João Lenon <lenon@athenna.io>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.Color = void 0;
15
+ const chalk_1 = __importDefault(require("chalk"));
16
+ class Color {
17
+ static get bold() {
18
+ return Color.chalk.bold;
19
+ }
20
+ static get purple() {
21
+ return Color.chalk.hex('#7628c8');
22
+ }
23
+ static get darkPurple() {
24
+ return Color.chalk.hex('#501b86');
25
+ }
26
+ static get yellow() {
27
+ return Color.chalk.hex('#ffe600');
28
+ }
29
+ static get cyan() {
30
+ return Color.chalk.hex('#00ffff');
31
+ }
32
+ static get white() {
33
+ return Color.chalk.hex('#ffffff');
34
+ }
35
+ static get orange() {
36
+ return Color.chalk.hex('#f18b0e');
37
+ }
38
+ static get green() {
39
+ return Color.chalk.hex('#0ef12c');
40
+ }
41
+ static get darkGreen() {
42
+ return Color.chalk.hex('#1cb70b');
43
+ }
44
+ static get red() {
45
+ return Color.chalk.hex('#f10e0e');
46
+ }
47
+ static removeColors(string) {
48
+ return Color.chalk.reset(string).replace(
49
+ // eslint-disable-next-line no-control-regex
50
+ /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
51
+ }
52
+ static get info() {
53
+ return this.cyan.bold;
54
+ }
55
+ static get log() {
56
+ return this.green.bold;
57
+ }
58
+ static get debug() {
59
+ return this.purple.bold;
60
+ }
61
+ static get error() {
62
+ return this.red.bold;
63
+ }
64
+ static get warning() {
65
+ return this.orange.bold;
66
+ }
67
+ static httpMethod(method) {
68
+ return this[method];
69
+ }
70
+ static get GET() {
71
+ return this.purple.bold('GET 🔍');
72
+ }
73
+ static get PUT() {
74
+ return this.yellow.bold('PUT 🛠');
75
+ }
76
+ static get POST() {
77
+ return this.green.bold('POST 🧱');
78
+ }
79
+ static get DELETE() {
80
+ return this.red.bold('DELETE ❌');
81
+ }
82
+ }
83
+ exports.Color = Color;
84
+ Color.chalk = chalk_1.default;
@@ -0,0 +1,9 @@
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
+ export declare function getTimestamp(): string;