From 687748a784ff60a49e10cd252dcc8298cb6c0a9b Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Fri, 5 Oct 2018 20:38:33 +0200 Subject: [PATCH] Fixing bug with not closed file while moving to new destination --- out/index.js | 40 ++++++++++++++++++++++++++++------------ out/index.js.map | 2 +- out/test.js | 26 +++++++++++++++++++++----- out/test.js.map | 2 +- package.json | 2 +- src/index.ts | 40 ++++++++++++++++++++++++++-------------- src/test.ts | 27 ++++++++++++++++++++++----- 7 files changed, 100 insertions(+), 39 deletions(-) diff --git a/out/index.js b/out/index.js index 3a85b7f..0e13ac3 100644 --- a/out/index.js +++ b/out/index.js @@ -61,6 +61,9 @@ class LoggingFiles { } async initializeFile(new_file = false) { try { + if (this.stream) { + this.stream.close(); + } const folder = path.dirname(this.file); if (folder) { if (!await fsExists(folder)) { @@ -70,7 +73,7 @@ class LoggingFiles { let size = 0; if (await fsExists(this.file)) { let stats = await fsStat(this.file); - if (new_file || stats.size > maxFileSize) { + if (new_file || stats.size >= maxFileSize) { if (await fsExists(this.file + ".old")) await fsUnlink(this.file + ".old"); await fsMove(this.file, this.file + ".old"); @@ -99,11 +102,18 @@ class LoggingFiles { lock.release(); } async write_to_file(data) { - if (data.byteLength < maxFileSize && this.size + data.byteLength > maxFileSize) { - let f = await this.initializeFile(true); + try { + if (data.byteLength < maxFileSize && this.size + data.byteLength > maxFileSize) { + await this.initializeFile(true); + } + this.size += data.byteLength; + this.stream.write(data); + } + catch (err) { + console.error(err); + this.initializeFile(false); + this.write_to_file(data); } - this.size += data.byteLength; - this.stream.write(data); } write(data) { this.queue.push(data); @@ -299,14 +309,20 @@ function fsMove(oldPath, newPath) { callback(); }); function copy() { - var readStream = fs.createReadStream(oldPath); - var writeStream = fs.createWriteStream(newPath); - readStream.on('error', callback); - writeStream.on('error', callback); - readStream.on('close', function () { - fs.unlink(oldPath, callback); + fs.copyFile(oldPath, newPath, (err) => { + if (err) + callback(err); + else + fs.unlink(oldPath, callback); }); - readStream.pipe(writeStream); + // var readStream = fs.createReadStream(oldPath); + // var writeStream = fs.createWriteStream(newPath); + // readStream.on('error', callback); + // writeStream.on('error', callback); + // readStream.on('close', function () { + // fs.unlink(oldPath, callback); + // }); + // readStream.pipe(writeStream); } }); } diff --git a/out/index.js.map b/out/index.js.map index 9fe60b4..31325f7 100644 --- a/out/index.js.map +++ b/out/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,6BAA6B;AAC7B,yBAAyB;AACzB,mCAAsC;AACtC,6BAA6B;AAC7B,iCAA0B;AAEb,QAAA,MAAM,GAAG;IACnB,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;IACjB,GAAG,EAAE,SAAS;IACd,UAAU,EAAE,SAAS;IACrB,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,SAAS;IAEjB,OAAO,EAAE,UAAU;IACnB,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,UAAU;IAClB,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,UAAU;IAEnB,OAAO,EAAE,UAAU;IACnB,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,UAAU;IAClB,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,UAAU;CACrB,CAAA;AAED,MAAM,WAAW,GAAG,SAAS,CAAC;AAE9B,MAAM,0BAA0B,GAAS,KAAK,CAAC,SAAU,CAAC,iBAAiB,CAAA;AAqB3E;IAgBG,YAAoB,IAAY;QAHxB,SAAI,GAAW,CAAC,CAAC;QACjB,WAAM,GAAmB,SAAS,CAAC;QACnC,SAAI,GAAG,IAAI,cAAI,EAAE,CAAC;QA+ClB,UAAK,GAAa,EAAE,C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IAAI,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAA;QAC/D,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;YAChC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACrC,IAAI,CAAC,IAAI,OAAO,EAAE;gBACf,OAAO;oBACJ,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;iBAC7B,CAAC;aACJ;SACH;KACH;AACJ,CAAC;AAED,IAAY,YAKX;AALD,WAAY,YAAY;IACrB,6CAAG,CAAA;IACH,qDAAO,CAAA;IACP,iDAAK,CAAA;IACL,iDAAK,CAAA;AACR,CAAC,EALW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAKvB"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,6BAA6B;AAC7B,yBAAyB;AACzB,mCAAsC;AACtC,6BAA6B;AAC7B,iCAA0B;AAEb,QAAA,MAAM,GAAG;IACnB,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;IACjB,GAAG,EAAE,SAAS;IACd,UAAU,EAAE,SAAS;IACrB,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,SAAS;IAEjB,OAAO,EAAE,UAAU;IACnB,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,UAAU;IAClB,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,UAAU;IAEnB,OAAO,EAAE,UAAU;IACnB,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE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-1,6 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("./index"); +const crypto_1 = require("crypto"); index_1.Logging.log("test"); index_1.Logging.log("i", "am", { a: "an" }, 1000); index_1.Logging.error(new Error("fehler 001")); @@ -26,9 +27,24 @@ cus2.log("Hello from custom Logger 2"); cus22.log("Hello from custom Logger 22"); cus2.log("Hello from custom Logger 2"); index_1.Logging.console_out = false; -// Logging.waitForSetup().then(() => { -// for (let i = 0; i < 7000; i++) { -// Logging.log(randomBytes(50000).toString("hex")) -// } -// }); +async function benchmark(count, message_size) { + await index_1.Logging.waitForSetup(); + const randData = crypto_1.randomBytes(message_size).toString("hex"); + const t = process.hrtime(); + for (let i = 0; i < count; i++) { + index_1.Logging.log(randData); + } + const diff = process.hrtime(t); + const NS_PER_SEC = 1e9; + await index_1.Logging.waitForSetup(); + const ns = diff[0] * NS_PER_SEC + diff[1]; + console.log(`Benchmark took ${ns / 1000000}ms for ${count} messages with a size of ${message_size} characters`); + console.log(`This is equal to ${(ns / 1000000) / count} ms per message`); +} +index_1.Logging.waitForSetup().then(async () => { + console.log("Large data benchmark:"); + await benchmark(7000, 50000); + console.log("Realdata data benchmark:"); + await benchmark(100000, 100); +}); //# sourceMappingURL=test.js.map \ No newline at end of file diff --git a/out/test.js.map b/out/test.js.map index e57a6be..5fcaa95 100644 --- a/out/test.js.map +++ b/out/test.js.map @@ -1 +1 @@ -{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;AAAA,mCAA+C;AAG/C,eAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACnB,eAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;AAC1C,eAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;AACvC,eAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAA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AO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;IACpC,MAAM,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAE7B,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;IACvC,MAAM,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAC/B,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index dc21863..aca92bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/nodelogging", - "version": "1.3.16", + "version": "1.3.17", "description": "", "main": "out/index.js", "types": "out/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 3bfadd3..a001057 100644 --- a/src/index.ts +++ b/src/index.ts @@ -89,6 +89,9 @@ class LoggingFiles { private async initializeFile(new_file = false) { try { + if (this.stream) { + this.stream.close(); + } const folder = path.dirname(this.file); if (folder) { if (!await fsExists(folder)) { @@ -99,7 +102,7 @@ class LoggingFiles { let size = 0; if (await fsExists(this.file)) { let stats = await fsStat(this.file); - if (new_file || stats.size > maxFileSize) { + if (new_file || stats.size >= maxFileSize) { if (await fsExists(this.file + ".old")) await fsUnlink(this.file + ".old"); await fsMove(this.file, this.file + ".old") @@ -130,11 +133,17 @@ class LoggingFiles { } private async write_to_file(data: Buffer) { - if (data.byteLength < maxFileSize && this.size + data.byteLength > maxFileSize) { - let f = await this.initializeFile(true); + try { + if (data.byteLength < maxFileSize && this.size + data.byteLength > maxFileSize) { + await this.initializeFile(true) + } + this.size += data.byteLength; + this.stream.write(data); + } catch (err) { + console.error(err); + this.initializeFile(false); + this.write_to_file(data); } - this.size += data.byteLength; - this.stream.write(data); } public write(data: Buffer) { @@ -324,7 +333,6 @@ function fsStat(path: string) { function fsMove(oldPath: string, newPath: string) { return new Promise((resolve, reject) => { - let callback = (err?) => { if (err) reject(err) else resolve() @@ -343,17 +351,21 @@ function fsMove(oldPath: string, newPath: string) { }); function copy() { - var readStream = fs.createReadStream(oldPath); - var writeStream = fs.createWriteStream(newPath); + fs.copyFile(oldPath, newPath, (err) => { + if (err) callback(err) + else fs.unlink(oldPath, callback); + }) + // var readStream = fs.createReadStream(oldPath); + // var writeStream = fs.createWriteStream(newPath); - readStream.on('error', callback); - writeStream.on('error', callback); + // readStream.on('error', callback); + // writeStream.on('error', callback); - readStream.on('close', function () { - fs.unlink(oldPath, callback); - }); + // readStream.on('close', function () { + // fs.unlink(oldPath, callback); + // }); - readStream.pipe(writeStream); + // readStream.pipe(writeStream); } }) } diff --git a/src/test.ts b/src/test.ts index 8b6e0ac..2e3c9d1 100644 --- a/src/test.ts +++ b/src/test.ts @@ -31,8 +31,25 @@ cus22.log("Hello from custom Logger 22") cus2.log("Hello from custom Logger 2") Logging.console_out = false; -// Logging.waitForSetup().then(() => { -// for (let i = 0; i < 7000; i++) { -// Logging.log(randomBytes(50000).toString("hex")) -// } -// }); \ No newline at end of file +async function benchmark(count: number, message_size: number) { + await Logging.waitForSetup(); + const randData = randomBytes(message_size).toString("hex") + const t = process.hrtime(); + for (let i = 0; i < count; i++) { + Logging.log(randData) + } + const diff = process.hrtime(t); + const NS_PER_SEC = 1e9; + await Logging.waitForSetup(); + const ns = diff[0] * NS_PER_SEC + diff[1]; + console.log(`Benchmark took ${ns / 1000000}ms for ${count} messages with a size of ${message_size} characters`); + console.log(`This is equal to ${(ns / 1000000) / count} ms per message`) +} + +Logging.waitForSetup().then(async () => { + console.log("Large data benchmark:") + await benchmark(7000, 50000); + + console.log("Realdata data benchmark:") + await benchmark(100000, 100) +}); \ No newline at end of file