@athenna/logger 3.0.9 → 3.1.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.
- package/build/Drivers/ConsoleDriver.d.ts +12 -0
- package/build/Drivers/ConsoleDriver.js +19 -0
- package/build/Drivers/DiscordDriver.d.ts +12 -0
- package/build/Drivers/DiscordDriver.js +22 -0
- package/build/Drivers/Driver.d.ts +52 -0
- package/build/Drivers/Driver.js +85 -0
- package/build/Drivers/FileDriver.d.ts +12 -0
- package/build/Drivers/FileDriver.js +24 -0
- package/build/Drivers/NullDriver.d.ts +12 -0
- package/build/Drivers/NullDriver.js +14 -0
- package/build/Drivers/SlackDriver.d.ts +12 -0
- package/build/Drivers/SlackDriver.js +19 -0
- package/build/Drivers/StackDriver.d.ts +12 -0
- package/build/Drivers/StackDriver.js +19 -0
- package/build/Drivers/TelegramDriver.d.ts +12 -0
- package/build/Drivers/TelegramDriver.js +21 -0
- package/build/Exceptions/DriverExistException.d.ts +12 -0
- package/build/Exceptions/DriverExistException.js +21 -0
- package/{src/Facades/Log.js → build/Exceptions/FormatterExistException.d.ts} +4 -9
- package/build/Exceptions/FormatterExistException.js +21 -0
- package/build/Exceptions/NotFoundDriverException.d.ts +12 -0
- package/build/Exceptions/NotFoundDriverException.js +21 -0
- package/build/Exceptions/NotFoundFormatterException.d.ts +12 -0
- package/build/Exceptions/NotFoundFormatterException.js +21 -0
- package/build/Exceptions/NotImplementedConfigException.d.ts +12 -0
- package/build/Exceptions/NotImplementedConfigException.js +28 -0
- package/build/Facades/Log.d.ts +10 -0
- package/build/Facades/Log.js +10 -0
- package/build/Factories/DriverFactory.d.ts +39 -0
- package/build/Factories/DriverFactory.js +93 -0
- package/build/Factories/FormatterFactory.d.ts +29 -0
- package/build/Factories/FormatterFactory.js +57 -0
- package/build/Formatters/CliFormatter.d.ts +12 -0
- package/build/Formatters/CliFormatter.js +15 -0
- package/build/Formatters/Formatter.d.ts +85 -0
- package/build/Formatters/Formatter.js +177 -0
- package/build/Formatters/JsonFormatter.d.ts +12 -0
- package/build/Formatters/JsonFormatter.js +26 -0
- package/build/Formatters/MessageFormatter.d.ts +12 -0
- package/build/Formatters/MessageFormatter.js +14 -0
- package/build/Formatters/NoneFormatter.d.ts +12 -0
- package/{src → build}/Formatters/NoneFormatter.js +4 -12
- package/build/Formatters/RequestFormatter.d.ts +12 -0
- package/build/Formatters/RequestFormatter.js +45 -0
- package/build/Formatters/SimpleFormatter.d.ts +12 -0
- package/build/Formatters/SimpleFormatter.js +18 -0
- package/build/Helpers/ColorHelper.d.ts +131 -0
- package/build/Helpers/ColorHelper.js +215 -0
- package/build/Helpers/FactoryHelper.d.ts +14 -0
- package/build/Helpers/FactoryHelper.js +20 -0
- package/build/Logger/Logger.d.ts +68 -0
- package/build/Logger/Logger.js +105 -0
- package/build/Logger/VanillaLogger.d.ts +60 -0
- package/build/Logger/VanillaLogger.js +86 -0
- package/build/Providers/LoggerProvider.d.ts +12 -0
- package/{src → build}/Providers/LoggerProvider.js +5 -12
- package/build/index.d.ts +18 -0
- package/build/index.js +18 -0
- package/package.json +81 -59
- package/src/Drivers/ConsoleDriver.js +0 -40
- package/src/Drivers/DiscordDriver.js +0 -43
- package/src/Drivers/Driver.js +0 -134
- package/src/Drivers/FileDriver.js +0 -47
- package/src/Drivers/NullDriver.js +0 -33
- package/src/Drivers/SlackDriver.js +0 -40
- package/src/Drivers/StackDriver.js +0 -45
- package/src/Drivers/TelegramDriver.js +0 -46
- package/src/Exceptions/DriverExistException.js +0 -31
- package/src/Exceptions/FormatterExistException.js +0 -32
- package/src/Exceptions/NotFoundDriverException.js +0 -31
- package/src/Exceptions/NotFoundFormatterException.js +0 -31
- package/src/Exceptions/NotImplementedConfigException.js +0 -37
- package/src/Factories/DriverFactory.js +0 -128
- package/src/Factories/FormatterFactory.js +0 -77
- package/src/Formatters/CliFormatter.js +0 -24
- package/src/Formatters/Formatter.js +0 -266
- package/src/Formatters/JsonFormatter.js +0 -37
- package/src/Formatters/MessageFormatter.js +0 -26
- package/src/Formatters/RequestFormatter.js +0 -64
- package/src/Formatters/SimpleFormatter.js +0 -27
- package/src/Helpers/ColorHelper.js +0 -322
- package/src/Helpers/FactoryHelper.js +0 -31
- package/src/Helpers/VanillaLogger.js +0 -134
- package/src/index.d.ts +0 -797
- package/src/index.js +0 -180
|
@@ -6,17 +6,10 @@
|
|
|
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
|
-
|
|
10
|
-
import {
|
|
11
|
-
import { ServiceProvider } from '@athenna/ioc'
|
|
12
|
-
|
|
9
|
+
import { Logger } from '#src/Logger/Logger';
|
|
10
|
+
import { ServiceProvider } from '@athenna/ioc';
|
|
13
11
|
export class LoggerProvider extends ServiceProvider {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @return {void}
|
|
18
|
-
*/
|
|
19
|
-
register() {
|
|
20
|
-
this.container.bind('Athenna/Core/Logger', Logger, false)
|
|
21
|
-
}
|
|
12
|
+
register() {
|
|
13
|
+
this.container.bind('Athenna/Core/Logger', Logger, false);
|
|
14
|
+
}
|
|
22
15
|
}
|
package/build/index.d.ts
ADDED
|
@@ -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
|
+
export * from './Facades/Log.js';
|
|
10
|
+
export * from './Logger/Logger.js';
|
|
11
|
+
export * from './Drivers/Driver.js';
|
|
12
|
+
export * from './Helpers/ColorHelper.js';
|
|
13
|
+
export * from './Formatters/Formatter.js';
|
|
14
|
+
export * from './Logger/VanillaLogger.js';
|
|
15
|
+
export * from './Helpers/FactoryHelper.js';
|
|
16
|
+
export * from './Factories/DriverFactory.js';
|
|
17
|
+
export * from './Providers/LoggerProvider.js';
|
|
18
|
+
export * from './Factories/FormatterFactory.js';
|
package/build/index.js
ADDED
|
@@ -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
|
+
export * from './Facades/Log.js';
|
|
10
|
+
export * from './Logger/Logger.js';
|
|
11
|
+
export * from './Drivers/Driver.js';
|
|
12
|
+
export * from './Helpers/ColorHelper.js';
|
|
13
|
+
export * from './Formatters/Formatter.js';
|
|
14
|
+
export * from './Logger/VanillaLogger.js';
|
|
15
|
+
export * from './Helpers/FactoryHelper.js';
|
|
16
|
+
export * from './Factories/DriverFactory.js';
|
|
17
|
+
export * from './Providers/LoggerProvider.js';
|
|
18
|
+
export * from './Factories/FormatterFactory.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/logger",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "The Athenna logging solution. Log in stdout, files and buckets.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -22,70 +22,82 @@
|
|
|
22
22
|
"esm"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"test
|
|
28
|
-
"test:
|
|
29
|
-
"
|
|
25
|
+
"build": "rimraf build && tsc",
|
|
26
|
+
"lint:fix": "eslint \"{src,tests}/**/*.ts\" --fix",
|
|
27
|
+
"test": "npm run --silent lint:fix && ts-node ./bin/test.ts",
|
|
28
|
+
"test:debug": "cross-env DEBUG=api:* ts-node ./bin/test.ts --inspect",
|
|
29
|
+
"test:coverage": "c8 npm run --silent test"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
32
|
+
"build/*.js",
|
|
33
|
+
"build/*.d.ts",
|
|
34
|
+
"build/**/*.js",
|
|
35
|
+
"build/**/*.d.ts",
|
|
36
|
+
"templates/**"
|
|
36
37
|
],
|
|
37
38
|
"type": "module",
|
|
38
|
-
"main": "./
|
|
39
|
-
"types": "./
|
|
39
|
+
"main": "./build/index.js",
|
|
40
|
+
"types": "./build/index.d.ts",
|
|
40
41
|
"imports": {
|
|
41
|
-
"#src/*": "./
|
|
42
|
-
"#
|
|
42
|
+
"#src/*": "./build/*.js",
|
|
43
|
+
"#src": "./build/index.js",
|
|
44
|
+
"#tests/*": "./tests/*.js",
|
|
45
|
+
"#tests": "./tests/index.js"
|
|
43
46
|
},
|
|
44
47
|
"exports": {
|
|
45
|
-
".": "./
|
|
46
|
-
"./
|
|
47
|
-
"./providers/LoggerProvider": "./src/Providers/LoggerProvider.js"
|
|
48
|
+
".": "./build/index.js",
|
|
49
|
+
"./providers/LoggerProvider": "./build/Providers/LoggerProvider.js"
|
|
48
50
|
},
|
|
49
51
|
"dependencies": {
|
|
50
|
-
"chalk": "5.0
|
|
51
|
-
"telegraf": "4.
|
|
52
|
+
"chalk": "^5.2.0",
|
|
53
|
+
"telegraf": "^4.11.2"
|
|
52
54
|
},
|
|
53
55
|
"devDependencies": {
|
|
54
|
-
"@athenna/common": "3.0.
|
|
55
|
-
"@athenna/config": "3.0.
|
|
56
|
-
"@athenna/ioc": "3.0.
|
|
57
|
-
"@japa/assert": "1.3.
|
|
58
|
-
"@japa/run-failed-tests": "1.0
|
|
59
|
-
"@japa/runner": "2.
|
|
60
|
-
"@japa/spec-reporter": "1.
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"eslint-plugin
|
|
71
|
-
"eslint
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
56
|
+
"@athenna/common": "^3.0.0",
|
|
57
|
+
"@athenna/config": "^3.0.0",
|
|
58
|
+
"@athenna/ioc": "^3.0.0",
|
|
59
|
+
"@japa/assert": "^1.3.6",
|
|
60
|
+
"@japa/run-failed-tests": "^1.1.0",
|
|
61
|
+
"@japa/runner": "^2.2.2",
|
|
62
|
+
"@japa/spec-reporter": "^1.3.2",
|
|
63
|
+
"@swc/core": "^1.3.27",
|
|
64
|
+
"@types/bytes": "^3.1.1",
|
|
65
|
+
"@types/callsite": "^1.0.31",
|
|
66
|
+
"@types/debug": "^4.1.7",
|
|
67
|
+
"@types/kind-of": "^6.0.0",
|
|
68
|
+
"@types/lodash": "^4.14.191",
|
|
69
|
+
"@types/ms": "^0.7.31",
|
|
70
|
+
"@types/pluralize": "^0.0.29",
|
|
71
|
+
"@types/uuid": "^9.0.0",
|
|
72
|
+
"@typescript-eslint/eslint-plugin": "^5.48.1",
|
|
73
|
+
"@typescript-eslint/parser": "^5.48.1",
|
|
74
|
+
"c8": "^7.12.0",
|
|
75
|
+
"cls-rtracer": "^2.6.2",
|
|
76
|
+
"commitizen": "^4.2.6",
|
|
77
|
+
"cross-env": "^7.0.3",
|
|
78
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
79
|
+
"eslint": "^8.32.0",
|
|
80
|
+
"eslint-config-prettier": "^8.6.0",
|
|
81
|
+
"eslint-config-standard": "^17.0.0",
|
|
82
|
+
"eslint-plugin-import": "^2.27.5",
|
|
83
|
+
"eslint-plugin-n": "^15.6.1",
|
|
84
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
85
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
86
|
+
"husky": "^3.1.0",
|
|
87
|
+
"lint-staged": "^12.5.0",
|
|
88
|
+
"minimist": "^1.2.7",
|
|
89
|
+
"prettier": "^2.8.3",
|
|
90
|
+
"reflect-metadata": "^0.1.13",
|
|
91
|
+
"rimraf": "^3.0.2",
|
|
92
|
+
"ts-node": "^10.9.1",
|
|
93
|
+
"typescript": "^4.9.4"
|
|
80
94
|
},
|
|
81
95
|
"c8": {
|
|
82
96
|
"all": true,
|
|
83
97
|
"include": [
|
|
84
|
-
"src/**/*.
|
|
85
|
-
],
|
|
86
|
-
"exclude": [
|
|
87
|
-
"src/Helpers/ColorHelper.js"
|
|
98
|
+
"src/**/*.ts"
|
|
88
99
|
],
|
|
100
|
+
"exclude": [],
|
|
89
101
|
"reporter": [
|
|
90
102
|
"text-summary",
|
|
91
103
|
"html"
|
|
@@ -129,6 +141,9 @@
|
|
|
129
141
|
}
|
|
130
142
|
]
|
|
131
143
|
},
|
|
144
|
+
"eslintIgnore": [
|
|
145
|
+
"build/**/*"
|
|
146
|
+
],
|
|
132
147
|
"eslintConfig": {
|
|
133
148
|
"env": {
|
|
134
149
|
"es2021": true,
|
|
@@ -141,25 +156,32 @@
|
|
|
141
156
|
"Config": true
|
|
142
157
|
},
|
|
143
158
|
"plugins": [
|
|
144
|
-
"prettier"
|
|
159
|
+
"prettier",
|
|
160
|
+
"@typescript-eslint"
|
|
145
161
|
],
|
|
146
162
|
"extends": [
|
|
147
163
|
"standard",
|
|
148
164
|
"eslint:recommended",
|
|
149
|
-
"plugin:prettier/recommended"
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
"**/*.d.ts"
|
|
165
|
+
"plugin:prettier/recommended",
|
|
166
|
+
"plugin:@typescript-eslint/recommended",
|
|
167
|
+
"plugin:@typescript-eslint/eslint-recommended"
|
|
153
168
|
],
|
|
154
|
-
"
|
|
155
|
-
"ecmaVersion": "latest",
|
|
156
|
-
"sourceType": "module"
|
|
157
|
-
},
|
|
169
|
+
"parser": "@typescript-eslint/parser",
|
|
158
170
|
"rules": {
|
|
159
171
|
"camelcase": "off",
|
|
160
172
|
"dot-notation": "off",
|
|
161
173
|
"prettier/prettier": "error",
|
|
162
|
-
"no-useless-constructor": "off"
|
|
174
|
+
"no-useless-constructor": "off",
|
|
175
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
176
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
177
|
+
"@typescript-eslint/no-unused-vars": [
|
|
178
|
+
"error",
|
|
179
|
+
{
|
|
180
|
+
"argsIgnorePattern": "^_",
|
|
181
|
+
"varsIgnorePattern": "^_",
|
|
182
|
+
"caughtErrorsIgnorePattern": "^_"
|
|
183
|
+
}
|
|
184
|
+
]
|
|
163
185
|
}
|
|
164
186
|
}
|
|
165
187
|
}
|
|
@@ -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 { Driver } from '#src/Drivers/Driver'
|
|
11
|
-
|
|
12
|
-
export class ConsoleDriver extends Driver {
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new instance of ConsoleDriver.
|
|
15
|
-
*
|
|
16
|
-
* @param {any} configs
|
|
17
|
-
* @return {ConsoleDriver}
|
|
18
|
-
*/
|
|
19
|
-
constructor(configs) {
|
|
20
|
-
super(configs)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Transport the log.
|
|
25
|
-
*
|
|
26
|
-
* @param {string} level
|
|
27
|
-
* @param {any} message
|
|
28
|
-
* @return {any}
|
|
29
|
-
*/
|
|
30
|
-
transport(level, message) {
|
|
31
|
-
if (!this.couldBeTransported(level)) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const formatted = this.format(level, message)
|
|
36
|
-
const streamType = this.getStreamTypeFor(level)
|
|
37
|
-
|
|
38
|
-
return process[streamType].write(`${formatted}\n`)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -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
|
-
}
|
package/src/Drivers/Driver.js
DELETED
|
@@ -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
|
-
}
|