fixing file logger
This commit is contained in:
parent
243ed4ec7b
commit
712785e4a9
@ -2,12 +2,11 @@
|
||||
* @author Martin Karkowski
|
||||
* @email m.karkowski@zema.de
|
||||
* @create date 2021-05-21 16:44:59
|
||||
* @modify date 2021-05-21 16:44:59
|
||||
* @modify date 2021-07-29 16:06:13
|
||||
* @desc [description]
|
||||
*/
|
||||
|
||||
import { writeFile } from "fs";
|
||||
import * as Logger from "js-logger";
|
||||
import { join } from "path";
|
||||
import { createFile } from "../helpers/fileMethods";
|
||||
import { replaceAll } from "../helpers/stringMethods";
|
||||
@ -46,7 +45,7 @@ export function useLogFile(pathToFile = DEFAULT_FILE, bufferSize = 100): void {
|
||||
|
||||
// Define a function, that will write the content of the Buffer to our
|
||||
// file.
|
||||
const writeBufferToFile = function () {
|
||||
const writeBufferToFile = function (cb: () => void = null) {
|
||||
const textToStore = buffer.join("\n");
|
||||
|
||||
readyToWrite = false;
|
||||
@ -64,6 +63,10 @@ export function useLogFile(pathToFile = DEFAULT_FILE, bufferSize = 100): void {
|
||||
console.error(err);
|
||||
} else {
|
||||
readyToWrite = true;
|
||||
|
||||
if (typeof (cb) == "function") {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
@ -111,15 +114,12 @@ export function useLogFile(pathToFile = DEFAULT_FILE, bufferSize = 100): void {
|
||||
|
||||
if (bufferSize > 0) {
|
||||
const clearBufferAtEnd = function () {
|
||||
// change the default Handler:
|
||||
logger.setHandler(Logger.createDefaultHandler());
|
||||
|
||||
consoleLogger.info("Shutdown detected! Trying to Write the Buffer");
|
||||
|
||||
if (readyToWrite) {
|
||||
// Now if the Data is ready, lets write the
|
||||
// buffer to the File.
|
||||
writeBufferToFile();
|
||||
writeBufferToFile(() => process.exit(0));
|
||||
} else {
|
||||
setTimeout(clearBufferAtEnd, 50);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user