@ricdotnet/logger 0.0.3 → 0.0.6
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/Logs/29-8-2022-error.log +24 -0
- package/Logs/29-8-2022-info.log +27 -0
- package/Logs/29-8-2022-warn.log +33 -0
- package/package.json +11 -2
- package/tsconfig.json +5 -2
- package/Tests/Logger.spec.ts +0 -44
- package/dist/Tests/Logger.spec.d.ts +0 -1
- package/dist/Tests/Logger.spec.js +0 -37
- package/dist/Tests/Logger.spec.js.map +0 -1
- package/dist/jest.config.d.ts +0 -2
- package/dist/jest.config.js +0 -11
- package/dist/jest.config.js.map +0 -1
- package/dist/src/Configuration.d.ts +0 -0
- package/dist/src/Configuration.js +0 -1
- package/dist/src/Configuration.js.map +0 -1
- package/dist/src/Constants.d.ts +0 -25
- package/dist/src/Constants.js +0 -30
- package/dist/src/Constants.js.map +0 -1
- package/dist/src/Logger.d.ts +0 -8
- package/dist/src/Logger.js +0 -51
- package/dist/src/Logger.js.map +0 -1
- package/jest.config.js +0 -11
- package/src/Configuration.ts +0 -0
- package/src/Constants.ts +0 -27
- package/src/Logger.ts +0 -65
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Log Time: 11:13
|
|
2
|
+
hello world
|
|
3
|
+
|
|
4
|
+
Log Time: 11:13
|
|
5
|
+
hello world
|
|
6
|
+
|
|
7
|
+
Log Time: 11:14
|
|
8
|
+
hello world
|
|
9
|
+
|
|
10
|
+
Log Time: 11:15
|
|
11
|
+
hello world
|
|
12
|
+
|
|
13
|
+
Log Time: 11:18
|
|
14
|
+
hello world
|
|
15
|
+
|
|
16
|
+
Log Time: 11:19
|
|
17
|
+
hello world
|
|
18
|
+
|
|
19
|
+
Log Time: 11:19
|
|
20
|
+
hello world
|
|
21
|
+
|
|
22
|
+
Log Time: 11:20
|
|
23
|
+
hello world
|
|
24
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Log Time: 11:13
|
|
2
|
+
hello world
|
|
3
|
+
|
|
4
|
+
Log Time: 11:13
|
|
5
|
+
Logs folder generated.
|
|
6
|
+
|
|
7
|
+
Log Time: 11:13
|
|
8
|
+
hello world
|
|
9
|
+
|
|
10
|
+
Log Time: 11:14
|
|
11
|
+
hello world
|
|
12
|
+
|
|
13
|
+
Log Time: 11:15
|
|
14
|
+
hello world
|
|
15
|
+
|
|
16
|
+
Log Time: 11:18
|
|
17
|
+
hello world
|
|
18
|
+
|
|
19
|
+
Log Time: 11:19
|
|
20
|
+
hello world
|
|
21
|
+
|
|
22
|
+
Log Time: 11:19
|
|
23
|
+
hello world
|
|
24
|
+
|
|
25
|
+
Log Time: 11:20
|
|
26
|
+
hello world
|
|
27
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Log Time: 11:13
|
|
2
|
+
hello world
|
|
3
|
+
|
|
4
|
+
Log Time: 11:13
|
|
5
|
+
hello world
|
|
6
|
+
|
|
7
|
+
Log Time: 11:14
|
|
8
|
+
hello world
|
|
9
|
+
|
|
10
|
+
Log Time: 11:15
|
|
11
|
+
hello world
|
|
12
|
+
|
|
13
|
+
Log Time: 11:17
|
|
14
|
+
hello world
|
|
15
|
+
|
|
16
|
+
Log Time: 11:17
|
|
17
|
+
hello world
|
|
18
|
+
|
|
19
|
+
Log Time: 11:17
|
|
20
|
+
hello world
|
|
21
|
+
|
|
22
|
+
Log Time: 11:18
|
|
23
|
+
hello world
|
|
24
|
+
|
|
25
|
+
Log Time: 11:19
|
|
26
|
+
hello world
|
|
27
|
+
|
|
28
|
+
Log Time: 11:19
|
|
29
|
+
hello world
|
|
30
|
+
|
|
31
|
+
Log Time: 11:20
|
|
32
|
+
hello world
|
|
33
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricdotnet/logger",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "A logger utility for my personal projects.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,16 @@
|
|
|
9
9
|
"build": "rm -rf ./dist && tsc",
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
11
|
},
|
|
12
|
-
"keywords": [
|
|
12
|
+
"keywords": [
|
|
13
|
+
"logger",
|
|
14
|
+
"logs",
|
|
15
|
+
"console.log",
|
|
16
|
+
"log",
|
|
17
|
+
"logjs",
|
|
18
|
+
"logts",
|
|
19
|
+
"logger4ts",
|
|
20
|
+
"logger4js"
|
|
21
|
+
],
|
|
13
22
|
"author": "ricdotnet <me@rrocha.uk> https://ricr.dev",
|
|
14
23
|
"repository": "https://github.com/ricdotnet/logger-utility",
|
|
15
24
|
"license": "ISC",
|
package/tsconfig.json
CHANGED
package/Tests/Logger.spec.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Logger } from '../src/Logger';
|
|
2
|
-
import { Constants } from '../src/Constants';
|
|
3
|
-
|
|
4
|
-
const loggerSpy = {
|
|
5
|
-
info : jest.spyOn(Logger, 'info'),
|
|
6
|
-
warn : jest.spyOn(Logger, 'warn'),
|
|
7
|
-
error: jest.spyOn(Logger, 'error')
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const consoleSpy = {
|
|
11
|
-
info : jest.spyOn(console, 'log'),
|
|
12
|
-
warn : jest.spyOn(console, 'warn'),
|
|
13
|
-
error: jest.spyOn(console, 'error'),
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
describe('Logger test', () => {
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
loggerSpy.info.mockClear();
|
|
20
|
-
loggerSpy.warn.mockClear();
|
|
21
|
-
loggerSpy.error.mockClear();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('can log an info and check the output', () => {
|
|
25
|
-
Logger.info('hello world');
|
|
26
|
-
|
|
27
|
-
expect(loggerSpy.info).toHaveBeenCalledWith('hello world');
|
|
28
|
-
expect(consoleSpy.info).toHaveBeenCalledWith(`${Constants.TEXT_BLUE}[INFO]: hello world`);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('can log a warning', () => {
|
|
32
|
-
Logger.warn('hello world');
|
|
33
|
-
|
|
34
|
-
expect(loggerSpy.warn).toHaveBeenCalledWith('hello world');
|
|
35
|
-
expect(consoleSpy.warn).toHaveBeenCalledWith(`${Constants.TEXT_YELLOW}[WARN]: hello world`);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('can log an error', () => {
|
|
39
|
-
Logger.error('hello world');
|
|
40
|
-
|
|
41
|
-
expect(loggerSpy.error).toHaveBeenCalledWith('hello world');
|
|
42
|
-
expect(consoleSpy.error).toHaveBeenCalledWith(`${Constants.TEXT_RED}[ERROR]: hello world`);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const Logger_1 = require("../src/Logger");
|
|
4
|
-
const Constants_1 = require("../src/Constants");
|
|
5
|
-
const loggerSpy = {
|
|
6
|
-
info: jest.spyOn(Logger_1.Logger, 'info'),
|
|
7
|
-
warn: jest.spyOn(Logger_1.Logger, 'warn'),
|
|
8
|
-
error: jest.spyOn(Logger_1.Logger, 'error')
|
|
9
|
-
};
|
|
10
|
-
const consoleSpy = {
|
|
11
|
-
info: jest.spyOn(console, 'log'),
|
|
12
|
-
warn: jest.spyOn(console, 'warn'),
|
|
13
|
-
error: jest.spyOn(console, 'error'),
|
|
14
|
-
};
|
|
15
|
-
describe('Logger test', () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
loggerSpy.info.mockClear();
|
|
18
|
-
loggerSpy.warn.mockClear();
|
|
19
|
-
loggerSpy.error.mockClear();
|
|
20
|
-
});
|
|
21
|
-
it('can log an info and check the output', () => {
|
|
22
|
-
Logger_1.Logger.info('hello world');
|
|
23
|
-
expect(loggerSpy.info).toHaveBeenCalledWith('hello world');
|
|
24
|
-
expect(consoleSpy.info).toHaveBeenCalledWith(`${Constants_1.Constants.TEXT_BLUE}[INFO]: hello world`);
|
|
25
|
-
});
|
|
26
|
-
it('can log a warning', () => {
|
|
27
|
-
Logger_1.Logger.warn('hello world');
|
|
28
|
-
expect(loggerSpy.warn).toHaveBeenCalledWith('hello world');
|
|
29
|
-
expect(consoleSpy.warn).toHaveBeenCalledWith(`${Constants_1.Constants.TEXT_YELLOW}[WARN]: hello world`);
|
|
30
|
-
});
|
|
31
|
-
it('can log an error', () => {
|
|
32
|
-
Logger_1.Logger.error('hello world');
|
|
33
|
-
expect(loggerSpy.error).toHaveBeenCalledWith('hello world');
|
|
34
|
-
expect(consoleSpy.error).toHaveBeenCalledWith(`${Constants_1.Constants.TEXT_RED}[ERROR]: hello world`);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
//# sourceMappingURL=Logger.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.spec.js","sourceRoot":"./","sources":["Tests/Logger.spec.ts"],"names":[],"mappings":";;AAAA,0CAAuC;AACvC,gDAA6C;AAE7C,MAAM,SAAS,GAAG;IAChB,IAAI,EAAG,IAAI,CAAC,KAAK,CAAC,eAAM,EAAE,MAAM,CAAC;IACjC,IAAI,EAAG,IAAI,CAAC,KAAK,CAAC,eAAM,EAAE,MAAM,CAAC;IACjC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,eAAM,EAAE,OAAO,CAAC;CACnC,CAAC;AAEF,MAAM,UAAU,GAAG;IACjB,IAAI,EAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC;IACjC,IAAI,EAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC;IAClC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,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.config.d.ts
DELETED
package/dist/jest.config.js
DELETED
package/dist/jest.config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jest.config.js","sourceRoot":"./","sources":["jest.config.js"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,GAAG;IACf,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,MAAM;IACvB,KAAK,EAAE;QACL,WAAW;KACZ;IACD,iBAAiB,EAAE;QACjB,cAAc;KACf;CACF,CAAC"}
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=Configuration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Configuration.js","sourceRoot":"./","sources":["src/Configuration.ts"],"names":[],"mappings":""}
|
package/dist/src/Constants.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export declare enum Constants {
|
|
2
|
-
Reset = "\u001B[0m",
|
|
3
|
-
BRIGHT = "\u001B[1m",
|
|
4
|
-
Dim = "\u001B[2m",
|
|
5
|
-
Underscore = "\u001B[4m",
|
|
6
|
-
Blink = "\u001B[5m",
|
|
7
|
-
Reverse = "\u001B[7m",
|
|
8
|
-
Hidden = "\u001B[8m",
|
|
9
|
-
TEXT_BLACK = "\u001B[30m",
|
|
10
|
-
TEXT_RED = "\u001B[31m",
|
|
11
|
-
TEXT_GREEN = "\u001B[32m",
|
|
12
|
-
TEXT_YELLOW = "\u001B[33m",
|
|
13
|
-
TEXT_BLUE = "\u001B[34m",
|
|
14
|
-
TEXT_MAGENTA = "\u001B[35m",
|
|
15
|
-
TEXT_CYAN = "\u001B[36m",
|
|
16
|
-
TEXT_WHITE = "\u001B[37m",
|
|
17
|
-
BG_BLACK = "\u001B[40m",
|
|
18
|
-
BG_RED = "\u001B[41m",
|
|
19
|
-
BG_GREEN = "\u001B[42m",
|
|
20
|
-
BG_YELLOW = "\u001B[43m",
|
|
21
|
-
BG_BLUE = "\u001B[44m",
|
|
22
|
-
BG_MAGENTA = "\u001B[45m",
|
|
23
|
-
BG_CYAN = "\u001B[46m",
|
|
24
|
-
BG_WHITE = "\u001B[47m"
|
|
25
|
-
}
|
package/dist/src/Constants.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Constants = void 0;
|
|
4
|
-
var Constants;
|
|
5
|
-
(function (Constants) {
|
|
6
|
-
Constants["Reset"] = "\u001B[0m";
|
|
7
|
-
Constants["BRIGHT"] = "\u001B[1m";
|
|
8
|
-
Constants["Dim"] = "\u001B[2m";
|
|
9
|
-
Constants["Underscore"] = "\u001B[4m";
|
|
10
|
-
Constants["Blink"] = "\u001B[5m";
|
|
11
|
-
Constants["Reverse"] = "\u001B[7m";
|
|
12
|
-
Constants["Hidden"] = "\u001B[8m";
|
|
13
|
-
Constants["TEXT_BLACK"] = "\u001B[30m";
|
|
14
|
-
Constants["TEXT_RED"] = "\u001B[31m";
|
|
15
|
-
Constants["TEXT_GREEN"] = "\u001B[32m";
|
|
16
|
-
Constants["TEXT_YELLOW"] = "\u001B[33m";
|
|
17
|
-
Constants["TEXT_BLUE"] = "\u001B[34m";
|
|
18
|
-
Constants["TEXT_MAGENTA"] = "\u001B[35m";
|
|
19
|
-
Constants["TEXT_CYAN"] = "\u001B[36m";
|
|
20
|
-
Constants["TEXT_WHITE"] = "\u001B[37m";
|
|
21
|
-
Constants["BG_BLACK"] = "\u001B[40m";
|
|
22
|
-
Constants["BG_RED"] = "\u001B[41m";
|
|
23
|
-
Constants["BG_GREEN"] = "\u001B[42m";
|
|
24
|
-
Constants["BG_YELLOW"] = "\u001B[43m";
|
|
25
|
-
Constants["BG_BLUE"] = "\u001B[44m";
|
|
26
|
-
Constants["BG_MAGENTA"] = "\u001B[45m";
|
|
27
|
-
Constants["BG_CYAN"] = "\u001B[46m";
|
|
28
|
-
Constants["BG_WHITE"] = "\u001B[47m";
|
|
29
|
-
})(Constants = exports.Constants || (exports.Constants = {}));
|
|
30
|
-
//# sourceMappingURL=Constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.js","sourceRoot":"./","sources":["src/Constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,SA0BX;AA1BD,WAAY,SAAS;IACnB,gCAAwB,CAAA;IACxB,iCAAwB,CAAA;IACxB,8BAAwB,CAAA;IACxB,qCAAwB,CAAA;IACxB,gCAAwB,CAAA;IACxB,kCAAwB,CAAA;IACxB,iCAAwB,CAAA;IAExB,sCAAyB,CAAA;IACzB,oCAAyB,CAAA;IACzB,sCAAyB,CAAA;IACzB,uCAAyB,CAAA;IACzB,qCAAyB,CAAA;IACzB,wCAAyB,CAAA;IACzB,qCAAyB,CAAA;IACzB,sCAAyB,CAAA;IAEzB,oCAAyB,CAAA;IACzB,kCAAyB,CAAA;IACzB,oCAAyB,CAAA;IACzB,qCAAyB,CAAA;IACzB,mCAAyB,CAAA;IACzB,sCAAyB,CAAA;IACzB,mCAAyB,CAAA;IACzB,oCAAyB,CAAA;AAC3B,CAAC,EA1BW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QA0BpB"}
|
package/dist/src/Logger.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare class Logger {
|
|
2
|
-
static LOG_DIR: string;
|
|
3
|
-
static checkLogDir(): Promise<void>;
|
|
4
|
-
static info(message: any): Promise<void>;
|
|
5
|
-
static warn(message: any): Promise<void>;
|
|
6
|
-
static error(message: any): Promise<void>;
|
|
7
|
-
static writeToFile(message: any, type: string): Promise<void>;
|
|
8
|
-
}
|
package/dist/src/Logger.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logger = void 0;
|
|
4
|
-
const fs = require("fs/promises");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const Constants_1 = require("./Constants");
|
|
7
|
-
class Logger {
|
|
8
|
-
static LOG_DIR = './Logs';
|
|
9
|
-
static async checkLogDir() {
|
|
10
|
-
const dirs = await fs.readdir('./');
|
|
11
|
-
if (!dirs.includes(this.LOG_DIR.split('/')[1])) {
|
|
12
|
-
await fs.mkdir(this.LOG_DIR);
|
|
13
|
-
return this.info('Logs folder generated.');
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
static async info(message) {
|
|
17
|
-
await this.writeToFile(message, 'info');
|
|
18
|
-
console.log(`${Constants_1.Constants.TEXT_BLUE}[INFO]: ${message}`);
|
|
19
|
-
}
|
|
20
|
-
static async warn(message) {
|
|
21
|
-
await this.writeToFile(message, 'warn');
|
|
22
|
-
console.warn(`${Constants_1.Constants.TEXT_YELLOW}[WARN]: ${message}`);
|
|
23
|
-
}
|
|
24
|
-
static async error(message) {
|
|
25
|
-
await this.writeToFile(message, 'error');
|
|
26
|
-
console.error(`${Constants_1.Constants.TEXT_RED}[ERROR]: ${message}`);
|
|
27
|
-
}
|
|
28
|
-
static async writeToFile(message, type) {
|
|
29
|
-
const DAY = new Date().getDate();
|
|
30
|
-
const MONTH = new Date().getMonth() + 1;
|
|
31
|
-
const YEAR = new Date().getFullYear();
|
|
32
|
-
const HOURS = new Date().getHours();
|
|
33
|
-
const MINUTES = new Date().getMinutes();
|
|
34
|
-
const FULL_DATE = [DAY, MONTH, YEAR].join('-');
|
|
35
|
-
const FULL_TIME = [HOURS, MINUTES].join(':');
|
|
36
|
-
let logFile;
|
|
37
|
-
try {
|
|
38
|
-
logFile = await fs.readFile(path.join(this.LOG_DIR, `${FULL_DATE}-${type}.log`));
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
}
|
|
42
|
-
if (!logFile) {
|
|
43
|
-
const data = 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
|
|
44
|
-
return await fs.writeFile(path.join(this.LOG_DIR, `${FULL_DATE}-${type}.log`), data);
|
|
45
|
-
}
|
|
46
|
-
const data = logFile + 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
|
|
47
|
-
return await fs.writeFile(path.join(this.LOG_DIR, `${FULL_DATE}-${type}.log`), data);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.Logger = Logger;
|
|
51
|
-
//# sourceMappingURL=Logger.js.map
|
package/dist/src/Logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"./","sources":["src/Logger.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAClC,6BAA6B;AAC7B,2CAAwC;AAMxC,MAAa,MAAM;IAEjB,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC;IAE1B,MAAM,CAAC,KAAK,CAAC,WAAW;QACtB,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACpC,IAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAG;YAChD,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;SAC5C;IAGH,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAY;QAC5B,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,GAAG,qBAAS,CAAC,SAAS,WAAW,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAY;QAC5B,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,GAAG,qBAAS,CAAC,WAAW,WAAW,OAAO,EAAE,CAAC,CAAC;I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,OAAO,EAAE,GAAG,SAAS,IAAI,IAAI,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;SACtF;QAED,MAAM,IAAI,GAAG,OAAO,GAAG,YAAY,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC;QAC1E,OAAO,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,SAAS,IAAI,IAAI,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IACvF,CAAC;;AAtDH,wBAwDC"}
|
package/jest.config.js
DELETED
package/src/Configuration.ts
DELETED
|
File without changes
|
package/src/Constants.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export enum Constants {
|
|
2
|
-
Reset = '\x1b[0m',
|
|
3
|
-
BRIGHT = '\x1b[1m',
|
|
4
|
-
Dim = '\x1b[2m',
|
|
5
|
-
Underscore = '\x1b[4m',
|
|
6
|
-
Blink = '\x1b[5m',
|
|
7
|
-
Reverse = '\x1b[7m',
|
|
8
|
-
Hidden = '\x1b[8m',
|
|
9
|
-
|
|
10
|
-
TEXT_BLACK = '\x1b[30m',
|
|
11
|
-
TEXT_RED = '\x1b[31m',
|
|
12
|
-
TEXT_GREEN = '\x1b[32m',
|
|
13
|
-
TEXT_YELLOW = '\x1b[33m',
|
|
14
|
-
TEXT_BLUE = '\x1b[34m',
|
|
15
|
-
TEXT_MAGENTA = '\x1b[35m',
|
|
16
|
-
TEXT_CYAN = '\x1b[36m',
|
|
17
|
-
TEXT_WHITE = '\x1b[37m',
|
|
18
|
-
|
|
19
|
-
BG_BLACK = '\x1b[40m',
|
|
20
|
-
BG_RED = '\x1b[41m',
|
|
21
|
-
BG_GREEN = '\x1b[42m',
|
|
22
|
-
BG_YELLOW = '\x1b[43m',
|
|
23
|
-
BG_BLUE = '\x1b[44m',
|
|
24
|
-
BG_MAGENTA = '\x1b[45m',
|
|
25
|
-
BG_CYAN = '\x1b[46m',
|
|
26
|
-
BG_WHITE = '\x1b[47m',
|
|
27
|
-
}
|
package/src/Logger.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs/promises';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
import { Constants } from './Constants';
|
|
4
|
-
|
|
5
|
-
// some places use any just because I do not want to deal with multiple types of data...
|
|
6
|
-
// I guess generics would be cool here but eh
|
|
7
|
-
// TODO: Multiple log folders for [info, warn, error]
|
|
8
|
-
|
|
9
|
-
export class Logger {
|
|
10
|
-
|
|
11
|
-
static LOG_DIR = './Logs';
|
|
12
|
-
|
|
13
|
-
static async checkLogDir() {
|
|
14
|
-
const dirs = await fs.readdir('./');
|
|
15
|
-
if ( !dirs.includes(this.LOG_DIR.split('/')[1]) ) {
|
|
16
|
-
await fs.mkdir(this.LOG_DIR);
|
|
17
|
-
return this.info('Logs folder generated.');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// return this.info('Logs folder already exists... The logger will write inside it.');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static async info(message: any) {
|
|
24
|
-
await this.writeToFile(message, 'info');
|
|
25
|
-
console.log(`${Constants.TEXT_BLUE}[INFO]: ${message}`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static async warn(message: any) {
|
|
29
|
-
await this.writeToFile(message, 'warn');
|
|
30
|
-
console.warn(`${Constants.TEXT_YELLOW}[WARN]: ${message}`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static async error(message: any) {
|
|
34
|
-
await this.writeToFile(message, 'error');
|
|
35
|
-
console.error(`${Constants.TEXT_RED}[ERROR]: ${message}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static async writeToFile(message: any, type: string) {
|
|
39
|
-
const DAY: number = new Date().getDate();
|
|
40
|
-
const MONTH: number = new Date().getMonth() + 1; // +1 because it goes 0-11
|
|
41
|
-
const YEAR: number = new Date().getFullYear();
|
|
42
|
-
const HOURS: number = new Date().getHours();
|
|
43
|
-
const MINUTES: number = new Date().getMinutes();
|
|
44
|
-
|
|
45
|
-
const FULL_DATE: string = [DAY, MONTH, YEAR].join('-');
|
|
46
|
-
const FULL_TIME: string = [HOURS, MINUTES].join(':');
|
|
47
|
-
|
|
48
|
-
let logFile;
|
|
49
|
-
try {
|
|
50
|
-
logFile = await fs.readFile(path.join(this.LOG_DIR, `${FULL_DATE}-${type}.log`));
|
|
51
|
-
} catch (e) {
|
|
52
|
-
// console.error(e);
|
|
53
|
-
// let me just fail silently if the file does not exist
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if ( !logFile ) {
|
|
57
|
-
const data = 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
|
|
58
|
-
return await fs.writeFile(path.join(this.LOG_DIR, `${FULL_DATE}-${type}.log`), data);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const data = logFile + 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
|
|
62
|
-
return await fs.writeFile(path.join(this.LOG_DIR, `${FULL_DATE}-${type}.log`), data);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
}
|