@athenna/logger 1.1.8 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +3 -15
- package/README.md +6 -6
- package/package.json +87 -106
- package/src/Drivers/ConsoleDriver.js +43 -17
- package/src/Drivers/DebugDriver.js +45 -18
- package/src/Drivers/DiscordDriver.js +48 -25
- package/src/Drivers/FileDriver.js +51 -29
- package/src/Drivers/NullDriver.js +19 -7
- package/src/Drivers/PinoDriver.js +83 -61
- package/src/Drivers/SlackDriver.js +45 -22
- package/src/Drivers/TelegramDriver.js +44 -21
- package/src/Exceptions/DriverExistException.js +31 -0
- package/src/Exceptions/FormatterExistException.js +32 -0
- package/src/Exceptions/NotFoundChannelException.js +32 -0
- package/src/Exceptions/NotFoundDriverException.js +22 -10
- package/src/Exceptions/NotFoundFormatterException.js +22 -10
- package/src/Exceptions/OnlyPinoPrettyException.js +19 -10
- package/src/Facades/Log.js +9 -5
- package/src/Factories/DriverFactory.js +98 -56
- package/src/Factories/FormatterFactory.js +67 -37
- package/src/Formatters/CliFormatter.js +21 -22
- package/src/Formatters/JsonFormatter.js +15 -10
- package/src/Formatters/MessageFormatter.js +30 -33
- package/src/Formatters/NestFormatter.js +31 -22
- package/src/Formatters/NoneFormatter.js +21 -0
- package/src/Formatters/RequestFormatter.js +49 -37
- package/src/Formatters/SimpleFormatter.js +30 -33
- package/src/Helpers/ColorHelper.js +259 -0
- package/src/Helpers/FactoryHelper.js +121 -0
- package/src/Providers/LoggerProvider.js +13 -15
- package/src/index.d.ts +383 -0
- package/src/index.js +269 -0
- package/index.d.ts +0 -13
- package/index.js +0 -25
- package/src/Contracts/DefaultDriverConfigs.d.ts +0 -4
- package/src/Contracts/DefaultDriverConfigs.js +0 -2
- package/src/Contracts/DriverContract.d.ts +0 -13
- package/src/Contracts/DriverContract.js +0 -10
- package/src/Contracts/FormatterContract.d.ts +0 -11
- package/src/Contracts/FormatterContract.js +0 -10
- package/src/Contracts/LevelTypes.d.ts +0 -1
- package/src/Contracts/LevelTypes.js +0 -2
- package/src/Drivers/ConsoleDriver.d.ts +0 -19
- package/src/Drivers/DebugDriver.d.ts +0 -19
- package/src/Drivers/DiscordDriver.d.ts +0 -20
- package/src/Drivers/FileDriver.d.ts +0 -19
- package/src/Drivers/NullDriver.d.ts +0 -13
- package/src/Drivers/PinoDriver.d.ts +0 -20
- package/src/Drivers/SlackDriver.d.ts +0 -19
- package/src/Drivers/TelegramDriver.d.ts +0 -21
- package/src/Exceptions/ChannelNotConfiguredException.d.ts +0 -12
- package/src/Exceptions/ChannelNotConfiguredException.js +0 -19
- package/src/Exceptions/DriverAlreadyExistException.d.ts +0 -12
- package/src/Exceptions/DriverAlreadyExistException.js +0 -19
- package/src/Exceptions/FormatterAlreadyExistException.d.ts +0 -12
- package/src/Exceptions/FormatterAlreadyExistException.js +0 -19
- package/src/Exceptions/NotFoundDriverException.d.ts +0 -12
- package/src/Exceptions/NotFoundFormatterException.d.ts +0 -12
- package/src/Exceptions/OnlyPinoPrettyException.d.ts +0 -12
- package/src/Facades/Log.d.ts +0 -10
- package/src/Factories/DriverFactory.d.ts +0 -19
- package/src/Factories/FormatterFactory.d.ts +0 -18
- package/src/Formatters/CliFormatter.d.ts +0 -19
- package/src/Formatters/JsonFormatter.d.ts +0 -16
- package/src/Formatters/MessageFormatter.d.ts +0 -20
- package/src/Formatters/NestFormatter.d.ts +0 -19
- package/src/Formatters/RequestFormatter.d.ts +0 -17
- package/src/Formatters/SimpleFormatter.d.ts +0 -21
- package/src/Logger.d.ts +0 -110
- package/src/Logger.js +0 -216
- package/src/Providers/LoggerProvider.d.ts +0 -17
- package/src/Utils/Color.d.ts +0 -48
- package/src/Utils/Color.js +0 -93
- package/src/Utils/getTimestamp.d.ts +0 -9
- package/src/Utils/getTimestamp.js +0 -23
- package/src/Utils/groupConfigs.d.ts +0 -9
- package/src/Utils/groupConfigs.js +0 -18
package/LICENSE.md
CHANGED
|
@@ -2,20 +2,8 @@ MIT License
|
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2022 The Athenna Framework
|
|
4
4
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
11
6
|
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
14
8
|
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Template 📔
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Template for new projects
|
|
4
4
|
|
|
5
5
|
[](https://github.com/athennaio?tab=followers)
|
|
6
|
-
[](https://github.com/AthennaIO/Logger/stargazers/)
|
|
7
7
|
|
|
8
8
|
<p>
|
|
9
9
|
<a href="https://www.buymeacoffee.com/athenna" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
12
|
<p>
|
|
13
|
-
<img alt="GitHub language count" src="https://img.shields.io/github/languages/count/
|
|
13
|
+
<img alt="GitHub language count" src="https://img.shields.io/github/languages/count/AthennaIO/Logger?style=for-the-badge&logo=appveyor">
|
|
14
14
|
|
|
15
|
-
<img alt="Repository size" src="https://img.shields.io/github/repo-size/
|
|
15
|
+
<img alt="Repository size" src="https://img.shields.io/github/repo-size/AthennaIO/Logger?style=for-the-badge&logo=appveyor">
|
|
16
16
|
|
|
17
17
|
<img alt="License" src="https://img.shields.io/badge/license-MIT-brightgreen?style=for-the-badge&logo=appveyor">
|
|
18
18
|
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
## Contributing
|
|
29
29
|
|
|
30
|
-
> If you want to contribute to this project, first read the [CONTRIBUTING.MD](https://github.com/
|
|
30
|
+
> If you want to contribute to this project, first read the [CONTRIBUTING.MD](https://github.com/AthennaIO/Logger/blob/develop/CONTRIBUTING.md) file. It will be a pleasure to receive your help.
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
package/package.json
CHANGED
|
@@ -1,49 +1,91 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/logger",
|
|
3
|
-
"version": "1.1
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "Template for new projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
7
|
-
"repository": "https://github.com/AthennaIO/Logger.git",
|
|
8
7
|
"bugs": "https://github.com/AthennaIO/Logger/issues",
|
|
8
|
+
"repository": "https://github.com/AthennaIO/Logger.git",
|
|
9
9
|
"homepage": "https://github.com/AthennaIO/Logger#readme",
|
|
10
|
+
"keywords": [],
|
|
10
11
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"test": "npm run lint:fix &&
|
|
13
|
-
"test:debug": "
|
|
14
|
-
"
|
|
12
|
+
"lint:fix": "eslint \"{src,tests}/**/*.js\" --fix",
|
|
13
|
+
"test": "npm run --silent lint:fix && node ./tests/index.js",
|
|
14
|
+
"test:debug": "cross-env DEBUG=api:* && npm run --silent test",
|
|
15
|
+
"test:coverage": "c8 npm run --silent test",
|
|
16
|
+
"gen:types": "tsc src/*.js --declaration --allowJs --emitDeclarationOnly --out src/index.js"
|
|
15
17
|
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"files": [
|
|
19
|
+
"src/*.js",
|
|
20
|
+
"src/*.d.ts",
|
|
21
|
+
"src/**/*.js",
|
|
22
|
+
"src/**/*.d.ts"
|
|
20
23
|
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./src/index.js",
|
|
26
|
+
"types": "./src/index.d.ts",
|
|
27
|
+
"imports": {
|
|
28
|
+
"#src/*": "./src/*.js",
|
|
29
|
+
"#tests/*": "./tests/*.js"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": "./src/index.js",
|
|
33
|
+
"./facades/Log": "./src/Facades/Log.js",
|
|
34
|
+
"./providers/LoggerProvider": "./src/Providers/LoggerProvider.js"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@athenna/ioc": "1.1.7",
|
|
38
|
+
"@secjs/utils": "1.9.3",
|
|
39
|
+
"axios": "0.26.1",
|
|
40
|
+
"chalk": "5.0.1",
|
|
41
|
+
"debug": "4.3.4",
|
|
42
|
+
"pino": "7.10.0",
|
|
43
|
+
"pino-pretty": "7.6.1",
|
|
44
|
+
"telegraf": "4.7.0"
|
|
45
|
+
},
|
|
21
46
|
"devDependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"@
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
47
|
+
"@japa/assert": "1.3.4",
|
|
48
|
+
"@japa/run-failed-tests": "1.0.7",
|
|
49
|
+
"@japa/runner": "2.0.7",
|
|
50
|
+
"@japa/spec-reporter": "1.1.12",
|
|
51
|
+
"c8": "7.11.2",
|
|
26
52
|
"commitizen": "4.2.4",
|
|
27
53
|
"cross-env": "7.0.3",
|
|
28
54
|
"cz-conventional-changelog": "3.3.0",
|
|
29
|
-
"eslint": "
|
|
30
|
-
"eslint-config-prettier": "8.
|
|
31
|
-
"eslint-config-standard": "
|
|
32
|
-
"eslint-import
|
|
33
|
-
"eslint-plugin-
|
|
34
|
-
"eslint-plugin-node": "11.1.0",
|
|
55
|
+
"eslint": "8.14.0",
|
|
56
|
+
"eslint-config-prettier": "8.5.0",
|
|
57
|
+
"eslint-config-standard": "17.0.0",
|
|
58
|
+
"eslint-plugin-import": "2.26.0",
|
|
59
|
+
"eslint-plugin-n": "15.2.0",
|
|
35
60
|
"eslint-plugin-prettier": "4.0.0",
|
|
36
|
-
"eslint-plugin-promise": "
|
|
37
|
-
"eslint-plugin-standard": "5.0.0",
|
|
61
|
+
"eslint-plugin-promise": "6.0.0",
|
|
38
62
|
"husky": "3.0.9",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"prettier": "2.
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
63
|
+
"lint-staged": "12.4.1",
|
|
64
|
+
"minimist": "1.2.6",
|
|
65
|
+
"prettier": "2.6.2",
|
|
66
|
+
"rimraf": "3.0.2",
|
|
67
|
+
"typescript": "4.6.4"
|
|
68
|
+
},
|
|
69
|
+
"c8": {
|
|
70
|
+
"all": true,
|
|
71
|
+
"include": [
|
|
72
|
+
"src/**/*.js"
|
|
73
|
+
],
|
|
74
|
+
"reporter": [
|
|
75
|
+
"text-summary",
|
|
76
|
+
"html"
|
|
77
|
+
],
|
|
78
|
+
"report-dir": "./tests/Coverage",
|
|
79
|
+
"check-coverage": true,
|
|
80
|
+
"statements": "80",
|
|
81
|
+
"branches": "80",
|
|
82
|
+
"functions": "50",
|
|
83
|
+
"lines": "80"
|
|
84
|
+
},
|
|
85
|
+
"husky": {
|
|
86
|
+
"hooks": {
|
|
87
|
+
"prepare-commit-msg": "lint-staged && exec < /dev/tty && git cz --hook || true"
|
|
88
|
+
}
|
|
47
89
|
},
|
|
48
90
|
"lint-staged": {
|
|
49
91
|
"*.js": [
|
|
@@ -55,30 +97,11 @@
|
|
|
55
97
|
"git add"
|
|
56
98
|
]
|
|
57
99
|
},
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"prepare-commit-msg": "exec < /dev/tty && git cz --hook || true"
|
|
100
|
+
"config": {
|
|
101
|
+
"commitizen": {
|
|
102
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
62
103
|
}
|
|
63
104
|
},
|
|
64
|
-
"jest": {
|
|
65
|
-
"modulePaths": [
|
|
66
|
-
"<rootDir>"
|
|
67
|
-
],
|
|
68
|
-
"moduleFileExtensions": [
|
|
69
|
-
"js",
|
|
70
|
-
"json",
|
|
71
|
-
"ts"
|
|
72
|
-
],
|
|
73
|
-
"rootDir": ".",
|
|
74
|
-
"testRegex": "Test.ts$",
|
|
75
|
-
"transform": {
|
|
76
|
-
"^.+\\.(t|j)s$": "ts-jest"
|
|
77
|
-
},
|
|
78
|
-
"coverageDirectory": "./coverage",
|
|
79
|
-
"preset": "ts-jest",
|
|
80
|
-
"testEnvironment": "node"
|
|
81
|
-
},
|
|
82
105
|
"prettier": {
|
|
83
106
|
"singleQuote": true,
|
|
84
107
|
"trailingComma": "all",
|
|
@@ -97,71 +120,29 @@
|
|
|
97
120
|
},
|
|
98
121
|
"eslintConfig": {
|
|
99
122
|
"env": {
|
|
100
|
-
"
|
|
123
|
+
"es2021": true,
|
|
101
124
|
"node": true
|
|
102
125
|
},
|
|
126
|
+
"plugins": [
|
|
127
|
+
"prettier"
|
|
128
|
+
],
|
|
103
129
|
"extends": [
|
|
104
130
|
"standard",
|
|
105
|
-
"
|
|
131
|
+
"eslint:recommended",
|
|
106
132
|
"plugin:prettier/recommended"
|
|
107
133
|
],
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
|
|
111
|
-
},
|
|
112
|
-
"parser": "@typescript-eslint/parser",
|
|
134
|
+
"ignorePatterns": [
|
|
135
|
+
"**/*.d.ts"
|
|
136
|
+
],
|
|
113
137
|
"parserOptions": {
|
|
114
|
-
"ecmaVersion":
|
|
138
|
+
"ecmaVersion": "latest",
|
|
115
139
|
"sourceType": "module"
|
|
116
140
|
},
|
|
117
|
-
"plugins": [
|
|
118
|
-
"@typescript-eslint",
|
|
119
|
-
"prettier"
|
|
120
|
-
],
|
|
121
141
|
"rules": {
|
|
122
|
-
"dot-notation": "off",
|
|
123
142
|
"camelcase": "off",
|
|
124
|
-
"
|
|
125
|
-
"no-useless-escape": "off",
|
|
126
|
-
"@typescript-eslint/no-var-requires": "off",
|
|
127
|
-
"no-useless-constructor": "off",
|
|
128
|
-
"@typescript-eslint/no-useless-constructor": "off",
|
|
129
|
-
"@typescript-eslint/camelcase": "off",
|
|
130
|
-
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
131
|
-
"@typescript-eslint/interface-name-prefix": "off",
|
|
132
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
143
|
+
"dot-notation": "off",
|
|
133
144
|
"prettier/prettier": "error",
|
|
134
|
-
"
|
|
135
|
-
"@typescript-eslint/no-unused-vars": [
|
|
136
|
-
"error",
|
|
137
|
-
{
|
|
138
|
-
"argsIgnorePattern": "_"
|
|
139
|
-
}
|
|
140
|
-
]
|
|
145
|
+
"no-useless-constructor": "off"
|
|
141
146
|
}
|
|
142
|
-
},
|
|
143
|
-
"files": [
|
|
144
|
-
"src/*.js",
|
|
145
|
-
"src/*.d.ts",
|
|
146
|
-
"src/**/*.js",
|
|
147
|
-
"src/**/*.d.ts",
|
|
148
|
-
"*.js",
|
|
149
|
-
"*.d.ts"
|
|
150
|
-
],
|
|
151
|
-
"config": {
|
|
152
|
-
"commitizen": {
|
|
153
|
-
"path": "./node_modules/cz-conventional-changelog"
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
"dependencies": {
|
|
157
|
-
"@athenna/ioc": "1.1.3",
|
|
158
|
-
"@secjs/utils": "1.8.3",
|
|
159
|
-
"axios": "0.26.1",
|
|
160
|
-
"chalk": "4.1.1",
|
|
161
|
-
"pino": "7.10.0",
|
|
162
|
-
"pino-pretty": "7.6.1",
|
|
163
|
-
"reflect-metadata": "0.1.13",
|
|
164
|
-
"telegraf": "4.7.0",
|
|
165
|
-
"tscpaths": "0.0.9"
|
|
166
147
|
}
|
|
167
148
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @athenna/logger
|
|
4
3
|
*
|
|
@@ -7,20 +6,47 @@
|
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class ConsoleDriver {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
|
|
10
|
+
import { Config } from '@secjs/utils'
|
|
11
|
+
|
|
12
|
+
import { FactoryHelper, FormatterFactory } from '#src/index'
|
|
13
|
+
|
|
14
|
+
export class ConsoleDriver {
|
|
15
|
+
/**
|
|
16
|
+
* Holds the configuration set of ConsoleDriver.
|
|
17
|
+
*
|
|
18
|
+
* @type {{ streamType?: 'stdout' | 'stderr', formatter?: any, formatterConfig?: any }}
|
|
19
|
+
*/
|
|
20
|
+
configs
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new instance of ConsoleDriver.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} channel
|
|
26
|
+
* @param {any} [configs]
|
|
27
|
+
* @return {ConsoleDriver}
|
|
28
|
+
*/
|
|
29
|
+
constructor(channel, configs) {
|
|
30
|
+
const channelConfig = Config.get(`logging.channels.${channel}`)
|
|
31
|
+
|
|
32
|
+
this.configs = FactoryHelper.groupConfigs(configs, channelConfig)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Transport the log.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} message
|
|
39
|
+
* @param {{ streamType?: 'stdout' | 'stderr', formatter?: any, formatterConfig?: any }} [options]
|
|
40
|
+
* @return {void}
|
|
41
|
+
*/
|
|
42
|
+
transport(message, options = {}) {
|
|
43
|
+
const configs = FactoryHelper.groupConfigs(options, this.configs)
|
|
44
|
+
|
|
45
|
+
message = FormatterFactory.fabricate(configs.formatter).format(
|
|
46
|
+
message,
|
|
47
|
+
configs.formatterConfig,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
process[configs.streamType].write(`${message}\n`)
|
|
51
|
+
}
|
|
25
52
|
}
|
|
26
|
-
exports.ConsoleDriver = ConsoleDriver;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @athenna/logger
|
|
4
3
|
*
|
|
@@ -7,21 +6,49 @@
|
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
|
|
10
|
+
import debug from 'debug'
|
|
11
|
+
|
|
12
|
+
import { Config } from '@secjs/utils'
|
|
13
|
+
|
|
14
|
+
import { FactoryHelper, FormatterFactory } from '#src/index'
|
|
15
|
+
|
|
16
|
+
export class DebugDriver {
|
|
17
|
+
/**
|
|
18
|
+
* Holds the configuration set of DebugDriver.
|
|
19
|
+
*
|
|
20
|
+
* @type {{ namespace?: string, formatter?: any, formatterConfig?: any }}
|
|
21
|
+
*/
|
|
22
|
+
configs
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new instance of DebugDriver.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} channel
|
|
28
|
+
* @param {any} [configs]
|
|
29
|
+
* @return {DebugDriver}
|
|
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 {{ namespace?: string, formatter?: any, formatterConfig?: any }} [options]
|
|
42
|
+
* @return {void}
|
|
43
|
+
*/
|
|
44
|
+
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
|
+
debug(configs.namespace)(message)
|
|
53
|
+
}
|
|
26
54
|
}
|
|
27
|
-
exports.DebugDriver = DebugDriver;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @athenna/logger
|
|
4
3
|
*
|
|
@@ -7,28 +6,52 @@
|
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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 DiscordDriver {
|
|
17
|
+
/**
|
|
18
|
+
* Holds the configuration set of DiscordDriver.
|
|
19
|
+
*
|
|
20
|
+
* @type {{ url?: string, username?: string, formatter?: any, formatterConfig?: any }}
|
|
21
|
+
*/
|
|
22
|
+
configs
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new instance of DiscordDriver.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} channel
|
|
28
|
+
* @param {any} [configs]
|
|
29
|
+
* @return {DiscordDriver}
|
|
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, username?: string, formatter?: any, formatterConfig?: any }} [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, {
|
|
53
|
+
username: configs.username,
|
|
54
|
+
content: ColorHelper.removeColors(message),
|
|
55
|
+
})
|
|
56
|
+
}
|
|
33
57
|
}
|
|
34
|
-
exports.DiscordDriver = DiscordDriver;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @athenna/logger
|
|
4
3
|
*
|
|
@@ -7,33 +6,56 @@
|
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
9
|
+
|
|
10
|
+
import { Config, File } from '@secjs/utils'
|
|
11
|
+
|
|
12
|
+
import { ColorHelper, FactoryHelper, FormatterFactory } from '#src/index'
|
|
13
|
+
|
|
14
|
+
export class FileDriver {
|
|
15
|
+
/**
|
|
16
|
+
* Holds the configuration set of FileDriver.
|
|
17
|
+
*
|
|
18
|
+
* @type {{ filePath?: string, formatter?: any, formatterConfig?: any }}
|
|
19
|
+
*/
|
|
20
|
+
configs
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new instance of FileDriver.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} channel
|
|
26
|
+
* @param {any} [configs]
|
|
27
|
+
* @return {FileDriver}
|
|
28
|
+
*/
|
|
29
|
+
constructor(channel, configs = {}) {
|
|
30
|
+
const channelConfig = Config.get(`logging.channels.${channel}`)
|
|
31
|
+
|
|
32
|
+
this.configs = FactoryHelper.groupConfigs(configs, channelConfig)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Transport the log.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} message
|
|
39
|
+
* @param {{ filePath?: string, formatter?: any, formatterConfig?: any }} [options]
|
|
40
|
+
* @return {Promise<void>}
|
|
41
|
+
*/
|
|
42
|
+
async transport(message, options = {}) {
|
|
43
|
+
const configs = FactoryHelper.groupConfigs(options, this.configs)
|
|
44
|
+
|
|
45
|
+
message = FormatterFactory.fabricate(configs.formatter).format(
|
|
46
|
+
message,
|
|
47
|
+
configs.formatterConfig,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const messageBuffer = Buffer.from(`${ColorHelper.removeColors(message)}\n`)
|
|
51
|
+
|
|
52
|
+
const file = new File(configs.filePath, messageBuffer)
|
|
53
|
+
const fileExists = await File.exists(configs.filePath)
|
|
54
|
+
|
|
55
|
+
if (!fileExists) {
|
|
56
|
+
return file.load()
|
|
37
57
|
}
|
|
58
|
+
|
|
59
|
+
return file.append(messageBuffer)
|
|
60
|
+
}
|
|
38
61
|
}
|
|
39
|
-
exports.FileDriver = FileDriver;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @athenna/logger
|
|
4
3
|
*
|
|
@@ -7,10 +6,23 @@
|
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
|
|
10
|
+
export class NullDriver {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new instance of NullDriver.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} _channel
|
|
15
|
+
* @param {any} [_configs]
|
|
16
|
+
* @return {NullDriver}
|
|
17
|
+
*/
|
|
18
|
+
constructor(_channel, _configs = {}) {}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Transport the log.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} _message
|
|
24
|
+
* @param {any} [_options]
|
|
25
|
+
* @return {void}
|
|
26
|
+
*/
|
|
27
|
+
transport(_message, _options) {}
|
|
15
28
|
}
|
|
16
|
-
exports.NullDriver = NullDriver;
|