@ricdotnet/logger 0.0.4 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricdotnet/logger",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "description": "A logger utility for my personal projects.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,24 +0,0 @@
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
-
@@ -1,27 +0,0 @@
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
-
@@ -1,33 +0,0 @@
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
-
@@ -1,55 +0,0 @@
1
- import { Logger } from '../src/Logger';
2
- import { Constants } from '../src/Constants';
3
-
4
-
5
- // const loggerSpy = {
6
- // info: jest.spyOn(Logger.getInstance(), 'info'),
7
- // warn: jest.spyOn(Logger.getInstance(), 'warn'),
8
- // error: jest.spyOn(Logger.getInstance(), 'error')
9
- // };
10
-
11
- const consoleSpy = {
12
- info: jest.spyOn(console, 'log'),
13
- warn: jest.spyOn(console, 'warn'),
14
- error: jest.spyOn(console, 'error'),
15
- };
16
-
17
- describe('Logger test', () => {
18
- let loggerInstance;
19
- let loggerSpy;
20
-
21
- beforeEach(() => {
22
- loggerInstance = new Logger();
23
-
24
- loggerSpy = {
25
- info: jest.spyOn(loggerInstance, 'info'),
26
- warn: jest.spyOn(loggerInstance, 'warn'),
27
- error: jest.spyOn(loggerInstance, 'error')
28
- };
29
-
30
- loggerSpy.info.mockClear();
31
- loggerSpy.warn.mockClear();
32
- loggerSpy.error.mockClear();
33
- });
34
-
35
- it('can log an info', async () => {
36
- await loggerInstance.info('hello world');
37
-
38
- await expect(loggerSpy.info).toHaveBeenCalledWith('hello world');
39
- await expect(consoleSpy.info).toHaveBeenCalledWith(`${Constants.TEXT_BLUE}[INFO]: hello world`);
40
- });
41
-
42
- it('can log a warning', () => {
43
- loggerInstance.warn('hello world');
44
-
45
- expect(loggerSpy.warn).toHaveBeenCalledWith('hello world');
46
- // expect(consoleSpy.warn).toHaveBeenCalledWith(`${Constants.TEXT_YELLOW}[WARN]: hello world`);
47
- });
48
-
49
- it('can log an error', () => {
50
- loggerInstance.error('hello world');
51
-
52
- expect(loggerSpy.error).toHaveBeenCalledWith('hello world');
53
- expect(consoleSpy.error).toHaveBeenCalledWith(`${Constants.TEXT_RED}[ERROR]: hello world`);
54
- });
55
- });
@@ -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
- }
@@ -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"}
@@ -1,10 +0,0 @@
1
- import { ILogger, Primitives } from './Types';
2
- export declare class Logger {
3
- private readonly logDir;
4
- constructor(options?: ILogger);
5
- checkLogDir(): Promise<void>;
6
- info<T = string>(message: T | Primitives): Promise<void>;
7
- warn<T = string>(message: T | Primitives): Promise<void>;
8
- error<T = string>(message: T | Primitives): Promise<void>;
9
- writeToFile(message: any, type: string): Promise<void>;
10
- }
@@ -1,57 +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
- logDir;
9
- constructor(options) {
10
- this.logDir = path.join(process.cwd(), options?.directory ?? 'Logs');
11
- this.checkLogDir();
12
- }
13
- async checkLogDir() {
14
- try {
15
- await fs.mkdir(this.logDir);
16
- await this.info(`Logs folder generated. Logging to: ${this.logDir}`);
17
- }
18
- catch (error) {
19
- await this.info(`Logs folder already exists. Logging to: ${this.logDir}`);
20
- }
21
- }
22
- async info(message) {
23
- await this.writeToFile(message, 'info');
24
- console.log(`${Constants_1.Constants.TEXT_BLUE}[INFO]: ${message}`);
25
- }
26
- async warn(message) {
27
- await this.writeToFile(message, 'warn');
28
- console.warn(`${Constants_1.Constants.TEXT_YELLOW}[WARN]: ${message}`);
29
- }
30
- async error(message) {
31
- await this.writeToFile(message, 'error');
32
- console.error(`${Constants_1.Constants.TEXT_RED}[ERROR]: ${message}`);
33
- }
34
- async writeToFile(message, type) {
35
- const DAY = new Date().getDate();
36
- const MONTH = new Date().getMonth() + 1;
37
- const YEAR = new Date().getFullYear();
38
- const HOURS = new Date().getHours();
39
- const MINUTES = new Date().getMinutes();
40
- const FULL_DATE = [DAY, MONTH, YEAR].join('-');
41
- const FULL_TIME = [HOURS, MINUTES].join(':');
42
- let logFile;
43
- try {
44
- logFile = await fs.readFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`));
45
- if (!logFile) {
46
- const data = 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
47
- await fs.writeFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`), data);
48
- }
49
- const data = logFile + 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
50
- await fs.writeFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`), data);
51
- }
52
- catch (e) {
53
- }
54
- }
55
- }
56
- exports.Logger = Logger;
57
- //# sourceMappingURL=Logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Logger.js","sourceRoot":"./","sources":["src/Logger.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAClC,6BAA6B;AAC7B,2CAAwC;AAGxC,MAAa,MAAM;IAEA,MAAM,CAAS;IAEhC,YAAY,OAAiB;QAC3B,IAAI,CAAC,MAAM,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interface ILogger {
3
- directory?: string;
4
- }
package/dist/src/Types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=Types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Types.js","sourceRoot":"./","sources":["src/Types.ts"],"names":[],"mappings":""}
package/jest.config.js DELETED
@@ -1,11 +0,0 @@
1
- /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
- module.exports = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- roots: [
6
- '<rootDir>',
7
- ],
8
- moduleDirectories: [
9
- 'node_modules'
10
- ],
11
- };
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,66 +0,0 @@
1
- import * as fs from 'fs/promises';
2
- import * as path from 'path';
3
- import { Constants } from './Constants';
4
- import { ILogger, Primitives } from './Types';
5
-
6
- export class Logger {
7
-
8
- private readonly logDir: string;
9
-
10
- constructor(options?: ILogger) {
11
- this.logDir = path.join(process.cwd(), options?.directory ?? 'Logs');
12
- this.checkLogDir();
13
- }
14
-
15
- async checkLogDir() {
16
- try {
17
- await fs.mkdir(this.logDir);
18
- await this.info(`Logs folder generated. Logging to: ${this.logDir}`);
19
- } catch (error) {
20
- await this.info(`Logs folder already exists. Logging to: ${this.logDir}`);
21
- }
22
- }
23
-
24
- async info<T = string>(message: T | Primitives) {
25
- await this.writeToFile(message, 'info');
26
- console.log(`${Constants.TEXT_BLUE}[INFO]: ${message}`);
27
- }
28
-
29
- async warn<T = string>(message: T | Primitives) {
30
- await this.writeToFile(message, 'warn');
31
- console.warn(`${Constants.TEXT_YELLOW}[WARN]: ${message}`);
32
- }
33
-
34
- async error<T = string>(message: T | Primitives) {
35
- await this.writeToFile(message, 'error');
36
- console.error(`${Constants.TEXT_RED}[ERROR]: ${message}`);
37
- }
38
-
39
- async writeToFile(message: any, type: string) {
40
- const DAY: number = new Date().getDate();
41
- const MONTH: number = new Date().getMonth() + 1; // +1 because it goes 0-11
42
- const YEAR: number = new Date().getFullYear();
43
- const HOURS: number = new Date().getHours();
44
- const MINUTES: number = new Date().getMinutes();
45
-
46
- const FULL_DATE: string = [DAY, MONTH, YEAR].join('-');
47
- const FULL_TIME: string = [HOURS, MINUTES].join(':');
48
-
49
- let logFile;
50
- try {
51
- logFile = await fs.readFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`));
52
-
53
- if ( !logFile ) {
54
- const data = 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
55
- await fs.writeFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`), data);
56
- }
57
-
58
- const data = logFile + 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
59
- await fs.writeFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`), data);
60
- } catch (e) {
61
- // console.error(e);
62
- // let me just fail silently if the file does not exist
63
- }
64
- }
65
-
66
- }
package/src/Types.ts DELETED
@@ -1,5 +0,0 @@
1
- export type Primitives = string | number | object;
2
-
3
- export interface ILogger {
4
- directory?: string;
5
- }