jet-logger 1.3.0 → 2.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/20240906T172140_jet-logger-alt2.log +15 -0
- package/20240906T172140_jet-logger-json.log +5 -0
- package/20240906T172140_jet-logger.log +5 -0
- package/20240906T172811_jet-logger-alt2.log +15 -0
- package/20240906T172811_jet-logger-json.log +5 -0
- package/20240906T172811_jet-logger.log +5 -0
- package/README.md +5 -6
- package/jet-logger-alt.log +30 -0
- package/package.json +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -11
- package/lib/jetLogger.d.ts +0 -30
- package/lib/jetLogger.js +0 -190
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[2024-09-06T17:21:40.902Z] INFO: hello jet-logger
|
|
2
|
+
[2024-09-06T17:21:40.902Z] IMPORTANT: hello jet-logger
|
|
3
|
+
[2024-09-06T17:21:40.903Z] WARNING: hello jet-logger
|
|
4
|
+
[2024-09-06T17:21:40.903Z] ERROR: hello jet-logger
|
|
5
|
+
[2024-09-06T17:21:40.904Z] ERROR: Error: Demo print full error object
|
|
6
|
+
at Object.<anonymous> (/home/sean/projects/jet-logger/test/index.ts:76:13)
|
|
7
|
+
at Module._compile (node:internal/modules/cjs/loader:1256:14)
|
|
8
|
+
at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1618:23)
|
|
9
|
+
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
|
|
10
|
+
at Object.require.extensions.<computed> [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1621:12)
|
|
11
|
+
at Module.load (node:internal/modules/cjs/loader:1119:32)
|
|
12
|
+
at Function.Module._load (node:internal/modules/cjs/loader:960:12)
|
|
13
|
+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
|
|
14
|
+
at phase4 (/usr/local/lib/node_modules/ts-node/src/bin.ts:649:14)
|
|
15
|
+
at bootstrap (/usr/local/lib/node_modules/ts-node/src/bin.ts:95:10)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{"level":"INFO","message":"hello jet-logger","timestamp":"2024-09-06T17:21:40.904Z"}
|
|
2
|
+
{"level":"IMPORTANT","message":"hello jet-logger","timestamp":"2024-09-06T17:21:40.904Z"}
|
|
3
|
+
{"level":"WARNING","message":"hello jet-logger","timestamp":"2024-09-06T17:21:40.904Z"}
|
|
4
|
+
{"level":"ERROR","message":"hello jet-logger","timestamp":"2024-09-06T17:21:40.905Z"}
|
|
5
|
+
{"level":"ERROR","message":"Error: Demo print full error object\n at Object.<anonymous> (/home/sean/projects/jet-logger/test/index.ts:88:13)\n at Module._compile (node:internal/modules/cjs/loader:1256:14)\n at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1618:23)\n at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)\n at Object.require.extensions.<computed> [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1621:12)\n at Module.load (node:internal/modules/cjs/loader:1119:32)\n at Function.Module._load (node:internal/modules/cjs/loader:960:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)\n at phase4 (/usr/local/lib/node_modules/ts-node/src/bin.ts:649:14)\n at bootstrap (/usr/local/lib/node_modules/ts-node/src/bin.ts:95:10)","timestamp":"2024-09-06T17:21:40.906Z"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[2024-09-06T17:28:11.811Z] IMPORTANT: hello jet-logger
|
|
2
|
+
[2024-09-06T17:28:11.811Z] INFO: hello jet-logger
|
|
3
|
+
[2024-09-06T17:28:11.811Z] ERROR: hello jet-logger
|
|
4
|
+
[2024-09-06T17:28:11.811Z] WARNING: hello jet-logger
|
|
5
|
+
[2024-09-06T17:28:11.812Z] ERROR: Error: Demo print full error object
|
|
6
|
+
at Object.<anonymous> (/home/sean/projects/jet-logger/test/index.ts:74:13)
|
|
7
|
+
at Module._compile (node:internal/modules/cjs/loader:1256:14)
|
|
8
|
+
at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1618:23)
|
|
9
|
+
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
|
|
10
|
+
at Object.require.extensions.<computed> [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1621:12)
|
|
11
|
+
at Module.load (node:internal/modules/cjs/loader:1119:32)
|
|
12
|
+
at Function.Module._load (node:internal/modules/cjs/loader:960:12)
|
|
13
|
+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
|
|
14
|
+
at phase4 (/usr/local/lib/node_modules/ts-node/src/bin.ts:649:14)
|
|
15
|
+
at bootstrap (/usr/local/lib/node_modules/ts-node/src/bin.ts:95:10)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{"level":"INFO","message":"hello jet-logger","timestamp":"2024-09-06T17:28:11.812Z"}
|
|
2
|
+
{"level":"IMPORTANT","message":"hello jet-logger","timestamp":"2024-09-06T17:28:11.812Z"}
|
|
3
|
+
{"level":"WARNING","message":"hello jet-logger","timestamp":"2024-09-06T17:28:11.812Z"}
|
|
4
|
+
{"level":"ERROR","message":"hello jet-logger","timestamp":"2024-09-06T17:28:11.812Z"}
|
|
5
|
+
{"level":"ERROR","message":"Error: Demo print full error object\n at Object.<anonymous> (/home/sean/projects/jet-logger/test/index.ts:86:13)\n at Module._compile (node:internal/modules/cjs/loader:1256:14)\n at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1618:23)\n at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)\n at Object.require.extensions.<computed> [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1621:12)\n at Module.load (node:internal/modules/cjs/loader:1119:32)\n at Function.Module._load (node:internal/modules/cjs/loader:960:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)\n at phase4 (/usr/local/lib/node_modules/ts-node/src/bin.ts:649:14)\n at bootstrap (/usr/local/lib/node_modules/ts-node/src/bin.ts:95:10)","timestamp":"2024-09-06T17:28:11.813Z"}
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ $ npm install --save jet-logger
|
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
### Guide
|
|
16
|
-
The logger package's
|
|
16
|
+
The logger package's default export is an instance of the `JetLogger` class. This default export uses all the default settings. If you wish to pass your own settings you can import the `JetLogger` class and pass parameters to the constructor to configure your own custom logger.
|
|
17
17
|
|
|
18
18
|
- The five environment variables are:
|
|
19
19
|
- `JET_LOGGER_MODE`: can be `'CONSOLE'`(default), `'FILE'`, `'CUSTOM'`, and `'OFF'`.
|
|
@@ -22,7 +22,7 @@ The logger package's main export is the default `logger` object. This default ex
|
|
|
22
22
|
- `JET_LOGGER_TIMESTAMP`: adds a timestamp next to each log. Can be `'TRUE'` (default) or `'FALSE'`.
|
|
23
23
|
- `JET_LOGGER_FORMAT`: formats log as a line or JSON object. Can be `'LINE'` (default) or `'JSON'`.
|
|
24
24
|
|
|
25
|
-
_logger_ has an export `LoggerModes` which is an enum that provides all the modes if you want to use them in code. I would recommend using `Console` for local development, `File` for remote development, and `Custom` or `Off` for production. If you want to change the settings in code, you can do so via importing the `JetLogger`
|
|
25
|
+
_logger_ has an export `LoggerModes` which is an enum that provides all the modes if you want to use them in code. I would recommend using `Console` for local development, `File` for remote development, and `Custom` or `Off` for production. If you want to change the settings in code, you can do so via importing the `JetLogger` class and calling it with whatever options you want.
|
|
26
26
|
<br>
|
|
27
27
|
|
|
28
28
|
- There are 4 functions on Logger to print logs.
|
|
@@ -97,18 +97,17 @@ For production you'll probably have some third party logging tool like ElasticSe
|
|
|
97
97
|
// In the route file
|
|
98
98
|
import { OK } from 'http-status-codes';
|
|
99
99
|
import { Router, Request, Response } from 'express';
|
|
100
|
-
import {
|
|
100
|
+
import { JetLogger, TCustomLogFn } from 'jet-logger';
|
|
101
101
|
import { thirdPartyLoggingApp } from 'thirdPartyLoggingApplicationLib';
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
// Needs to be implemented
|
|
105
|
-
const customSend: TCustomLogFn = (timestamp: Date, level: string, content:
|
|
105
|
+
const customSend: TCustomLogFn = (timestamp: Date, level: string, content: unknown) => {
|
|
106
106
|
thirdPartyLoggingApp.doStuff(...);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
router.get('api/users', async (req: Request, res: Reponse) => {
|
|
110
|
-
const logger
|
|
111
|
-
logger.rmTimestamp = true;
|
|
110
|
+
const logger = new JetLogger(LoggerModes.CUSTOM, '', true, true, undefined, customSend);
|
|
112
111
|
logger.info(req.params.msg);
|
|
113
112
|
return res.status(OK).json({
|
|
114
113
|
message: 'console_mode',
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
INFO: hello jet-logger
|
|
2
|
+
IMPORTANT: hello jet-logger
|
|
3
|
+
WARNING: hello jet-logger
|
|
4
|
+
ERROR: hello jet-logger
|
|
5
|
+
ERROR: Error: Demo print full error object
|
|
6
|
+
at Object.<anonymous> (/home/sean/projects/jet-logger/test/index.ts:65:13)
|
|
7
|
+
at Module._compile (node:internal/modules/cjs/loader:1256:14)
|
|
8
|
+
at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1618:23)
|
|
9
|
+
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
|
|
10
|
+
at Object.require.extensions.<computed> [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1621:12)
|
|
11
|
+
at Module.load (node:internal/modules/cjs/loader:1119:32)
|
|
12
|
+
at Function.Module._load (node:internal/modules/cjs/loader:960:12)
|
|
13
|
+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
|
|
14
|
+
at phase4 (/usr/local/lib/node_modules/ts-node/src/bin.ts:649:14)
|
|
15
|
+
at bootstrap (/usr/local/lib/node_modules/ts-node/src/bin.ts:95:10)
|
|
16
|
+
INFO: hello jet-logger
|
|
17
|
+
WARNING: hello jet-logger
|
|
18
|
+
ERROR: hello jet-logger
|
|
19
|
+
ERROR: Error: Demo print full error object
|
|
20
|
+
at Object.<anonymous> (/home/sean/projects/jet-logger/test/index.ts:63:13)
|
|
21
|
+
at Module._compile (node:internal/modules/cjs/loader:1256:14)
|
|
22
|
+
at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1618:23)
|
|
23
|
+
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
|
|
24
|
+
at Object.require.extensions.<computed> [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1621:12)
|
|
25
|
+
at Module.load (node:internal/modules/cjs/loader:1119:32)
|
|
26
|
+
at Function.Module._load (node:internal/modules/cjs/loader:960:12)
|
|
27
|
+
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
|
|
28
|
+
at phase4 (/usr/local/lib/node_modules/ts-node/src/bin.ts:649:14)
|
|
29
|
+
at bootstrap (/usr/local/lib/node_modules/ts-node/src/bin.ts:95:10)
|
|
30
|
+
IMPORTANT: hello jet-logger
|
package/package.json
CHANGED
package/lib/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { LoggerModes, Formats, TCustomLogFn, ILogger, jetLogger, default as default, } from './jetLogger';
|
package/lib/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = exports.jetLogger = exports.Formats = exports.LoggerModes = void 0;
|
|
7
|
-
var jetLogger_1 = require("./jetLogger");
|
|
8
|
-
Object.defineProperty(exports, "LoggerModes", { enumerable: true, get: function () { return jetLogger_1.LoggerModes; } });
|
|
9
|
-
Object.defineProperty(exports, "Formats", { enumerable: true, get: function () { return jetLogger_1.Formats; } });
|
|
10
|
-
Object.defineProperty(exports, "jetLogger", { enumerable: true, get: function () { return jetLogger_1.jetLogger; } });
|
|
11
|
-
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(jetLogger_1).default; } });
|
package/lib/jetLogger.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export declare enum LoggerModes {
|
|
2
|
-
Console = "CONSOLE",
|
|
3
|
-
File = "FILE",
|
|
4
|
-
Custom = "CUSTOM",
|
|
5
|
-
Off = "OFF"
|
|
6
|
-
}
|
|
7
|
-
export declare enum Formats {
|
|
8
|
-
Line = "LINE",
|
|
9
|
-
Json = "JSON"
|
|
10
|
-
}
|
|
11
|
-
declare type TLogFn = (content: any, printFull?: boolean) => void;
|
|
12
|
-
export declare type TCustomLogFn = (timestamp: Date, prefix: string, content: unknown) => void;
|
|
13
|
-
export interface ILogger {
|
|
14
|
-
settings: ISettings;
|
|
15
|
-
info: TLogFn;
|
|
16
|
-
imp: TLogFn;
|
|
17
|
-
warn: TLogFn;
|
|
18
|
-
err: TLogFn;
|
|
19
|
-
}
|
|
20
|
-
interface ISettings {
|
|
21
|
-
mode: LoggerModes;
|
|
22
|
-
filepath: string;
|
|
23
|
-
filepathDatetime: boolean;
|
|
24
|
-
timestamp: boolean;
|
|
25
|
-
format: Formats;
|
|
26
|
-
customLogFn?: TCustomLogFn;
|
|
27
|
-
}
|
|
28
|
-
export declare function jetLogger(mode?: LoggerModes, filepath?: string, filepathDatetime?: boolean, timestamp?: boolean, format?: Formats, customLogFn?: TCustomLogFn): ILogger;
|
|
29
|
-
declare const _default: ILogger;
|
|
30
|
-
export default _default;
|
package/lib/jetLogger.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.jetLogger = exports.Formats = exports.LoggerModes = void 0;
|
|
7
|
-
var util_1 = __importDefault(require("util"));
|
|
8
|
-
var colors_1 = __importDefault(require("colors"));
|
|
9
|
-
var fs_1 = __importDefault(require("fs"));
|
|
10
|
-
var LoggerModes;
|
|
11
|
-
(function (LoggerModes) {
|
|
12
|
-
LoggerModes["Console"] = "CONSOLE";
|
|
13
|
-
LoggerModes["File"] = "FILE";
|
|
14
|
-
LoggerModes["Custom"] = "CUSTOM";
|
|
15
|
-
LoggerModes["Off"] = "OFF";
|
|
16
|
-
})(LoggerModes = exports.LoggerModes || (exports.LoggerModes = {}));
|
|
17
|
-
var Formats;
|
|
18
|
-
(function (Formats) {
|
|
19
|
-
Formats["Line"] = "LINE";
|
|
20
|
-
Formats["Json"] = "JSON";
|
|
21
|
-
})(Formats = exports.Formats || (exports.Formats = {}));
|
|
22
|
-
var Levels = {
|
|
23
|
-
Info: {
|
|
24
|
-
Color: 'green',
|
|
25
|
-
Prefix: 'INFO',
|
|
26
|
-
},
|
|
27
|
-
Imp: {
|
|
28
|
-
Color: 'magenta',
|
|
29
|
-
Prefix: 'IMPORTANT',
|
|
30
|
-
},
|
|
31
|
-
Warn: {
|
|
32
|
-
Color: 'yellow',
|
|
33
|
-
Prefix: 'WARNING',
|
|
34
|
-
},
|
|
35
|
-
Err: {
|
|
36
|
-
Color: 'red',
|
|
37
|
-
Prefix: 'ERROR',
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var Errors = {
|
|
41
|
-
customLogFn: 'Custom logger mode set to true, but no custom logger was ' +
|
|
42
|
-
'provided.',
|
|
43
|
-
Mode: 'The correct logger mode was not specified: Must be "CUSTOM", ' +
|
|
44
|
-
'"FILE", "OFF", or "CONSOLE".'
|
|
45
|
-
};
|
|
46
|
-
var Defaults = {
|
|
47
|
-
Filepath: 'jet-logger.log',
|
|
48
|
-
Mode: LoggerModes.Console,
|
|
49
|
-
Timestamp: true,
|
|
50
|
-
FilepathDatetime: true,
|
|
51
|
-
Format: Formats.Line,
|
|
52
|
-
};
|
|
53
|
-
function jetLogger(mode, filepath, filepathDatetime, timestamp, format, customLogFn) {
|
|
54
|
-
var settings = getSettings(mode, filepath, timestamp, filepathDatetime, format, customLogFn);
|
|
55
|
-
return { settings: settings, info: info, imp: imp, warn: warn, err: err };
|
|
56
|
-
}
|
|
57
|
-
exports.jetLogger = jetLogger;
|
|
58
|
-
function getSettings(mode, filepath, filepathDatetime, timestamp, format, customLogFn) {
|
|
59
|
-
if (!mode) {
|
|
60
|
-
if (!!process.env.JET_LOGGER_MODE) {
|
|
61
|
-
mode = process.env.JET_LOGGER_MODE.toUpperCase();
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
mode = Defaults.Mode;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (!filepath) {
|
|
68
|
-
if (!!process.env.JET_LOGGER_FILEPATH) {
|
|
69
|
-
filepath = process.env.JET_LOGGER_FILEPATH;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
filepath = Defaults.Filepath;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (filepathDatetime === undefined || filepathDatetime === null) {
|
|
76
|
-
var envVar = process.env.JET_LOGGER_FILEPATH_DATETIME;
|
|
77
|
-
if (!!envVar) {
|
|
78
|
-
filepathDatetime = (envVar.toUpperCase() === 'TRUE');
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
filepathDatetime = Defaults.FilepathDatetime;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (timestamp === undefined || timestamp === null) {
|
|
85
|
-
if (!!process.env.JET_LOGGER_TIMESTAMP) {
|
|
86
|
-
timestamp = (process.env.JET_LOGGER_TIMESTAMP.toUpperCase() === 'TRUE');
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
timestamp = Defaults.Timestamp;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (!format) {
|
|
93
|
-
if (!!process.env.JET_LOGGER_FORMAT) {
|
|
94
|
-
format = process.env.JET_LOGGER_FORMAT.toUpperCase();
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
format = Defaults.Format;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (filepathDatetime) {
|
|
101
|
-
filepath = addDatetimeToFileName(filepath);
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
mode: mode,
|
|
105
|
-
filepath: filepath,
|
|
106
|
-
filepathDatetime: filepathDatetime,
|
|
107
|
-
timestamp: timestamp,
|
|
108
|
-
format: format,
|
|
109
|
-
customLogFn: customLogFn,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function addDatetimeToFileName(filePath) {
|
|
113
|
-
var dateStr = new Date().toISOString()
|
|
114
|
-
.split('-').join('')
|
|
115
|
-
.split(':').join('')
|
|
116
|
-
.slice(0, 15);
|
|
117
|
-
var filePathArr = filePath.split('/'), lastIdx = filePathArr.length - 1, fileName = filePathArr[lastIdx], fileNameNew = (dateStr + '_' + fileName);
|
|
118
|
-
filePathArr[lastIdx] = fileNameNew;
|
|
119
|
-
return filePathArr.join('/');
|
|
120
|
-
}
|
|
121
|
-
function info(content, printFull) {
|
|
122
|
-
return printLog(content, printFull !== null && printFull !== void 0 ? printFull : false, Levels.Info, this.settings);
|
|
123
|
-
}
|
|
124
|
-
function imp(content, printFull) {
|
|
125
|
-
return printLog(content, printFull !== null && printFull !== void 0 ? printFull : false, Levels.Imp, this.settings);
|
|
126
|
-
}
|
|
127
|
-
function warn(content, printFull) {
|
|
128
|
-
return printLog(content, printFull !== null && printFull !== void 0 ? printFull : false, Levels.Warn, this.settings);
|
|
129
|
-
}
|
|
130
|
-
function err(content, printFull) {
|
|
131
|
-
return printLog(content, printFull !== null && printFull !== void 0 ? printFull : false, Levels.Err, this.settings);
|
|
132
|
-
}
|
|
133
|
-
function printLog(content, printFull, level, settings) {
|
|
134
|
-
var mode = settings.mode, format = settings.format, timestamp = settings.timestamp, filepath = settings.filepath, customLogFn = settings.customLogFn;
|
|
135
|
-
if (mode === LoggerModes.Off) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (printFull) {
|
|
139
|
-
content = util_1.default.inspect(content);
|
|
140
|
-
}
|
|
141
|
-
if (mode === LoggerModes.Custom) {
|
|
142
|
-
if (!!customLogFn) {
|
|
143
|
-
return customLogFn(new Date(), level.Prefix, content);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
throw Error(Errors.customLogFn);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (format === Formats.Line) {
|
|
150
|
-
content = setupLineFormat(content, timestamp, level);
|
|
151
|
-
}
|
|
152
|
-
else if (format === Formats.Json) {
|
|
153
|
-
content = setupJsonFormat(content, timestamp, level);
|
|
154
|
-
}
|
|
155
|
-
if (mode === LoggerModes.Console) {
|
|
156
|
-
var colorFn = colors_1.default[level.Color];
|
|
157
|
-
console.log(colorFn(content));
|
|
158
|
-
}
|
|
159
|
-
else if (mode === LoggerModes.File) {
|
|
160
|
-
writeToFile(content + '\n', filepath)
|
|
161
|
-
.catch(function (err) { return console.log(err); });
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
throw Error(Errors.Mode);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function setupLineFormat(content, timestamp, level) {
|
|
168
|
-
content = (level.Prefix + ': ' + content);
|
|
169
|
-
if (timestamp) {
|
|
170
|
-
var time = '[' + new Date().toISOString() + '] ';
|
|
171
|
-
return (time + content);
|
|
172
|
-
}
|
|
173
|
-
return content;
|
|
174
|
-
}
|
|
175
|
-
function setupJsonFormat(content, timestamp, level) {
|
|
176
|
-
var json = {
|
|
177
|
-
level: level.Prefix,
|
|
178
|
-
message: content,
|
|
179
|
-
};
|
|
180
|
-
if (timestamp) {
|
|
181
|
-
json.timestamp = new Date().toISOString();
|
|
182
|
-
}
|
|
183
|
-
return JSON.stringify(json);
|
|
184
|
-
}
|
|
185
|
-
function writeToFile(content, filePath) {
|
|
186
|
-
return new Promise(function (res, rej) {
|
|
187
|
-
return fs_1.default.appendFile(filePath, content, (function (err) { return !!err ? rej(err) : res(); }));
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
exports.default = jetLogger();
|