@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.
- package/LICENSE.md +21 -0
- package/README.md +34 -0
- package/index.d.ts +12 -0
- package/index.js +24 -0
- package/package.json +159 -0
- package/src/Contracts/DriverContract.d.ts +11 -0
- package/src/Contracts/DriverContract.js +10 -0
- package/src/Contracts/FormatterContract.d.ts +11 -0
- package/src/Contracts/FormatterContract.js +10 -0
- package/src/Drivers/ConsoleDriver.d.ts +24 -0
- package/src/Drivers/ConsoleDriver.js +32 -0
- package/src/Drivers/DebugDriver.d.ts +25 -0
- package/src/Drivers/DebugDriver.js +33 -0
- package/src/Drivers/FileDriver.d.ts +23 -0
- package/src/Drivers/FileDriver.js +41 -0
- package/src/Exceptions/ChannelNotConfiguredException.d.ts +12 -0
- package/src/Exceptions/ChannelNotConfiguredException.js +19 -0
- package/src/Exceptions/DriverAlreadyExistException.d.ts +12 -0
- package/src/Exceptions/DriverAlreadyExistException.js +19 -0
- package/src/Exceptions/FormatterAlreadyExistException.d.ts +12 -0
- package/src/Exceptions/FormatterAlreadyExistException.js +19 -0
- package/src/Exceptions/NotFoundDriverException.d.ts +12 -0
- package/src/Exceptions/NotFoundDriverException.js +19 -0
- package/src/Exceptions/NotFoundFormatterException.d.ts +12 -0
- package/src/Exceptions/NotFoundFormatterException.js +19 -0
- package/src/Factories/DriverFactory.d.ts +19 -0
- package/src/Factories/DriverFactory.js +59 -0
- package/src/Factories/FormatterFactory.d.ts +18 -0
- package/src/Factories/FormatterFactory.js +45 -0
- package/src/Formatters/ContextFormatter.d.ts +19 -0
- package/src/Formatters/ContextFormatter.js +32 -0
- package/src/Formatters/DebugFormatter.d.ts +20 -0
- package/src/Formatters/DebugFormatter.js +32 -0
- package/src/Formatters/JsonFormatter.d.ts +16 -0
- package/src/Formatters/JsonFormatter.js +20 -0
- package/src/Formatters/LogFormatter.d.ts +18 -0
- package/src/Formatters/LogFormatter.js +33 -0
- package/src/Log.d.ts +18 -0
- package/src/Log.js +79 -0
- package/src/Logger.d.ts +19 -0
- package/src/Logger.js +73 -0
- package/src/Utils/Color.d.ts +37 -0
- package/src/Utils/Color.js +84 -0
- package/src/Utils/getTimestamp.d.ts +9 -0
- package/src/Utils/getTimestamp.js +23 -0
- package/src/Utils/global.d.ts +15 -0
- package/src/Utils/global.js +15 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 The Athenna Framework
|
|
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:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Logger 🔍
|
|
2
|
+
|
|
3
|
+
> The Athenna logging solution. Log in stdout, files and buckets
|
|
4
|
+
|
|
5
|
+
[](https://github.com/athennaio?tab=followers)
|
|
6
|
+
[](https://github.com/athennaio/logger/stargazers/)
|
|
7
|
+
|
|
8
|
+
<p>
|
|
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
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<p>
|
|
13
|
+
<img alt="GitHub language count" src="https://img.shields.io/github/languages/count/athennaio/logger?style=for-the-badge&logo=appveyor">
|
|
14
|
+
|
|
15
|
+
<img alt="Repository size" src="https://img.shields.io/github/repo-size/athennaio/logger?style=for-the-badge&logo=appveyor">
|
|
16
|
+
|
|
17
|
+
<img alt="License" src="https://img.shields.io/badge/license-MIT-brightgreen?style=for-the-badge&logo=appveyor">
|
|
18
|
+
|
|
19
|
+
<img alt="Commitizen" src="https://img.shields.io/badge/commitizen-friendly-brightgreen?style=for-the-badge&logo=appveyor">
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<img src=".github/logo.svg" width="200px" align="right" hspace="30px" vspace="100px">
|
|
23
|
+
|
|
24
|
+
## Links
|
|
25
|
+
|
|
26
|
+
> For project documentation [click here](https://athenna.io). If something is not clear in the documentation please open an issue in the [documentation repository](https://github.com/athennaio/docs)
|
|
27
|
+
|
|
28
|
+
## Contributing
|
|
29
|
+
|
|
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
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
Made with 🖤 by [Athenna Team](https://github.com/AthennaIO) :wave:
|
package/index.d.ts
ADDED
|
@@ -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
|
+
export * from './src/Log';
|
|
10
|
+
export * from './src/Logger';
|
|
11
|
+
export * from './src/Contracts/DriverContract';
|
|
12
|
+
export * from './src/Contracts/FormatterContract';
|
package/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
__exportStar(require("./src/Log"), exports);
|
|
22
|
+
__exportStar(require("./src/Logger"), exports);
|
|
23
|
+
__exportStar(require("./src/Contracts/DriverContract"), exports);
|
|
24
|
+
__exportStar(require("./src/Contracts/FormatterContract"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@athenna/logger",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "João Lenon <lenon@athenna.io>",
|
|
7
|
+
"repository": "https://github.com/AthennaIO/Logger.git",
|
|
8
|
+
"bugs": "https://github.com/AthennaIO/Logger/issues",
|
|
9
|
+
"homepage": "https://github.com/AthennaIO/Logger#readme",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc --project tsconfig.json && tscpaths -p tsconfig.json -s . -o .",
|
|
12
|
+
"test": "npm run lint:fix && cross-env NODE_TS=true cross-env NODE_ENV=testing jest --verbose",
|
|
13
|
+
"test:debug": "npm run lint:fix && cross-env NODE_TS=true cross-env NODE_ENV=testing cross-env DEBUG=api:* jest --verbose",
|
|
14
|
+
"lint:fix": "eslint \"{src,tests}/**/*.ts\" --fix"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"nodejs",
|
|
18
|
+
"athenna",
|
|
19
|
+
"typescript"
|
|
20
|
+
],
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/jest": "27.0.1",
|
|
23
|
+
"@types/node": "14.17.0",
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "4.31.0",
|
|
25
|
+
"@typescript-eslint/parser": "4.31.0",
|
|
26
|
+
"commitizen": "4.2.4",
|
|
27
|
+
"cross-env": "7.0.3",
|
|
28
|
+
"cz-conventional-changelog": "3.3.0",
|
|
29
|
+
"eslint": "7.32.0",
|
|
30
|
+
"eslint-config-prettier": "8.3.0",
|
|
31
|
+
"eslint-config-standard": "16.0.3",
|
|
32
|
+
"eslint-import-resolver-typescript": "2.4.0",
|
|
33
|
+
"eslint-plugin-import": "2.24.2",
|
|
34
|
+
"eslint-plugin-node": "11.1.0",
|
|
35
|
+
"eslint-plugin-prettier": "4.0.0",
|
|
36
|
+
"eslint-plugin-promise": "5.1.0",
|
|
37
|
+
"eslint-plugin-standard": "5.0.0",
|
|
38
|
+
"husky": "3.0.9",
|
|
39
|
+
"jest": "27.1.0",
|
|
40
|
+
"lint-staged": "9.4.3",
|
|
41
|
+
"prettier": "2.0.5",
|
|
42
|
+
"ts-jest": "27.0.5",
|
|
43
|
+
"ts-loader": "9.2.3",
|
|
44
|
+
"ts-node": "10.0.0",
|
|
45
|
+
"tsconfig-paths": "3.9.0",
|
|
46
|
+
"typescript": "4.3.5"
|
|
47
|
+
},
|
|
48
|
+
"lint-staged": {
|
|
49
|
+
"*.js": [
|
|
50
|
+
"eslint --fix",
|
|
51
|
+
"git add"
|
|
52
|
+
],
|
|
53
|
+
"*.json": [
|
|
54
|
+
"prettier --write",
|
|
55
|
+
"git add"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"husky": {
|
|
59
|
+
"hooks": {
|
|
60
|
+
"pre-commit": "lint-staged",
|
|
61
|
+
"prepare-commit-msg": "exec < /dev/tty && git cz --hook || true"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
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
|
+
"prettier": {
|
|
83
|
+
"singleQuote": true,
|
|
84
|
+
"trailingComma": "all",
|
|
85
|
+
"arrowParens": "avoid",
|
|
86
|
+
"endOfLine": "lf",
|
|
87
|
+
"semi": false,
|
|
88
|
+
"printWidth": 80,
|
|
89
|
+
"overrides": [
|
|
90
|
+
{
|
|
91
|
+
"files": "tests/**/*",
|
|
92
|
+
"options": {
|
|
93
|
+
"printWidth": 120
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
"eslintConfig": {
|
|
99
|
+
"env": {
|
|
100
|
+
"es6": true,
|
|
101
|
+
"node": true
|
|
102
|
+
},
|
|
103
|
+
"extends": [
|
|
104
|
+
"standard",
|
|
105
|
+
"plugin:@typescript-eslint/recommended",
|
|
106
|
+
"plugin:prettier/recommended"
|
|
107
|
+
],
|
|
108
|
+
"globals": {
|
|
109
|
+
"Atomics": "readonly",
|
|
110
|
+
"SharedArrayBuffer": "readonly"
|
|
111
|
+
},
|
|
112
|
+
"parser": "@typescript-eslint/parser",
|
|
113
|
+
"parserOptions": {
|
|
114
|
+
"ecmaVersion": 2018,
|
|
115
|
+
"sourceType": "module"
|
|
116
|
+
},
|
|
117
|
+
"plugins": [
|
|
118
|
+
"@typescript-eslint",
|
|
119
|
+
"prettier"
|
|
120
|
+
],
|
|
121
|
+
"rules": {
|
|
122
|
+
"dot-notation": "off",
|
|
123
|
+
"camelcase": "off",
|
|
124
|
+
"no-undef": "off",
|
|
125
|
+
"@typescript-eslint/no-var-requires": "off",
|
|
126
|
+
"no-useless-constructor": "off",
|
|
127
|
+
"@typescript-eslint/no-useless-constructor": "off",
|
|
128
|
+
"@typescript-eslint/camelcase": "off",
|
|
129
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
130
|
+
"@typescript-eslint/interface-name-prefix": "off",
|
|
131
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
132
|
+
"prettier/prettier": "error",
|
|
133
|
+
"@typescript-eslint/no-unused-vars": [
|
|
134
|
+
"error",
|
|
135
|
+
{
|
|
136
|
+
"argsIgnorePattern": "_"
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"files": [
|
|
142
|
+
"src/*.js",
|
|
143
|
+
"src/*.d.ts",
|
|
144
|
+
"src/**/*.js",
|
|
145
|
+
"src/**/*.d.ts",
|
|
146
|
+
"*.js",
|
|
147
|
+
"*.d.ts"
|
|
148
|
+
],
|
|
149
|
+
"config": {
|
|
150
|
+
"commitizen": {
|
|
151
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"dependencies": {
|
|
155
|
+
"@secjs/utils": "1.8.0",
|
|
156
|
+
"reflect-metadata": "0.1.13",
|
|
157
|
+
"tscpaths": "0.0.9"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 interface DriverContract {
|
|
10
|
+
transport(message: string, options?: any): void | Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 });
|
|
@@ -0,0 +1,11 @@
|
|
|
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 interface FormatterContract {
|
|
10
|
+
format(message: any, options?: any): any;
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 });
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { Color } from '../Utils/Color';
|
|
10
|
+
import { DriverContract } from '../Contracts/DriverContract';
|
|
11
|
+
export interface ConsoleDriverOpts {
|
|
12
|
+
color: Color;
|
|
13
|
+
level: string;
|
|
14
|
+
context: string;
|
|
15
|
+
streamType: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class ConsoleDriver implements DriverContract {
|
|
18
|
+
private readonly _level;
|
|
19
|
+
private readonly _context;
|
|
20
|
+
private readonly _formatter;
|
|
21
|
+
private readonly _streamType;
|
|
22
|
+
constructor(channel: string);
|
|
23
|
+
transport(message: string, options?: ConsoleDriverOpts): void;
|
|
24
|
+
}
|
|
@@ -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.ConsoleDriver = void 0;
|
|
12
|
+
const utils_1 = require("@secjs/utils");
|
|
13
|
+
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
14
|
+
class ConsoleDriver {
|
|
15
|
+
constructor(channel) {
|
|
16
|
+
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
17
|
+
this._level = channelConfig.level || 'INFO';
|
|
18
|
+
this._context = channelConfig.context || 'ConsoleDriver';
|
|
19
|
+
this._formatter = channelConfig.formatter || 'context';
|
|
20
|
+
this._streamType = channelConfig.streamType || 'stdout';
|
|
21
|
+
}
|
|
22
|
+
transport(message, options) {
|
|
23
|
+
options = Object.assign({}, {
|
|
24
|
+
level: this._level,
|
|
25
|
+
context: this._context,
|
|
26
|
+
streamType: this._streamType,
|
|
27
|
+
}, options);
|
|
28
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(this._formatter).format(message, options);
|
|
29
|
+
process[this._streamType].write(`${message}\n`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ConsoleDriver = ConsoleDriver;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { Color } from '../Utils/Color';
|
|
10
|
+
import { DriverContract } from '../Contracts/DriverContract';
|
|
11
|
+
export interface DebugDriverOpts {
|
|
12
|
+
color: Color;
|
|
13
|
+
level: string;
|
|
14
|
+
context: string;
|
|
15
|
+
formatter: string;
|
|
16
|
+
namespace: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class DebugDriver implements DriverContract {
|
|
19
|
+
private readonly _level;
|
|
20
|
+
private readonly _context;
|
|
21
|
+
private readonly _formatter;
|
|
22
|
+
private readonly _namespace;
|
|
23
|
+
constructor(channel: string);
|
|
24
|
+
transport(message: string, options?: DebugDriverOpts): void;
|
|
25
|
+
}
|
|
@@ -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.DebugDriver = void 0;
|
|
12
|
+
const debug_1 = require("debug");
|
|
13
|
+
const utils_1 = require("@secjs/utils");
|
|
14
|
+
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
15
|
+
class DebugDriver {
|
|
16
|
+
constructor(channel) {
|
|
17
|
+
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
18
|
+
this._level = channelConfig.level || 'DEBUG';
|
|
19
|
+
this._context = channelConfig.context || 'DebugDriver';
|
|
20
|
+
this._formatter = channelConfig.formatter || 'context';
|
|
21
|
+
this._namespace = channelConfig.namespace || 'api:main';
|
|
22
|
+
}
|
|
23
|
+
transport(message, options) {
|
|
24
|
+
options = Object.assign({}, {
|
|
25
|
+
level: this._level,
|
|
26
|
+
context: this._context,
|
|
27
|
+
namespace: this._namespace,
|
|
28
|
+
}, options);
|
|
29
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(this._formatter).format(message, options);
|
|
30
|
+
debug_1.debug(options.namespace)(message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.DebugDriver = DebugDriver;
|
|
@@ -0,0 +1,23 @@
|
|
|
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 FileDriverOpts {
|
|
11
|
+
level: string;
|
|
12
|
+
context: string;
|
|
13
|
+
formatter: string;
|
|
14
|
+
filePath: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class FileDriver implements DriverContract {
|
|
17
|
+
private readonly _level;
|
|
18
|
+
private readonly _context;
|
|
19
|
+
private readonly _filePath;
|
|
20
|
+
private readonly _formatter;
|
|
21
|
+
constructor(channel: string);
|
|
22
|
+
transport(message: string, options?: FileDriverOpts): Promise<void>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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.FileDriver = void 0;
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const Color_1 = require("../Utils/Color");
|
|
14
|
+
const utils_1 = require("@secjs/utils");
|
|
15
|
+
const fs_1 = require("fs");
|
|
16
|
+
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
17
|
+
class FileDriver {
|
|
18
|
+
constructor(channel) {
|
|
19
|
+
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
20
|
+
this._level = channelConfig.level || 'INFO';
|
|
21
|
+
this._context = channelConfig.context || 'FileDriver';
|
|
22
|
+
this._filePath = channelConfig.filePath || utils_1.Path.noBuild().logs('secjs.log');
|
|
23
|
+
this._formatter = channelConfig.formatter || 'log';
|
|
24
|
+
}
|
|
25
|
+
async transport(message, options) {
|
|
26
|
+
options = Object.assign({}, { level: this._level, context: this._context, filePath: this._filePath }, options);
|
|
27
|
+
const filePath = options.filePath;
|
|
28
|
+
const { dir } = path_1.parse(filePath);
|
|
29
|
+
if (!fs_1.existsSync(dir)) {
|
|
30
|
+
fs_1.mkdirSync(dir, { recursive: true });
|
|
31
|
+
}
|
|
32
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(this._formatter).format(message, options);
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const stream = fs_1.createWriteStream(filePath, { flags: 'a' });
|
|
35
|
+
stream.write(`${Color_1.Color.removeColors(message)}` + '\n');
|
|
36
|
+
stream.on('error', reject);
|
|
37
|
+
stream.end(resolve);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.FileDriver = FileDriver;
|
|
@@ -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 ChannelNotConfiguredException extends Exception {
|
|
11
|
+
constructor(channelName: string);
|
|
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.ChannelNotConfiguredException = void 0;
|
|
12
|
+
const utils_1 = require("@secjs/utils");
|
|
13
|
+
class ChannelNotConfiguredException extends utils_1.Exception {
|
|
14
|
+
constructor(channelName) {
|
|
15
|
+
const content = `Channel ${channelName} is not configured inside logging.channels object from config/logging file`;
|
|
16
|
+
super(content, 500, 'NOT_CONFIGURED_ERROR', `Implement the channel in the logging.channels`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ChannelNotConfiguredException = ChannelNotConfiguredException;
|
|
@@ -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 DriverAlreadyExistException extends Exception {
|
|
11
|
+
constructor(driverName: string);
|
|
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.DriverAlreadyExistException = void 0;
|
|
12
|
+
const utils_1 = require("@secjs/utils");
|
|
13
|
+
class DriverAlreadyExistException extends utils_1.Exception {
|
|
14
|
+
constructor(driverName) {
|
|
15
|
+
const content = `The driver ${driverName} already exists`;
|
|
16
|
+
super(content, 500, 'ALREADY_EXIST_ERROR', `The name ${driverName} is already in use. Try using a different name for your driver`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DriverAlreadyExistException = DriverAlreadyExistException;
|
|
@@ -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 FormatterAlreadyExistException extends Exception {
|
|
11
|
+
constructor(formatterName: string);
|
|
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.FormatterAlreadyExistException = void 0;
|
|
12
|
+
const utils_1 = require("@secjs/utils");
|
|
13
|
+
class FormatterAlreadyExistException extends utils_1.Exception {
|
|
14
|
+
constructor(formatterName) {
|
|
15
|
+
const content = `The formatter ${formatterName} already exists`;
|
|
16
|
+
super(content, 500, 'ALREADY_EXIST_ERROR', `The name ${formatterName} is already in use. Try using a different name for your formatter`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.FormatterAlreadyExistException = FormatterAlreadyExistException;
|
|
@@ -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 NotFoundDriverException extends Exception {
|
|
11
|
+
constructor(driverName: string);
|
|
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.NotFoundDriverException = void 0;
|
|
12
|
+
const utils_1 = require("@secjs/utils");
|
|
13
|
+
class NotFoundDriverException extends utils_1.Exception {
|
|
14
|
+
constructor(driverName) {
|
|
15
|
+
const content = `The driver ${driverName} has not been found`;
|
|
16
|
+
super(content, 500, 'NOT_FOUND_ERROR', `Look into your config/logger file if this driver is implemented by logger. Or create this driver implementation using Logger.buildDriver method`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.NotFoundDriverException = NotFoundDriverException;
|
|
@@ -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 NotFoundFormatterException extends Exception {
|
|
11
|
+
constructor(formatterName: string);
|
|
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.NotFoundFormatterException = void 0;
|
|
12
|
+
const utils_1 = require("@secjs/utils");
|
|
13
|
+
class NotFoundFormatterException extends utils_1.Exception {
|
|
14
|
+
constructor(formatterName) {
|
|
15
|
+
const content = `The driver ${formatterName} has not been found`;
|
|
16
|
+
super(content, 500, 'NOT_FOUND_ERROR', `Look into your config/logger file if this formatter is implemented by logger. Or create this formatter implementation using Logger.buildFormatter method`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.NotFoundFormatterException = NotFoundFormatterException;
|