@ricdotnet/logger 0.0.2 → 0.0.5

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.
@@ -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
+
@@ -1,42 +1,53 @@
1
1
  import { Logger } from '../src/Logger';
2
2
  import { Constants } from '../src/Constants';
3
3
 
4
- const loggerSpy = {
5
- info : jest.spyOn(Logger, 'info'),
6
- warn : jest.spyOn(Logger, 'warn'),
7
- error: jest.spyOn(Logger, 'error')
8
- };
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
+ // };
9
10
 
10
11
  const consoleSpy = {
11
- info : jest.spyOn(console, 'log'),
12
- warn : jest.spyOn(console, 'warn'),
12
+ info: jest.spyOn(console, 'log'),
13
+ warn: jest.spyOn(console, 'warn'),
13
14
  error: jest.spyOn(console, 'error'),
14
15
  };
15
16
 
16
17
  describe('Logger test', () => {
18
+ let loggerInstance;
19
+ let loggerSpy;
17
20
 
18
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
+
19
30
  loggerSpy.info.mockClear();
20
31
  loggerSpy.warn.mockClear();
21
32
  loggerSpy.error.mockClear();
22
33
  });
23
34
 
24
- it('can log an info and check the output', () => {
25
- Logger.info('hello world');
35
+ it('can log an info', async () => {
36
+ await loggerInstance.info('hello world');
26
37
 
27
- expect(loggerSpy.info).toHaveBeenCalledWith('hello world');
28
- expect(consoleSpy.info).toHaveBeenCalledWith(`${Constants.TEXT_BLUE}[INFO]: hello world`);
38
+ await expect(loggerSpy.info).toHaveBeenCalledWith('hello world');
39
+ await expect(consoleSpy.info).toHaveBeenCalledWith(`${Constants.TEXT_BLUE}[INFO]: hello world`);
29
40
  });
30
41
 
31
42
  it('can log a warning', () => {
32
- Logger.warn('hello world');
43
+ loggerInstance.warn('hello world');
33
44
 
34
45
  expect(loggerSpy.warn).toHaveBeenCalledWith('hello world');
35
- expect(consoleSpy.warn).toHaveBeenCalledWith(`${Constants.TEXT_YELLOW}[WARN]: hello world`);
46
+ // expect(consoleSpy.warn).toHaveBeenCalledWith(`${Constants.TEXT_YELLOW}[WARN]: hello world`);
36
47
  });
37
48
 
38
49
  it('can log an error', () => {
39
- Logger.error('hello world');
50
+ loggerInstance.error('hello world');
40
51
 
41
52
  expect(loggerSpy.error).toHaveBeenCalledWith('hello world');
42
53
  expect(consoleSpy.error).toHaveBeenCalledWith(`${Constants.TEXT_RED}[ERROR]: hello world`);
@@ -0,0 +1 @@
1
+ export { Logger } from './src/Logger';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ var Logger_1 = require("./src/Logger");
5
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return Logger_1.Logger; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"./","sources":["index.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAA7B,gGAAA,MAAM,OAAA"}
@@ -0,0 +1,25 @@
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
+ }
@@ -0,0 +1,30 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,61 @@
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
+ }
46
+ catch (e) {
47
+ try {
48
+ if (!logFile) {
49
+ const data = 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
50
+ await fs.writeFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`), data);
51
+ }
52
+ const data = logFile + 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
53
+ await fs.writeFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`), data);
54
+ }
55
+ catch (error) {
56
+ }
57
+ }
58
+ }
59
+ }
60
+ exports.Logger = Logger;
61
+ //# sourceMappingURL=Logger.js.map
@@ -0,0 +1 @@
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,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,SAAS,IAAI,MAAM,CAAC,CAAC;QACrE,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,WAAW;QACf,IAAI;YACF,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,sCAAsC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;SACtE;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,CAAC,IAAI,CAAC,2CAA2C,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;SAC3E;IACH,CAAC;IAED,KAAK,CAAC,IAAI,CAAa,OAAuB;QAC5C,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,KAAK,CAAC,IAAI,CAAa,OAAuB;QAC5C,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,GAAG,qBAAS,CAAC,WAAW,WAAW,OAAO,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,KAAK,CAAa,OAAuB;QAC7C,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACzC,OAAO,CAAC,KAAK,CAAC,GAAG,qBAAS,CAAC,QAAQ,YAAY,OAAO,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAY,EAAE,IAAY;QAC1C,MAAM,GAAG,GAAW,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QACzC,MAAM,KAAK,GAAW,IAAI,IAAI,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAChD,MAAM,IAAI,GAAW,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAW,IAAI,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC;QAC5C,MAAM,OAAO,GAAW,IAAI,IAAI,EAAE,CAAC,UAAU,EAAE,CAAC;QAEhD,MAAM,SAAS,GAAW,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvD,MAAM,SAAS,GAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAErD,IAAI,OAAO,CAAC;QACZ,IAAI;YACF,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC;SACjF;QAAC,OAAO,CAAC,EAAE;YACV,IAAI;gBACF,IAAK,CAAC,OAAO,EAAG;oBACd,MAAM,IAAI,GAAG,YAAY,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC;oBAChE,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,IAAI,IAAI,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;iBAC9E;gBAED,MAAM,IAAI,GAAG,OAAO,GAAG,YAAY,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC;gBAC1E,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,SAAS,IAAI,IAAI,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;aAC9E;YAAC,OAAO,KAAK,EAAE;aACf;SACF;IACH,CAAC;CAEF;AA5DD,wBA4DC"}
@@ -0,0 +1,4 @@
1
+ export declare type Primitives = string | number | object;
2
+ export interface ILogger {
3
+ directory?: string;
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Types.js","sourceRoot":"./","sources":["src/Types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricdotnet/logger",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
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": ["logger", "logs", "console.log", "log", "logjs", "logts", "logger4ts", "logger4js"],
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/src/Constants.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  export enum Constants {
2
- Reset = '\x1b[0m',
2
+ RESET = '\x1b[0m',
3
3
  BRIGHT = '\x1b[1m',
4
- Dim = '\x1b[2m',
5
- Underscore = '\x1b[4m',
6
- Blink = '\x1b[5m',
7
- Reverse = '\x1b[7m',
8
- Hidden = '\x1b[8m',
4
+ DIM = '\x1b[2m',
5
+ UNDERSCORE = '\x1b[4m',
6
+ BLINK = '\x1b[5m',
7
+ REVERSE = '\x1b[7m',
8
+ HIDDEN = '\x1b[8m',
9
9
 
10
10
  TEXT_BLACK = '\x1b[30m',
11
11
  TEXT_RED = '\x1b[31m',
package/src/Logger.ts CHANGED
@@ -1,45 +1,46 @@
1
1
  import * as fs from 'fs/promises';
2
2
  import * as path from 'path';
3
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]
4
+ import { ILogger, Primitives } from './Types';
8
5
 
9
6
  export class Logger {
10
7
 
11
- static LOG_DIR = './Logs';
8
+ private readonly logDir: string;
12
9
 
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
- }
10
+ constructor(options?: ILogger) {
11
+ this.logDir = path.join(process.cwd(), options?.directory ?? 'Logs');
12
+ this.checkLogDir();
13
+ }
19
14
 
20
- // return this.info('Logs folder already exists... The logger will write inside it.');
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
+ }
21
22
  }
22
23
 
23
- static async info(message: any) {
24
+ async info<T = string>(message: T | Primitives) {
24
25
  await this.writeToFile(message, 'info');
25
26
  console.log(`${Constants.TEXT_BLUE}[INFO]: ${message}`);
26
27
  }
27
28
 
28
- static async warn(message: any) {
29
+ async warn<T = string>(message: T | Primitives) {
29
30
  await this.writeToFile(message, 'warn');
30
31
  console.warn(`${Constants.TEXT_YELLOW}[WARN]: ${message}`);
31
32
  }
32
33
 
33
- static async error(message: any) {
34
+ async error<T = string>(message: T | Primitives) {
34
35
  await this.writeToFile(message, 'error');
35
36
  console.error(`${Constants.TEXT_RED}[ERROR]: ${message}`);
36
37
  }
37
38
 
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();
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();
43
44
  const MINUTES: number = new Date().getMinutes();
44
45
 
45
46
  const FULL_DATE: string = [DAY, MONTH, YEAR].join('-');
@@ -47,19 +48,19 @@ export class Logger {
47
48
 
48
49
  let logFile;
49
50
  try {
50
- logFile = await fs.readFile(path.join(this.LOG_DIR, `${FULL_DATE}-${type}.log`));
51
+ logFile = await fs.readFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`));
51
52
  } catch (e) {
52
- // console.error(e);
53
- // let me just fail silently if the file does not exist
54
- }
53
+ try {
54
+ if ( !logFile ) {
55
+ const data = 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
56
+ await fs.writeFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`), data);
57
+ }
55
58
 
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
+ const data = logFile + 'Log Time: ' + FULL_TIME + '\n' + message + '\n\n';
60
+ await fs.writeFile(path.join(this.logDir, `${FULL_DATE}-${type}.log`), data);
61
+ } catch (error) {
62
+ }
59
63
  }
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
  }
64
65
 
65
66
  }
package/src/Types.ts ADDED
@@ -0,0 +1,5 @@
1
+ export type Primitives = string | number | object;
2
+
3
+ export interface ILogger {
4
+ directory?: string;
5
+ }
package/tsconfig.json CHANGED
@@ -7,9 +7,12 @@
7
7
  "outDir": "dist",
8
8
  "sourceRoot": "./",
9
9
  "allowJs": true,
10
- "declaration": true
10
+ "declaration": true,
11
+ "resolveJsonModule": true
11
12
  },
12
13
  "exclude": [
13
- "node_modules"
14
+ "node_modules",
15
+ "Tests",
16
+ "jest.config.js",
14
17
  ]
15
18
  }
File without changes