fast-node-logger
Advanced tools
Comparing version 2.0.2 to 3.0.0-beta01
@@ -5,2 +5,9 @@ ### Changelog | ||
#### [v2.0.2](https://github.com/saostad/fast-node-logger/compare/v2.0.1...v2.0.2) | ||
> 19 July 2022 | ||
- pkg: removed depricated package [`c2fed91`](https://github.com/saostad/fast-node-logger/commit/c2fed91d32f2d2b91584736d5bb27cc662054054) | ||
- doc: change log [`00b4725`](https://github.com/saostad/fast-node-logger/commit/00b47254a047e106d9cc159214554b4e8aab0ddd) | ||
#### [v2.0.1](https://github.com/saostad/fast-node-logger/compare/v2.0.0...v2.0.1) | ||
@@ -7,0 +14,0 @@ |
@@ -70,23 +70,20 @@ "use strict"; | ||
console.log(`deleting old files from folder: ${pathToDelete}`); | ||
fs.readdir(pathToDelete, (err1, files) => { | ||
if (!err1) { | ||
files.forEach((file) => { | ||
if ((options && options.keepMetaFiles && file === ".empty") || | ||
file === ".Readme.md" || | ||
file === ".README") { | ||
return; | ||
const files = fs.readdirSync(pathToDelete); | ||
files.forEach((file) => { | ||
if ((options && options.keepMetaFiles && file === ".empty") || | ||
file === ".Readme.md" || | ||
file === ".README") { | ||
return; | ||
} | ||
fs.stat(path.join(pathToDelete, file), (err2, stat) => { | ||
if (!err2) { | ||
const now = new Date().getTime(); | ||
const endTime = new Date(stat.ctime).getTime() + keepAliveTime; | ||
if (now > endTime) { | ||
(0, rimraf_1.default)(path.join(pathToDelete, file), () => { | ||
null; | ||
}); | ||
} | ||
fs.stat(path.join(pathToDelete, file), (err2, stat) => { | ||
if (!err2) { | ||
const now = new Date().getTime(); | ||
const endTime = new Date(stat.ctime).getTime() + keepAliveTime; | ||
if (now > endTime) { | ||
(0, rimraf_1.default)(path.join(pathToDelete, file), () => { | ||
null; | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
@@ -93,0 +90,0 @@ } |
@@ -26,3 +26,3 @@ "use strict"; | ||
function createLogger(options) { | ||
var _a, _b, _c; | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -44,6 +44,13 @@ const fileName = `${new Date().getTime()}.log`; | ||
const dest = pino_1.default.destination(filePath); | ||
logToConsole = (0, pino_1.default)(Object.assign({}, options)); | ||
exports.logToFile = (0, pino_1.default)((_c = Object.assign(Object.assign({}, options), { prettyPrint: { colorize: false } })) !== null && _c !== void 0 ? _c : {}, dest); | ||
logToConsole.info(`Logging to file: ${filePath}`); | ||
return exports.logToFile; | ||
dest.on("ready", () => { | ||
var _a; | ||
console.log(`File: index.ts,`, `Line: 49 => `, `sonic is ready`); | ||
exports.logToFile = (0, pino_1.default)((_a = Object.assign(Object.assign({}, options), { prettyPrint: { colorize: false } })) !== null && _a !== void 0 ? _a : {}, dest); | ||
logToConsole = (0, pino_1.default)(Object.assign({}, options)); | ||
logToConsole.info(`Logging to file: ${filePath}`); | ||
}); | ||
if (exports.logToFile) { | ||
return exports.logToFile; | ||
} | ||
throw new Error("fffff"); | ||
}); | ||
@@ -55,21 +62,28 @@ } | ||
var _a, _b; | ||
if (exports.logToFile) { | ||
exports.logToFile[(_a = config.level) !== null && _a !== void 0 ? _a : defaultLogLevel](message); | ||
if (config.stdout) { | ||
logToConsole === null || logToConsole === void 0 ? void 0 : logToConsole[(_b = config.level) !== null && _b !== void 0 ? _b : defaultLogLevel](message); | ||
try { | ||
if (exports.logToFile) { | ||
exports.logToFile[(_a = config.level) !== null && _a !== void 0 ? _a : defaultLogLevel](message); | ||
if (config.stdout) { | ||
logToConsole === null || logToConsole === void 0 ? void 0 : logToConsole[(_b = config.level) !== null && _b !== void 0 ? _b : defaultLogLevel](message); | ||
} | ||
} | ||
} | ||
else { | ||
/** fallback to console.log | ||
* if: | ||
* - config provided | ||
* - && log level is "info" || "fatal" || "warn" || "error" | ||
* else: do nothing | ||
*/ | ||
if (config && (config === null || config === void 0 ? void 0 : config.level) === ("info" || "fatal" || "warn" || "error")) { | ||
console.log(message); | ||
else { | ||
/** fallback to console.log | ||
* if: | ||
* - config provided | ||
* - && log level is "info" || "fatal" || "warn" || "error" | ||
* else: do nothing | ||
*/ | ||
if (config && | ||
(config === null || config === void 0 ? void 0 : config.level) === ("info" || "fatal" || "warn" || "error")) { | ||
console.log(message); | ||
} | ||
} | ||
} | ||
catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} | ||
exports.writeLog = writeLog; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "fast-node-logger", | ||
"version": "2.0.2", | ||
"version": "3.0.0-beta01", | ||
"description": "fast file logger base on pino", | ||
@@ -62,2 +62,3 @@ "repository": { | ||
"ts-jest": "^28.0.7", | ||
"ts-node": "^10.9.1", | ||
"typedoc": "^0.23.8", | ||
@@ -64,0 +65,0 @@ "typescript": "^4.3.4" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53532
334
17
2