diff --git a/lib/logger/fileLogging.ts b/lib/logger/fileLogging.ts index 7240338..8a3267e 100644 --- a/lib/logger/fileLogging.ts +++ b/lib/logger/fileLogging.ts @@ -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); }