jet-logger 1.2.1 → 1.2.2
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/lib/index.js +8 -10
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -96,6 +96,9 @@ function getSettings(mode, filepath, filepathDatetime, timestamp, format, custom
|
|
|
96
96
|
format = defaults.format;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
+
if (filepathDatetime) {
|
|
100
|
+
filepath = addDatetimeToFileName(filepath);
|
|
101
|
+
}
|
|
99
102
|
return {
|
|
100
103
|
mode: mode,
|
|
101
104
|
filepath: filepath,
|
|
@@ -118,7 +121,7 @@ function err(content, printFull) {
|
|
|
118
121
|
return printLog(content, printFull !== null && printFull !== void 0 ? printFull : false, levels.err, this.settings);
|
|
119
122
|
}
|
|
120
123
|
function printLog(content, printFull, level, settings) {
|
|
121
|
-
var mode = settings.mode, format = settings.format, timestamp = settings.timestamp, filepath = settings.filepath,
|
|
124
|
+
var mode = settings.mode, format = settings.format, timestamp = settings.timestamp, filepath = settings.filepath, customLogger = settings.customLogger;
|
|
122
125
|
if (mode === LoggerModes.Off) {
|
|
123
126
|
return;
|
|
124
127
|
}
|
|
@@ -140,7 +143,7 @@ function printLog(content, printFull, level, settings) {
|
|
|
140
143
|
if (timestamp) {
|
|
141
144
|
if (format === Formats.Line) {
|
|
142
145
|
var time = '[' + new Date().toISOString() + '] ';
|
|
143
|
-
content = time + content;
|
|
146
|
+
content = (time + content);
|
|
144
147
|
}
|
|
145
148
|
else if (format === Formats.Json) {
|
|
146
149
|
jsonContent.timestamp = new Date().toISOString();
|
|
@@ -154,11 +157,7 @@ function printLog(content, printFull, level, settings) {
|
|
|
154
157
|
console.log(colorFn(content));
|
|
155
158
|
}
|
|
156
159
|
else if (mode === LoggerModes.File) {
|
|
157
|
-
|
|
158
|
-
if (filepathDatetime) {
|
|
159
|
-
filePathFinal = addDatetimeToFileName(filepath);
|
|
160
|
-
}
|
|
161
|
-
writeToFile(content + '\n', filePathFinal)
|
|
160
|
+
writeToFile(content + '\n', filepath)
|
|
162
161
|
.catch(function (err) { return console.log(err); });
|
|
163
162
|
}
|
|
164
163
|
else if (mode === LoggerModes.Custom) {
|
|
@@ -184,9 +183,8 @@ function addDatetimeToFileName(filePath) {
|
|
|
184
183
|
}
|
|
185
184
|
function writeToFile(content, filePath) {
|
|
186
185
|
return new Promise(function (res, rej) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
186
|
+
var fn = (function (err) { return !!err ? rej(err) : res(); });
|
|
187
|
+
return fs_1.default.appendFile(filePath, content, fn);
|
|
190
188
|
});
|
|
191
189
|
}
|
|
192
190
|
exports.default = JetLogger();
|