@athenna/logger 1.1.7 → 1.1.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 +6 -1
- package/src/Contracts/DefaultDriverConfigs.d.ts +4 -0
- package/src/Contracts/DefaultDriverConfigs.js +2 -0
- package/src/Contracts/DriverContract.d.ts +2 -0
- package/src/Drivers/ConsoleDriver.d.ts +4 -10
- package/src/Drivers/ConsoleDriver.js +6 -11
- package/src/Drivers/DebugDriver.d.ts +4 -10
- package/src/Drivers/DebugDriver.js +6 -11
- package/src/Drivers/DiscordDriver.d.ts +20 -0
- package/src/Drivers/DiscordDriver.js +34 -0
- package/src/Drivers/FileDriver.d.ts +4 -8
- package/src/Drivers/FileDriver.js +6 -11
- package/src/Drivers/NullDriver.d.ts +13 -0
- package/src/Drivers/NullDriver.js +16 -0
- package/src/Drivers/PinoDriver.d.ts +20 -0
- package/src/Drivers/PinoDriver.js +72 -0
- package/src/Drivers/SlackDriver.d.ts +19 -0
- package/src/Drivers/SlackDriver.js +31 -0
- package/src/Drivers/TelegramDriver.d.ts +21 -0
- package/src/Drivers/TelegramDriver.js +30 -0
- package/src/Exceptions/NotFoundFormatterException.js +1 -1
- package/src/Exceptions/OnlyPinoPrettyException.d.ts +12 -0
- package/src/Exceptions/OnlyPinoPrettyException.js +19 -0
- package/src/Factories/DriverFactory.js +11 -1
- package/src/Factories/FormatterFactory.js +2 -0
- package/src/Formatters/CliFormatter.js +2 -0
- package/src/Formatters/MessageFormatter.d.ts +20 -0
- package/src/Formatters/MessageFormatter.js +43 -0
- package/src/Formatters/SimpleFormatter.d.ts +2 -2
- package/src/Formatters/SimpleFormatter.js +2 -0
- package/src/Logger.js +0 -7
- package/src/Utils/groupConfigs.d.ts +9 -0
- package/src/Utils/groupConfigs.js +18 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/logger",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -122,6 +122,7 @@
|
|
|
122
122
|
"dot-notation": "off",
|
|
123
123
|
"camelcase": "off",
|
|
124
124
|
"no-undef": "off",
|
|
125
|
+
"no-useless-escape": "off",
|
|
125
126
|
"@typescript-eslint/no-var-requires": "off",
|
|
126
127
|
"no-useless-constructor": "off",
|
|
127
128
|
"@typescript-eslint/no-useless-constructor": "off",
|
|
@@ -155,8 +156,12 @@
|
|
|
155
156
|
"dependencies": {
|
|
156
157
|
"@athenna/ioc": "1.1.3",
|
|
157
158
|
"@secjs/utils": "1.8.3",
|
|
159
|
+
"axios": "0.26.1",
|
|
158
160
|
"chalk": "4.1.1",
|
|
161
|
+
"pino": "7.10.0",
|
|
162
|
+
"pino-pretty": "7.6.1",
|
|
159
163
|
"reflect-metadata": "0.1.13",
|
|
164
|
+
"telegraf": "4.7.0",
|
|
160
165
|
"tscpaths": "0.0.9"
|
|
161
166
|
}
|
|
162
167
|
}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
+
import { DefaultDriverConfigs } from './DefaultDriverConfigs';
|
|
9
10
|
export interface DriverContract {
|
|
11
|
+
configs?: DefaultDriverConfigs | any;
|
|
10
12
|
transport(message: string, options?: any): void | Promise<void>;
|
|
11
13
|
}
|
|
@@ -6,20 +6,14 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import { Color } from '../Utils/Color';
|
|
10
9
|
import { DriverContract } from '../Contracts/DriverContract';
|
|
11
10
|
export interface ConsoleDriverOpts {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
formatter: string;
|
|
16
|
-
streamType: string;
|
|
17
|
-
formatterConfig: any;
|
|
11
|
+
streamType?: 'stdout' | 'stderr';
|
|
12
|
+
formatter?: any;
|
|
13
|
+
formatterConfig?: any;
|
|
18
14
|
}
|
|
19
15
|
export declare class ConsoleDriver implements DriverContract {
|
|
20
|
-
|
|
21
|
-
private readonly _streamType;
|
|
22
|
-
private readonly _formatterConfig;
|
|
16
|
+
configs: Required<ConsoleDriverOpts>;
|
|
23
17
|
constructor(channel: string, configs?: any);
|
|
24
18
|
transport(message: string, options?: ConsoleDriverOpts): void;
|
|
25
19
|
}
|
|
@@ -10,22 +10,17 @@
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.ConsoleDriver = void 0;
|
|
12
12
|
const utils_1 = require("@secjs/utils");
|
|
13
|
+
const groupConfigs_1 = require("../Utils/groupConfigs");
|
|
13
14
|
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
14
15
|
class ConsoleDriver {
|
|
15
16
|
constructor(channel, configs = {}) {
|
|
16
17
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
17
|
-
this.
|
|
18
|
-
this._streamType = configs.streamType || channelConfig.streamType;
|
|
19
|
-
this._formatterConfig = Object.assign({}, channelConfig.formatterConfig, configs.formatterConfig);
|
|
18
|
+
this.configs = groupConfigs_1.groupConfigs(configs, channelConfig);
|
|
20
19
|
}
|
|
21
|
-
transport(message, options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}, options);
|
|
26
|
-
const formatterOptions = Object.assign({}, this._formatterConfig, options.formatterConfig);
|
|
27
|
-
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, formatterOptions);
|
|
28
|
-
process[options.streamType].write(`${message}\n`);
|
|
20
|
+
transport(message, options = {}) {
|
|
21
|
+
const configs = groupConfigs_1.groupConfigs(options, this.configs);
|
|
22
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(configs.formatter).format(message, configs.formatterConfig);
|
|
23
|
+
process[configs.streamType].write(`${message}\n`);
|
|
29
24
|
}
|
|
30
25
|
}
|
|
31
26
|
exports.ConsoleDriver = ConsoleDriver;
|
|
@@ -6,20 +6,14 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import { Color } from '../Utils/Color';
|
|
10
9
|
import { DriverContract } from '../Contracts/DriverContract';
|
|
11
10
|
export interface DebugDriverOpts {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
formatter: string;
|
|
16
|
-
namespace: string;
|
|
17
|
-
formatterConfig: any;
|
|
11
|
+
namespace?: string;
|
|
12
|
+
formatter?: any;
|
|
13
|
+
formatterConfig?: any;
|
|
18
14
|
}
|
|
19
15
|
export declare class DebugDriver implements DriverContract {
|
|
20
|
-
|
|
21
|
-
private readonly _namespace;
|
|
22
|
-
private readonly _formatterConfig;
|
|
16
|
+
configs: Required<DebugDriverOpts>;
|
|
23
17
|
constructor(channel: string, configs?: any);
|
|
24
18
|
transport(message: string, options?: DebugDriverOpts): void;
|
|
25
19
|
}
|
|
@@ -11,22 +11,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
exports.DebugDriver = void 0;
|
|
12
12
|
const debug_1 = require("debug");
|
|
13
13
|
const utils_1 = require("@secjs/utils");
|
|
14
|
+
const groupConfigs_1 = require("../Utils/groupConfigs");
|
|
14
15
|
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
15
16
|
class DebugDriver {
|
|
16
17
|
constructor(channel, configs = {}) {
|
|
17
18
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
18
|
-
this.
|
|
19
|
-
this._namespace = configs.namespace || channelConfig.namespace;
|
|
20
|
-
this._formatterConfig = Object.assign({}, channelConfig.formatterConfig, configs.formatterConfig);
|
|
19
|
+
this.configs = groupConfigs_1.groupConfigs(configs, channelConfig);
|
|
21
20
|
}
|
|
22
|
-
transport(message, options) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}, options);
|
|
27
|
-
const formatterOptions = Object.assign({}, this._formatterConfig, options.formatterConfig);
|
|
28
|
-
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, formatterOptions);
|
|
29
|
-
debug_1.debug(options.namespace)(message);
|
|
21
|
+
transport(message, options = {}) {
|
|
22
|
+
const configs = groupConfigs_1.groupConfigs(options, this.configs);
|
|
23
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(configs.formatter).format(message, configs.formatterConfig);
|
|
24
|
+
debug_1.debug(configs.namespace)(message);
|
|
30
25
|
}
|
|
31
26
|
}
|
|
32
27
|
exports.DebugDriver = DebugDriver;
|
|
@@ -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 { DriverContract } from '../Contracts/DriverContract';
|
|
10
|
+
export interface DiscordDriverOpts {
|
|
11
|
+
url?: string;
|
|
12
|
+
username?: string;
|
|
13
|
+
formatter?: any;
|
|
14
|
+
formatterConfig?: any;
|
|
15
|
+
}
|
|
16
|
+
export declare class DiscordDriver implements DriverContract {
|
|
17
|
+
configs: Required<DiscordDriverOpts>;
|
|
18
|
+
constructor(channel: string, configs?: any);
|
|
19
|
+
transport(message: string, options?: DiscordDriverOpts): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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.DiscordDriver = void 0;
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const utils_1 = require("@secjs/utils");
|
|
17
|
+
const Color_1 = require("../Utils/Color");
|
|
18
|
+
const groupConfigs_1 = require("../Utils/groupConfigs");
|
|
19
|
+
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
20
|
+
class DiscordDriver {
|
|
21
|
+
constructor(channel, configs = {}) {
|
|
22
|
+
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
23
|
+
this.configs = groupConfigs_1.groupConfigs(configs, channelConfig);
|
|
24
|
+
}
|
|
25
|
+
async transport(message, options = {}) {
|
|
26
|
+
const configs = groupConfigs_1.groupConfigs(options, this.configs);
|
|
27
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(configs.formatter).format(message, configs.formatterConfig);
|
|
28
|
+
await axios_1.default.post(configs.url, {
|
|
29
|
+
username: configs.username,
|
|
30
|
+
content: Color_1.Color.removeColors(message),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.DiscordDriver = DiscordDriver;
|
|
@@ -8,16 +8,12 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { DriverContract } from '../Contracts/DriverContract';
|
|
10
10
|
export interface FileDriverOpts {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
filePath: string;
|
|
15
|
-
formatterConfig: any;
|
|
11
|
+
filePath?: string;
|
|
12
|
+
formatter?: any;
|
|
13
|
+
formatterConfig?: any;
|
|
16
14
|
}
|
|
17
15
|
export declare class FileDriver implements DriverContract {
|
|
18
|
-
|
|
19
|
-
private readonly _formatter;
|
|
20
|
-
private readonly _formatterConfig;
|
|
16
|
+
configs: Required<FileDriverOpts>;
|
|
21
17
|
constructor(channel: string, configs?: any);
|
|
22
18
|
transport(message: string, options?: FileDriverOpts): Promise<void>;
|
|
23
19
|
}
|
|
@@ -12,27 +12,22 @@ exports.FileDriver = void 0;
|
|
|
12
12
|
const path_1 = require("path");
|
|
13
13
|
const utils_1 = require("@secjs/utils");
|
|
14
14
|
const Color_1 = require("../Utils/Color");
|
|
15
|
+
const groupConfigs_1 = require("../Utils/groupConfigs");
|
|
15
16
|
const fs_1 = require("fs");
|
|
16
17
|
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
17
18
|
class FileDriver {
|
|
18
19
|
constructor(channel, configs = {}) {
|
|
19
20
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
20
|
-
this.
|
|
21
|
-
this._formatter = configs.formatter || channelConfig.formatter;
|
|
22
|
-
this._formatterConfig = Object.assign({}, channelConfig.formatterConfig, configs.formatterConfig);
|
|
21
|
+
this.configs = groupConfigs_1.groupConfigs(configs, channelConfig);
|
|
23
22
|
}
|
|
24
|
-
async transport(message, options) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
formatter: this._formatter,
|
|
28
|
-
}, options);
|
|
29
|
-
const filePath = options.filePath;
|
|
23
|
+
async transport(message, options = {}) {
|
|
24
|
+
const configs = groupConfigs_1.groupConfigs(options, this.configs);
|
|
25
|
+
const filePath = configs.filePath;
|
|
30
26
|
const { dir } = path_1.parse(filePath);
|
|
31
27
|
if (!fs_1.existsSync(dir)) {
|
|
32
28
|
fs_1.mkdirSync(dir, { recursive: true });
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, formatterOptions);
|
|
30
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(configs.formatter).format(message, configs.formatterConfig);
|
|
36
31
|
return new Promise((resolve, reject) => {
|
|
37
32
|
const stream = fs_1.createWriteStream(filePath, { flags: 'a' });
|
|
38
33
|
stream.write(`${Color_1.Color.removeColors(message)}` + '\n');
|
|
@@ -0,0 +1,13 @@
|
|
|
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 declare class NullDriver implements DriverContract {
|
|
11
|
+
constructor(_channel: string, _configs?: any);
|
|
12
|
+
transport(_message: string, _options?: any): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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.NullDriver = void 0;
|
|
12
|
+
class NullDriver {
|
|
13
|
+
constructor(_channel, _configs = {}) { }
|
|
14
|
+
transport(_message, _options) { }
|
|
15
|
+
}
|
|
16
|
+
exports.NullDriver = NullDriver;
|
|
@@ -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 pino from 'pino';
|
|
10
|
+
import pinoPretty from 'pino-pretty';
|
|
11
|
+
import { DriverContract } from '../Contracts/DriverContract';
|
|
12
|
+
export interface PinoDriverOpts extends pino.LoggerOptions {
|
|
13
|
+
formatter: 'pino-pretty';
|
|
14
|
+
formatterConfig: pinoPretty.PrettyOptions;
|
|
15
|
+
}
|
|
16
|
+
export declare class PinoDriver implements DriverContract {
|
|
17
|
+
configs: PinoDriverOpts;
|
|
18
|
+
constructor(channel: string, configs?: any);
|
|
19
|
+
transport(message: any, options?: Partial<PinoDriverOpts>): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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.PinoDriver = void 0;
|
|
15
|
+
const pino_1 = __importDefault(require("pino"));
|
|
16
|
+
const utils_1 = require("@secjs/utils");
|
|
17
|
+
const groupConfigs_1 = require("../Utils/groupConfigs");
|
|
18
|
+
const OnlyPinoPrettyException_1 = require("../Exceptions/OnlyPinoPrettyException");
|
|
19
|
+
class PinoDriver {
|
|
20
|
+
constructor(channel, configs = {}) {
|
|
21
|
+
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
22
|
+
this.configs = groupConfigs_1.groupConfigs(configs, channelConfig);
|
|
23
|
+
}
|
|
24
|
+
transport(message, options = {}) {
|
|
25
|
+
const configs = groupConfigs_1.groupConfigs(options, this.configs);
|
|
26
|
+
configs.customLevels = {
|
|
27
|
+
info: 1,
|
|
28
|
+
warn: 2,
|
|
29
|
+
error: 3,
|
|
30
|
+
debug: 4,
|
|
31
|
+
success: 5,
|
|
32
|
+
};
|
|
33
|
+
configs.useOnlyCustomLevels = true;
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
const pinoMethod = configs.formatterConfig.level.toLowerCase();
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
delete configs.formatterConfig.level;
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
delete configs.formatterConfig.chalk;
|
|
43
|
+
if (configs.formatter !== 'pino-pretty') {
|
|
44
|
+
throw new OnlyPinoPrettyException_1.OnlyPinoPrettyException();
|
|
45
|
+
}
|
|
46
|
+
const pinoConfigs = {};
|
|
47
|
+
Object.keys(configs).forEach(key => {
|
|
48
|
+
if (key === 'formatter') {
|
|
49
|
+
pinoConfigs.transport = {
|
|
50
|
+
target: 'pino-pretty',
|
|
51
|
+
options: configs.formatterConfig,
|
|
52
|
+
};
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
configs.formatterConfig.customLevels =
|
|
56
|
+
'info:1,warn:2,error:3,debug:4,success:5';
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
configs.formatterConfig.customColors =
|
|
60
|
+
'info:cyan,warn:yellow,error:red,debug:magenta,success:green';
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (['driver', 'formatterConfig'].includes(key)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
pinoConfigs[key] = configs[key];
|
|
67
|
+
});
|
|
68
|
+
const logger = pino_1.default(pinoConfigs);
|
|
69
|
+
return logger[pinoMethod](message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.PinoDriver = PinoDriver;
|
|
@@ -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 SlackDriverOpts {
|
|
11
|
+
url?: string;
|
|
12
|
+
formatter?: any;
|
|
13
|
+
formatterConfig?: any;
|
|
14
|
+
}
|
|
15
|
+
export declare class SlackDriver implements DriverContract {
|
|
16
|
+
configs: Required<SlackDriverOpts>;
|
|
17
|
+
constructor(channel: string, configs?: any);
|
|
18
|
+
transport(message: string, options?: SlackDriverOpts): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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.SlackDriver = void 0;
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const utils_1 = require("@secjs/utils");
|
|
17
|
+
const Color_1 = require("../Utils/Color");
|
|
18
|
+
const groupConfigs_1 = require("../Utils/groupConfigs");
|
|
19
|
+
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
20
|
+
class SlackDriver {
|
|
21
|
+
constructor(channel, configs = {}) {
|
|
22
|
+
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
23
|
+
this.configs = groupConfigs_1.groupConfigs(configs, channelConfig);
|
|
24
|
+
}
|
|
25
|
+
async transport(message, options = {}) {
|
|
26
|
+
const configs = groupConfigs_1.groupConfigs(options, this.configs);
|
|
27
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(configs.formatter).format(message, configs.formatterConfig);
|
|
28
|
+
await axios_1.default.post(configs.url, { text: Color_1.Color.removeColors(message) });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.SlackDriver = SlackDriver;
|
|
@@ -0,0 +1,21 @@
|
|
|
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 TelegramDriverOpts {
|
|
11
|
+
token?: string;
|
|
12
|
+
chatId?: string | number;
|
|
13
|
+
parseMode?: 'HTML' | 'Markdown' | 'MarkdownV2';
|
|
14
|
+
formatter?: any;
|
|
15
|
+
formatterConfig?: any;
|
|
16
|
+
}
|
|
17
|
+
export declare class TelegramDriver implements DriverContract {
|
|
18
|
+
configs: Required<TelegramDriverOpts>;
|
|
19
|
+
constructor(channel: string, configs?: any);
|
|
20
|
+
transport(message: string, options?: TelegramDriverOpts): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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.TelegramDriver = void 0;
|
|
12
|
+
const telegraf_1 = require("telegraf");
|
|
13
|
+
const utils_1 = require("@secjs/utils");
|
|
14
|
+
const Color_1 = require("../Utils/Color");
|
|
15
|
+
const groupConfigs_1 = require("../Utils/groupConfigs");
|
|
16
|
+
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
17
|
+
class TelegramDriver {
|
|
18
|
+
constructor(channel, configs = {}) {
|
|
19
|
+
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
20
|
+
this.configs = groupConfigs_1.groupConfigs(configs, channelConfig);
|
|
21
|
+
}
|
|
22
|
+
async transport(message, options = {}) {
|
|
23
|
+
const configs = groupConfigs_1.groupConfigs(options, this.configs);
|
|
24
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(configs.formatter).format(message, configs.formatterConfig);
|
|
25
|
+
await new telegraf_1.Telegraf(configs.token).telegram.sendMessage(configs.chatId, Color_1.Color.removeColors(message), {
|
|
26
|
+
parse_mode: configs.parseMode,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.TelegramDriver = TelegramDriver;
|
|
@@ -12,7 +12,7 @@ exports.NotFoundFormatterException = void 0;
|
|
|
12
12
|
const utils_1 = require("@secjs/utils");
|
|
13
13
|
class NotFoundFormatterException extends utils_1.Exception {
|
|
14
14
|
constructor(formatterName) {
|
|
15
|
-
const content = `The
|
|
15
|
+
const content = `The formatter ${formatterName} has not been found`;
|
|
16
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
17
|
}
|
|
18
18
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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 { Exception } from '@secjs/utils';
|
|
10
|
+
export declare class OnlyPinoPrettyException extends Exception {
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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.OnlyPinoPrettyException = void 0;
|
|
12
|
+
const utils_1 = require("@secjs/utils");
|
|
13
|
+
class OnlyPinoPrettyException extends utils_1.Exception {
|
|
14
|
+
constructor() {
|
|
15
|
+
const content = `The driver "pino" can only be used with "pino-pretty" formatter.`;
|
|
16
|
+
super(content, 500, 'ONLY_PINO-PRETTY_EXCEPTION', `Look into your config/logger file the formatter that you are trying to use with your channel configuration.`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.OnlyPinoPrettyException = OnlyPinoPrettyException;
|
|
@@ -10,9 +10,14 @@
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.DriverFactory = void 0;
|
|
12
12
|
const utils_1 = require("@secjs/utils");
|
|
13
|
+
const PinoDriver_1 = require("../Drivers/PinoDriver");
|
|
13
14
|
const FileDriver_1 = require("../Drivers/FileDriver");
|
|
15
|
+
const NullDriver_1 = require("../Drivers/NullDriver");
|
|
14
16
|
const DebugDriver_1 = require("../Drivers/DebugDriver");
|
|
17
|
+
const SlackDriver_1 = require("../Drivers/SlackDriver");
|
|
15
18
|
const ConsoleDriver_1 = require("../Drivers/ConsoleDriver");
|
|
19
|
+
const DiscordDriver_1 = require("../Drivers/DiscordDriver");
|
|
20
|
+
const TelegramDriver_1 = require("../Drivers/TelegramDriver");
|
|
16
21
|
const NotFoundDriverException_1 = require("../Exceptions/NotFoundDriverException");
|
|
17
22
|
const DriverAlreadyExistException_1 = require("../Exceptions/DriverAlreadyExistException");
|
|
18
23
|
const ChannelNotConfiguredException_1 = require("../Exceptions/ChannelNotConfiguredException");
|
|
@@ -55,5 +60,10 @@ class DriverFactory {
|
|
|
55
60
|
exports.DriverFactory = DriverFactory;
|
|
56
61
|
DriverFactory.drivers = new Map()
|
|
57
62
|
.set('file', { Driver: FileDriver_1.FileDriver })
|
|
63
|
+
.set('null', { Driver: NullDriver_1.NullDriver })
|
|
64
|
+
.set('pino', { Driver: PinoDriver_1.PinoDriver })
|
|
65
|
+
.set('slack', { Driver: SlackDriver_1.SlackDriver })
|
|
58
66
|
.set('debug', { Driver: DebugDriver_1.DebugDriver })
|
|
59
|
-
.set('console', { Driver: ConsoleDriver_1.ConsoleDriver })
|
|
67
|
+
.set('console', { Driver: ConsoleDriver_1.ConsoleDriver })
|
|
68
|
+
.set('discord', { Driver: DiscordDriver_1.DiscordDriver })
|
|
69
|
+
.set('telegram', { Driver: TelegramDriver_1.TelegramDriver });
|
|
@@ -13,6 +13,7 @@ const CliFormatter_1 = require("../Formatters/CliFormatter");
|
|
|
13
13
|
const JsonFormatter_1 = require("../Formatters/JsonFormatter");
|
|
14
14
|
const NestFormatter_1 = require("../Formatters/NestFormatter");
|
|
15
15
|
const SimpleFormatter_1 = require("../Formatters/SimpleFormatter");
|
|
16
|
+
const MessageFormatter_1 = require("../Formatters/MessageFormatter");
|
|
16
17
|
const RequestFormatter_1 = require("../Formatters/RequestFormatter");
|
|
17
18
|
const NotFoundFormatterException_1 = require("../Exceptions/NotFoundFormatterException");
|
|
18
19
|
const FormatterAlreadyExistException_1 = require("../Exceptions/FormatterAlreadyExistException");
|
|
@@ -44,4 +45,5 @@ FormatterFactory.formatters = new Map()
|
|
|
44
45
|
.set('nest', { Formatter: NestFormatter_1.NestFormatter })
|
|
45
46
|
.set('json', { Formatter: JsonFormatter_1.JsonFormatter })
|
|
46
47
|
.set('simple', { Formatter: SimpleFormatter_1.SimpleFormatter })
|
|
48
|
+
.set('message', { Formatter: MessageFormatter_1.MessageFormatter })
|
|
47
49
|
.set('request', { Formatter: RequestFormatter_1.RequestFormatter });
|
|
@@ -19,6 +19,8 @@ class CliFormatter {
|
|
|
19
19
|
error: Color_1.Color.error,
|
|
20
20
|
success: Color_1.Color.log,
|
|
21
21
|
};
|
|
22
|
+
if (!levelColors[level.toLowerCase()])
|
|
23
|
+
return `[ ${level.toLowerCase()} ]`;
|
|
22
24
|
return levelColors[level.toLowerCase()](`[ ${level.toLowerCase()} ]`);
|
|
23
25
|
}
|
|
24
26
|
format(message, options) {
|
|
@@ -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 { LevelTypes } from '../Contracts/LevelTypes';
|
|
10
|
+
import { FormatterContract } from '../Contracts/FormatterContract';
|
|
11
|
+
export interface MessageFormatterOpts {
|
|
12
|
+
level: LevelTypes;
|
|
13
|
+
customEmoji: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class MessageFormatter implements FormatterContract {
|
|
16
|
+
private static lastTimestamp?;
|
|
17
|
+
private static getTimestampDiff;
|
|
18
|
+
private static getEmojiByLevel;
|
|
19
|
+
format(message: string, options: MessageFormatterOpts): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable prettier/prettier */
|
|
3
|
+
/**
|
|
4
|
+
* @athenna/logger
|
|
5
|
+
*
|
|
6
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
7
|
+
*
|
|
8
|
+
* For the full copyright and license information, please view the LICENSE
|
|
9
|
+
* file that was distributed with this source code.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MessageFormatter = void 0;
|
|
13
|
+
const Color_1 = require("../Utils/Color");
|
|
14
|
+
class MessageFormatter {
|
|
15
|
+
static getTimestampDiff() {
|
|
16
|
+
let result = '';
|
|
17
|
+
if (this.lastTimestamp) {
|
|
18
|
+
result = Color_1.Color.yellow(` +${Date.now() - this.lastTimestamp}ms`);
|
|
19
|
+
}
|
|
20
|
+
this.lastTimestamp = Date.now();
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
static getEmojiByLevel(level, customEmoji) {
|
|
24
|
+
if (customEmoji)
|
|
25
|
+
return customEmoji;
|
|
26
|
+
const levelEmojis = {
|
|
27
|
+
info: '\u{2139}',
|
|
28
|
+
debug: '\u{1F50E}',
|
|
29
|
+
warn: '\u{26A0}',
|
|
30
|
+
error: '\u{274C}',
|
|
31
|
+
success: '\u{2705}',
|
|
32
|
+
};
|
|
33
|
+
if (!levelEmojis[level.toLowerCase()])
|
|
34
|
+
return '';
|
|
35
|
+
return levelEmojis[level.toLowerCase()];
|
|
36
|
+
}
|
|
37
|
+
format(message, options) {
|
|
38
|
+
const timestampDiff = MessageFormatter.getTimestampDiff();
|
|
39
|
+
const level = MessageFormatter.getEmojiByLevel(options.level, options.customEmoji);
|
|
40
|
+
return `${level} ${message}${timestampDiff}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.MessageFormatter = MessageFormatter;
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { Chalk } from 'chalk';
|
|
10
10
|
import { LevelTypes } from '../Contracts/LevelTypes';
|
|
11
11
|
import { FormatterContract } from '../Contracts/FormatterContract';
|
|
12
|
-
export interface
|
|
12
|
+
export interface SimpleFormatterOpts {
|
|
13
13
|
chalk: Chalk;
|
|
14
14
|
level: LevelTypes;
|
|
15
15
|
}
|
|
@@ -17,5 +17,5 @@ export declare class SimpleFormatter implements FormatterContract {
|
|
|
17
17
|
private static lastTimestamp?;
|
|
18
18
|
private static getTimestampDiff;
|
|
19
19
|
private static paintByLevel;
|
|
20
|
-
format(message: string, options:
|
|
20
|
+
format(message: string, options: SimpleFormatterOpts): string;
|
|
21
21
|
}
|
|
@@ -28,6 +28,8 @@ class SimpleFormatter {
|
|
|
28
28
|
error: Color_1.Color.error,
|
|
29
29
|
success: Color_1.Color.log,
|
|
30
30
|
};
|
|
31
|
+
if (!levelColors[level.toLowerCase()])
|
|
32
|
+
return `[${level.toUpperCase()}]`;
|
|
31
33
|
return levelColors[level.toLowerCase()](`[${level.toUpperCase()}]`);
|
|
32
34
|
}
|
|
33
35
|
format(message, options) {
|
package/src/Logger.js
CHANGED
|
@@ -133,7 +133,6 @@ class Logger {
|
|
|
133
133
|
*/
|
|
134
134
|
warn(message, options = {}) {
|
|
135
135
|
options = this.createOptions(options, {
|
|
136
|
-
streamType: 'stdout',
|
|
137
136
|
formatterConfig: {
|
|
138
137
|
level: 'WARN',
|
|
139
138
|
chalk: Color_1.Color.orange,
|
|
@@ -150,7 +149,6 @@ class Logger {
|
|
|
150
149
|
*/
|
|
151
150
|
error(message, options = {}) {
|
|
152
151
|
options = this.createOptions(options, {
|
|
153
|
-
streamType: 'stdout',
|
|
154
152
|
formatterConfig: {
|
|
155
153
|
level: 'ERROR',
|
|
156
154
|
chalk: Color_1.Color.red,
|
|
@@ -167,7 +165,6 @@ class Logger {
|
|
|
167
165
|
*/
|
|
168
166
|
debug(message, options = {}) {
|
|
169
167
|
options = this.createOptions(options, {
|
|
170
|
-
streamType: 'stdout',
|
|
171
168
|
formatterConfig: {
|
|
172
169
|
level: 'DEBUG',
|
|
173
170
|
chalk: Color_1.Color.purple,
|
|
@@ -184,7 +181,6 @@ class Logger {
|
|
|
184
181
|
*/
|
|
185
182
|
success(message, options = {}) {
|
|
186
183
|
options = this.createOptions(options, {
|
|
187
|
-
streamType: 'stdout',
|
|
188
184
|
formatterConfig: {
|
|
189
185
|
level: 'SUCCESS',
|
|
190
186
|
chalk: Color_1.Color.green,
|
|
@@ -210,9 +206,6 @@ class Logger {
|
|
|
210
206
|
...formatterConfig,
|
|
211
207
|
};
|
|
212
208
|
}
|
|
213
|
-
options = Object.assign({}, {
|
|
214
|
-
streamType: 'stdout',
|
|
215
|
-
}, options);
|
|
216
209
|
options = {
|
|
217
210
|
...options,
|
|
218
211
|
formatterConfig,
|
|
@@ -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 groupConfigs<T = any>(main: any, fallback: any): Required<T>;
|
|
@@ -0,0 +1,18 @@
|
|
|
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.groupConfigs = void 0;
|
|
12
|
+
function groupConfigs(main, fallback) {
|
|
13
|
+
const formatter = main.formatter || fallback.formatter;
|
|
14
|
+
const formatterConfig = Object.assign({}, fallback.formatterConfig, main.formatterConfig);
|
|
15
|
+
const driverConfig = Object.assign({}, fallback, main);
|
|
16
|
+
return { ...driverConfig, formatter, formatterConfig };
|
|
17
|
+
}
|
|
18
|
+
exports.groupConfigs = groupConfigs;
|